Skip to content

Commit

Permalink
feat: update server
Browse files Browse the repository at this point in the history
  • Loading branch information
pomelo-nwu committed Sep 26, 2024
1 parent 836a7d3 commit 2149253
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const createGraph = async (params: { nodes: any[]; edges: any[] }, graph_
const kuzuDriver = await getDriver();

const createSchema = 'CREATE NODE TABLE User(name STRING, age INT64, PRIMARY KEY (name))';
await kuzuDriver.createSchema(createSchema);
await kuzuDriver.createSchema(schema);

const insertQuery = "CREATE (u:User {name: 'Alice', age: 35})";
await kuzuDriver.insertData(insertQuery);
Expand Down
40 changes: 22 additions & 18 deletions examples/kuzu-graph/src/kuzu-javascript-driver/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,28 @@ export class KuzuDriver {
this.conn = await result.Connection(this.db);
}

async createSchema(schema: string): Promise<void> {
const createResult = await this.conn?.execute(schema);
async createSchema(schema: { nodes: any[]; edges: any[] }): Promise<void> {
const { nodes, edges } = schema;
const node_scripts = nodes.map(node => {
const { label, properties } = node;
const property_scripts = properties.map(property => {
const { name, type } = property;
return `${name} ${type}`;
});
return `CREATE NODE TABLE ${label} (${property_scripts.join(', ')})`;
});
const edge_scripts = edges.map(edge => {
const { label, source, target, properties } = edge;
const property_scripts = properties.map(property => {
const { name, type } = property;
return `${name} ${type}`;
});
return `CREATE REL TABLE ${label} FROM ${source} TO ${target} (${property_scripts.join(', ')})`;
});

console.log(node_scripts.join('; ') + '; ' + edge_scripts.join('; '));

const createResult = await this.conn?.execute(node_scripts[0]);
console.log('Schema created: ', createResult.toString());
}

Expand Down Expand Up @@ -62,19 +82,3 @@ export class KuzuDriver {
}
}
}

export const testFn = async () => {
const kuzuDriver = new KuzuDriver();
await kuzuDriver.initialize();

const createSchema = 'CREATE NODE TABLE User(name STRING, age INT64, PRIMARY KEY (name))';
await kuzuDriver.createSchema(createSchema);

const insertQuery = "CREATE (u:User {name: 'Alice', age: 35})";
await kuzuDriver.insertData(insertQuery);

const query = 'MATCH (n) RETURN n';
const queryResult = await kuzuDriver.queryData(query);

await kuzuDriver.close();
};

0 comments on commit 2149253

Please sign in to comment.