Repository navigation
Expand file tree
/
Copy pathbasic-usage.ts
More file actions
84 lines (74 loc) · 2.04 KB
/
Copy pathbasic-usage.ts
File metadata and controls
84 lines (74 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Basic usage example for the ageSchemaClient library
*
* This example shows how to use the individual components:
* - Connection Pool Management
* - Query Building
* - Schema Loading
*/
import {
PgConnectionManager,
QueryBuilder,
QueryExecutor,
SchemaLoader
} from '../src';
async function basicUsageExample() {
// 1. Set up connection pool
const connectionManager = new PgConnectionManager({
host: 'localhost',
port: 5432,
database: 'my_database',
user: 'postgres',
password: 'postgres',
// PostgreSQL-specific options
pgOptions: {
// Ensure ag_catalog is in the search path for Apache AGE
searchPath: 'ag_catalog, "$user", public',
applicationName: 'ageSchemaClient-basic',
},
});
// 2. Set up query executor
const queryExecutor = new QueryExecutor(connectionManager);
// 3. Load and validate schema
const schemaLoader = new SchemaLoader(connectionManager);
// Example schema definition
const schema = {
version: '1.0.0',
vertices: {
Person: {
properties: {
id: { type: 'integer' },
name: { type: 'string' },
age: { type: 'integer' }
},
required: ['id', 'name']
}
},
edges: {
KNOWS: {
properties: {},
fromVertex: 'Person',
toVertex: 'Person'
}
}
};
// 4. Create query builder with schema and executor
const queryBuilder = new QueryBuilder(schema, queryExecutor, 'my_graph');
// 5. Build and execute queries
const query = queryBuilder
.match('Person', 'p')
.where('p.age > $minAge')
.return('p.name', 'p.age')
.limit(10);
console.log('Query built successfully');
console.log('Components initialized:', {
connectionManager: !!connectionManager,
queryExecutor: !!queryExecutor,
schemaLoader: !!schemaLoader,
queryBuilder: !!queryBuilder
});
// Note: In a real application, you would execute the query:
// const results = await query.execute();
}
// Run the example
basicUsageExample().catch(console.error);