Skip to content

Commit

Permalink
Address issues (#31)
Browse files Browse the repository at this point in the history
* Update kuzu to 0.0.11

* Address #20
  • Loading branch information
mewim committed Oct 23, 2023
1 parent 574c668 commit ae59618
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 32 deletions.
2 changes: 1 addition & 1 deletion kuzu
Submodule kuzu updated 485 files
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"bootstrap": "^5.3.1",
"core-js": "^3.8.3",
"express": "^4.18.2",
"kuzu": "0.0.9",
"kuzu": "0.0.11",
"moment": "^2.29.4",
"monaco-editor": "^0.41.0",
"monaco-themes": "^0.4.4",
Expand Down
5 changes: 0 additions & 5 deletions src/components/MainLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ export default {
async getSchema() {
const response = await Axios.get("/api/schema");
const schema = response.data;
schema.relTables.forEach((table) => {
table.src = table.properties.src;
table.dst = table.properties.dst;
table.properties = table.properties.props;
});
this.schema = schema;
},
async reloadSchema(rerender) {
Expand Down
24 changes: 3 additions & 21 deletions src/server/Schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,12 @@ const database = require("./utils/database");
const express = require("express");
const router = express.Router();

router.get("/", async (req, res) => {
const conn = database.getConnection();
router.get("/", async (_, res) => {
try {
const nodeTableNames = await conn.getNodeTableNames();
const relTableNames = await conn.getRelTableNames();
const nodeTableSchemas = await Promise.all(
nodeTableNames.map((table) => conn.getNodePropertyNames(table))
);
const nodeTables = nodeTableNames.map((table, i) => ({
name: table,
properties: nodeTableSchemas[i],
}));
const relTableSchemas = await Promise.all(
relTableNames.map((table) => conn.getRelPropertyNames(table))
);
const relTables = relTableNames.map((table, i) => ({
name: table,
properties: relTableSchemas[i],
}));
res.send({ nodeTables, relTables });
const schema = await database.getSchema();
res.send(schema);
} catch (err) {
return res.status(400).send({ error: err.message });
} finally {
database.releaseConnection(conn);
}
});

Expand Down
49 changes: 49 additions & 0 deletions src/server/utils/database.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const path = require("path");
const process = require("process");
const TABLE_TYPES = {
NODE: "NODE",
REL: "REL",
};

let kuzu;
if (process.env.NODE_ENV !== "production") {
const kuzuPath = path.join(
Expand Down Expand Up @@ -76,6 +81,50 @@ class Database {
}
return false;
}

async getSchema() {
const conn = this.getConnection();
try {
const tables = await conn
.query("CALL show_tables() RETURN *;")
.then((res) => res.getAll());
const nodeTables = [];
const relTables = [];
for (const table of tables) {
const properties = (
await conn
.query(`CALL TABLE_INFO('${table.name}') RETURN *;`)
.then((res) => res.getAll())
).map((property) => ({
name: property.name,
type: property.type,
isPrimaryKey: property["primary key"],
}));
if (table.type === TABLE_TYPES.NODE) {
delete table["type"];
table.properties = properties;
nodeTables.push(table);
} else if (table.type === TABLE_TYPES.REL) {
delete table["type"];
properties.forEach((property) => {
delete property.isPrimaryKey;
});
table.properties = properties;
const connectivity = await conn
.query(`CALL SHOW_CONNECTION('${table.name}') RETURN *;`)
.then((res) => res.getAll());
const src = connectivity[0]["source table name"];
const dst = connectivity[0]["destination table name"];
table.src = src;
table.dst = dst;
relTables.push(table);
}
}
return { nodeTables, relTables };
} finally {
this.releaseConnection(conn);
}
}
}

module.exports = new Database();

0 comments on commit ae59618

Please sign in to comment.