diff --git a/hooks/gsd-intel-index.js b/hooks/gsd-intel-index.js index b371beef8..a02bf2386 100755 --- a/hooks/gsd-intel-index.js +++ b/hooks/gsd-intel-index.js @@ -5,6 +5,25 @@ const fs = require('fs'); const path = require('path'); +const initSqlJs = require('sql.js'); + +// Graph database schema (simple-graph pattern) +const GRAPH_SCHEMA = ` +CREATE TABLE IF NOT EXISTS nodes ( + body TEXT, + id TEXT GENERATED ALWAYS AS (json_extract(body, '$.id')) VIRTUAL NOT NULL UNIQUE +); +CREATE INDEX IF NOT EXISTS id_idx ON nodes(id); + +CREATE TABLE IF NOT EXISTS edges ( + source TEXT NOT NULL, + target TEXT NOT NULL, + relationship TEXT DEFAULT 'depends_on', + UNIQUE(source, target, relationship) ON CONFLICT REPLACE +); +CREATE INDEX IF NOT EXISTS source_idx ON edges(source); +CREATE INDEX IF NOT EXISTS target_idx ON edges(target); +`; // JS/TS file extensions to index const INDEXABLE_EXTENSIONS = ['.js', '.ts', '.jsx', '.tsx', '.mjs', '.cjs']; diff --git a/package.json b/package.json index d2d924ce9..36cde3f88 100644 --- a/package.json +++ b/package.json @@ -32,5 +32,8 @@ }, "engines": { "node": ">=16.7.0" + }, + "dependencies": { + "sql.js": "^1.12.0" } }