@nicia-ai/typegraph 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/{ast-CXFx6bF6.d.ts → ast-CG87Zr6p.d.ts} +2 -2
- package/dist/{ast-D-3bOanX.d.cts → ast-Cq9qrnNP.d.cts} +2 -2
- package/dist/backend/postgres/index.cjs +295 -23
- package/dist/backend/postgres/index.cjs.map +1 -1
- package/dist/backend/postgres/index.d.cts +33 -10
- package/dist/backend/postgres/index.d.ts +33 -10
- package/dist/backend/postgres/index.js +285 -5
- package/dist/backend/postgres/index.js.map +1 -1
- package/dist/backend/sqlite/index.cjs +21 -90
- package/dist/backend/sqlite/index.cjs.map +1 -1
- package/dist/backend/sqlite/index.d.cts +22 -58
- package/dist/backend/sqlite/index.d.ts +22 -58
- package/dist/backend/sqlite/index.js +3 -78
- package/dist/backend/sqlite/index.js.map +1 -1
- package/dist/backend/sqlite/local.cjs +83 -0
- package/dist/backend/sqlite/local.cjs.map +1 -0
- package/dist/backend/sqlite/local.d.cts +66 -0
- package/dist/backend/sqlite/local.d.ts +66 -0
- package/dist/backend/sqlite/local.js +77 -0
- package/dist/backend/sqlite/local.js.map +1 -0
- package/dist/chunk-23NGZHUN.cjs +2132 -0
- package/dist/chunk-23NGZHUN.cjs.map +1 -0
- package/dist/{chunk-4MTYE6CF.js → chunk-2DKSQNPW.js} +3 -4
- package/dist/chunk-2DKSQNPW.js.map +1 -0
- package/dist/chunk-JPO7W262.js +2093 -0
- package/dist/chunk-JPO7W262.js.map +1 -0
- package/dist/{chunk-KPU6TLUV.cjs → chunk-K5O7TOJO.cjs} +15 -16
- package/dist/chunk-K5O7TOJO.cjs.map +1 -0
- package/dist/{backend/drizzle/schema/postgres.d.ts → ddl-Bcyb4DW1.d.cts} +17 -17
- package/dist/{backend/drizzle/schema/postgres.d.cts → ddl-D7DQx8w8.d.ts} +17 -17
- package/dist/{index-DyrR_d-H.d.ts → index-QTnQwakS.d.cts} +1 -1
- package/dist/{index-DyrR_d-H.d.cts → index-QTnQwakS.d.ts} +1 -1
- package/dist/index.d.cts +11 -12
- package/dist/index.d.ts +11 -12
- package/dist/indexes/index.d.cts +5 -6
- package/dist/indexes/index.d.ts +5 -6
- package/dist/interchange/index.d.cts +5 -6
- package/dist/interchange/index.d.ts +5 -6
- package/dist/{manager-DiPf-0GG.d.cts → manager-BImRiYwz.d.cts} +3 -3
- package/dist/{manager-DXC7CqKG.d.ts → manager-DGQ9UF18.d.ts} +3 -3
- package/dist/profiler/index.d.cts +7 -8
- package/dist/profiler/index.d.ts +7 -8
- package/dist/schema/index.d.cts +6 -7
- package/dist/schema/index.d.ts +6 -7
- package/dist/{backend/drizzle/schema/sqlite.d.ts → sqlite-CSJ-fgIm.d.ts} +2 -25
- package/dist/{backend/drizzle/schema/sqlite.d.cts → sqlite-FWGZLwDd.d.cts} +2 -25
- package/dist/{store-DODIWZxC.d.ts → store-CscQUG-S.d.ts} +5 -6
- package/dist/{store-nDW3GOFb.d.cts → store-DNv1yd3n.d.cts} +5 -6
- package/dist/{types-DHRsi6j9.d.cts → types-BbMn2Ycv.d.cts} +2 -2
- package/dist/{types-ZT5mlism.d.ts → types-C2rhqkg7.d.ts} +2 -2
- package/dist/{types-DpIoePMI.d.ts → types-D5ggX07j.d.ts} +2 -3
- package/dist/{types-BL1GyVku.d.cts → types-DEMAqkA1.d.cts} +1 -1
- package/dist/{types-DCGa53O2.d.ts → types-DJZoHy5R.d.ts} +1 -1
- package/dist/{types-DTJEu_-h.d.ts → types-DolHw9pJ.d.cts} +14 -1
- package/dist/{types-DTJEu_-h.d.cts → types-DolHw9pJ.d.ts} +14 -1
- package/dist/{types-WX8V9dqn.d.cts → types-SVDEKnU6.d.cts} +2 -3
- package/package.json +6 -46
- package/dist/backend/drizzle/index.cjs +0 -40
- package/dist/backend/drizzle/index.cjs.map +0 -1
- package/dist/backend/drizzle/index.d.cts +0 -13
- package/dist/backend/drizzle/index.d.ts +0 -13
- package/dist/backend/drizzle/index.js +0 -11
- package/dist/backend/drizzle/index.js.map +0 -1
- package/dist/backend/drizzle/postgres.cjs +0 -26
- package/dist/backend/drizzle/postgres.cjs.map +0 -1
- package/dist/backend/drizzle/postgres.d.cts +0 -35
- package/dist/backend/drizzle/postgres.d.ts +0 -35
- package/dist/backend/drizzle/postgres.js +0 -9
- package/dist/backend/drizzle/postgres.js.map +0 -1
- package/dist/backend/drizzle/schema/postgres.cjs +0 -39
- package/dist/backend/drizzle/schema/postgres.cjs.map +0 -1
- package/dist/backend/drizzle/schema/postgres.js +0 -6
- package/dist/backend/drizzle/schema/postgres.js.map +0 -1
- package/dist/backend/drizzle/schema/sqlite.cjs +0 -39
- package/dist/backend/drizzle/schema/sqlite.cjs.map +0 -1
- package/dist/backend/drizzle/schema/sqlite.js +0 -6
- package/dist/backend/drizzle/schema/sqlite.js.map +0 -1
- package/dist/backend/drizzle/sqlite.cjs +0 -26
- package/dist/backend/drizzle/sqlite.cjs.map +0 -1
- package/dist/backend/drizzle/sqlite.d.cts +0 -35
- package/dist/backend/drizzle/sqlite.d.ts +0 -35
- package/dist/backend/drizzle/sqlite.js +0 -9
- package/dist/backend/drizzle/sqlite.js.map +0 -1
- package/dist/chunk-3PURVEA4.js +0 -193
- package/dist/chunk-3PURVEA4.js.map +0 -1
- package/dist/chunk-4MTYE6CF.js.map +0 -1
- package/dist/chunk-6HFWKZU5.js +0 -1506
- package/dist/chunk-6HFWKZU5.js.map +0 -1
- package/dist/chunk-ENXM4W4M.cjs +0 -289
- package/dist/chunk-ENXM4W4M.cjs.map +0 -1
- package/dist/chunk-KKFJJYCP.js +0 -287
- package/dist/chunk-KKFJJYCP.js.map +0 -1
- package/dist/chunk-KPU6TLUV.cjs.map +0 -1
- package/dist/chunk-NU2XNMVI.cjs +0 -201
- package/dist/chunk-NU2XNMVI.cjs.map +0 -1
- package/dist/chunk-OGGLFYFA.js +0 -177
- package/dist/chunk-OGGLFYFA.js.map +0 -1
- package/dist/chunk-PW5BSBZV.cjs +0 -1527
- package/dist/chunk-PW5BSBZV.cjs.map +0 -1
- package/dist/chunk-SMLIWLS7.js +0 -236
- package/dist/chunk-SMLIWLS7.js.map +0 -1
- package/dist/chunk-UYMT4LO2.cjs +0 -241
- package/dist/chunk-UYMT4LO2.cjs.map +0 -1
- package/dist/chunk-XZL6MCZJ.cjs +0 -185
- package/dist/chunk-XZL6MCZJ.cjs.map +0 -1
- package/dist/test-helpers-CIq1Hhj1.d.ts +0 -26
- package/dist/test-helpers-DPRFVky4.d.cts +0 -26
- package/dist/types-BRzHlhKC.d.cts +0 -14
- package/dist/types-BRzHlhKC.d.ts +0 -14
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ import Database from "better-sqlite3";
|
|
|
19
19
|
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
20
20
|
|
|
21
21
|
import { createStore, defineEdge, defineGraph, defineNode } from "@nicia-ai/typegraph";
|
|
22
|
-
import { createSqliteBackend,
|
|
22
|
+
import { createSqliteBackend, generateSqliteMigrationSQL } from "@nicia-ai/typegraph/sqlite";
|
|
23
23
|
|
|
24
24
|
const Person = defineNode("Person", { schema: z.object({ name: z.string() }) });
|
|
25
25
|
const knows = defineEdge("knows");
|
|
@@ -32,7 +32,7 @@ const graph = defineGraph({
|
|
|
32
32
|
|
|
33
33
|
const sqlite = new Database(":memory:");
|
|
34
34
|
const db = drizzle(sqlite);
|
|
35
|
-
sqlite.exec(
|
|
35
|
+
sqlite.exec(generateSqliteMigrationSQL());
|
|
36
36
|
|
|
37
37
|
const backend = createSqliteBackend(db);
|
|
38
38
|
const store = createStore(graph, backend);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as TemporalMode } from './types-
|
|
1
|
+
import { T as TemporalMode } from './types-DolHw9pJ.js';
|
|
2
2
|
|
|
3
3
|
declare const MAX_JSON_POINTER_DEPTH: 5;
|
|
4
4
|
type JsonPointer = string & {
|
|
@@ -441,4 +441,4 @@ type SetOperation = Readonly<{
|
|
|
441
441
|
*/
|
|
442
442
|
type ComposableQuery = QueryAst | SetOperation;
|
|
443
443
|
|
|
444
|
-
export { type AggregateExpr as A, type ComparisonOp as C, type FieldRef as F, type GroupBySpec as G, type JsonPointer as J, MAX_JSON_POINTER_DEPTH as M, type NodePredicate as N, type OrderSpec as O, type ParameterRef as P, type QueryAst as Q, type ResolveJsonPointer as R, type SortDirection as S, type TraversalExpansion as T, type ValueType as V, type
|
|
444
|
+
export { type AggregateExpr as A, type ComparisonOp as C, type FieldRef as F, type GroupBySpec as G, type JsonPointer as J, MAX_JSON_POINTER_DEPTH as M, type NodePredicate as N, type OrderSpec as O, type ParameterRef as P, type QueryAst as Q, type ResolveJsonPointer as R, type SortDirection as S, type TraversalExpansion as T, type ValueType as V, type AggregateComparisonPredicate as a, type JsonPointerFor as b, type JsonPointerInput as c, type JsonPointerSegment as d, type JsonPointerSegments as e, type JsonPointerSegmentsFor as f, type ResolveJsonPointerSegments as g, jsonPointer as h, type PredicateExpression as i, joinJsonPointers as j, type VectorMetricType as k, type Traversal as l, type ProjectedField as m, normalizeJsonPointer as n, type RecursiveCyclePolicy as o, parseJsonPointer as p, type TraversalDirection as q, type SelectiveField as r, type ComposableQuery as s, type SetOperationType as t, type SetOperation as u };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as TemporalMode } from './types-
|
|
1
|
+
import { T as TemporalMode } from './types-DolHw9pJ.cjs';
|
|
2
2
|
|
|
3
3
|
declare const MAX_JSON_POINTER_DEPTH: 5;
|
|
4
4
|
type JsonPointer = string & {
|
|
@@ -441,4 +441,4 @@ type SetOperation = Readonly<{
|
|
|
441
441
|
*/
|
|
442
442
|
type ComposableQuery = QueryAst | SetOperation;
|
|
443
443
|
|
|
444
|
-
export { type AggregateExpr as A, type ComparisonOp as C, type FieldRef as F, type GroupBySpec as G, type JsonPointer as J, MAX_JSON_POINTER_DEPTH as M, type NodePredicate as N, type OrderSpec as O, type ParameterRef as P, type QueryAst as Q, type ResolveJsonPointer as R, type SortDirection as S, type TraversalExpansion as T, type ValueType as V, type
|
|
444
|
+
export { type AggregateExpr as A, type ComparisonOp as C, type FieldRef as F, type GroupBySpec as G, type JsonPointer as J, MAX_JSON_POINTER_DEPTH as M, type NodePredicate as N, type OrderSpec as O, type ParameterRef as P, type QueryAst as Q, type ResolveJsonPointer as R, type SortDirection as S, type TraversalExpansion as T, type ValueType as V, type AggregateComparisonPredicate as a, type JsonPointerFor as b, type JsonPointerInput as c, type JsonPointerSegment as d, type JsonPointerSegments as e, type JsonPointerSegmentsFor as f, type ResolveJsonPointerSegments as g, jsonPointer as h, type PredicateExpression as i, joinJsonPointers as j, type VectorMetricType as k, type Traversal as l, type ProjectedField as m, normalizeJsonPointer as n, type RecursiveCyclePolicy as o, parseJsonPointer as p, type TraversalDirection as q, type SelectiveField as r, type ComposableQuery as s, type SetOperationType as t, type SetOperation as u };
|
|
@@ -1,56 +1,328 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var chunkENXM4W4M_cjs = require('../../chunk-ENXM4W4M.cjs');
|
|
5
|
-
require('../../chunk-PW5BSBZV.cjs');
|
|
6
|
-
require('../../chunk-XZL6MCZJ.cjs');
|
|
7
|
-
var chunkNU2XNMVI_cjs = require('../../chunk-NU2XNMVI.cjs');
|
|
3
|
+
var chunk23NGZHUN_cjs = require('../../chunk-23NGZHUN.cjs');
|
|
8
4
|
require('../../chunk-44SXEVF4.cjs');
|
|
9
5
|
require('../../chunk-JQDWEX6V.cjs');
|
|
10
6
|
require('../../chunk-2WVFEIHR.cjs');
|
|
11
7
|
require('../../chunk-P5CNM325.cjs');
|
|
8
|
+
var drizzleOrm = require('drizzle-orm');
|
|
12
9
|
|
|
10
|
+
// src/backend/drizzle/execution/postgres-execution.ts
|
|
11
|
+
function resolvePgClient(db) {
|
|
12
|
+
const databaseWithClient = db;
|
|
13
|
+
const pgClient = databaseWithClient.$client;
|
|
14
|
+
if (pgClient?.query === void 0) {
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
return pgClient;
|
|
18
|
+
}
|
|
19
|
+
async function executeDrizzleQuery(db, query) {
|
|
20
|
+
const result = await db.execute(query);
|
|
21
|
+
return result.rows;
|
|
22
|
+
}
|
|
23
|
+
function createPgPreparedStatement(pgClient, sqlText) {
|
|
24
|
+
return {
|
|
25
|
+
async execute(params) {
|
|
26
|
+
const result = await pgClient.query(sqlText, params);
|
|
27
|
+
return result.rows;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function createPostgresExecutionAdapter(db) {
|
|
32
|
+
const pgClient = resolvePgClient(db);
|
|
33
|
+
function compile(query) {
|
|
34
|
+
return chunk23NGZHUN_cjs.compileQueryWithDialect(db, query, "PostgreSQL");
|
|
35
|
+
}
|
|
36
|
+
if (pgClient === void 0) {
|
|
37
|
+
return {
|
|
38
|
+
compile,
|
|
39
|
+
async execute(query) {
|
|
40
|
+
return executeDrizzleQuery(db, query);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const pgQueryClient = pgClient;
|
|
45
|
+
async function executeCompiled(compiledQuery) {
|
|
46
|
+
const result = await pgQueryClient.query(
|
|
47
|
+
compiledQuery.sql,
|
|
48
|
+
compiledQuery.params
|
|
49
|
+
);
|
|
50
|
+
return result.rows;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
compile,
|
|
54
|
+
async execute(query) {
|
|
55
|
+
return executeDrizzleQuery(db, query);
|
|
56
|
+
},
|
|
57
|
+
executeCompiled,
|
|
58
|
+
prepare(sqlText) {
|
|
59
|
+
return createPgPreparedStatement(pgQueryClient, sqlText);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
13
63
|
|
|
64
|
+
// src/backend/drizzle/postgres.ts
|
|
65
|
+
var POSTGRES_MAX_BIND_PARAMETERS = 65535;
|
|
66
|
+
var NODE_INSERT_PARAM_COUNT = 9;
|
|
67
|
+
var EDGE_INSERT_PARAM_COUNT = 12;
|
|
68
|
+
var POSTGRES_NODE_INSERT_BATCH_SIZE = Math.max(
|
|
69
|
+
1,
|
|
70
|
+
Math.floor(POSTGRES_MAX_BIND_PARAMETERS / NODE_INSERT_PARAM_COUNT)
|
|
71
|
+
);
|
|
72
|
+
var POSTGRES_EDGE_INSERT_BATCH_SIZE = Math.max(
|
|
73
|
+
1,
|
|
74
|
+
Math.floor(POSTGRES_MAX_BIND_PARAMETERS / EDGE_INSERT_PARAM_COUNT)
|
|
75
|
+
);
|
|
76
|
+
var POSTGRES_GET_NODES_ID_CHUNK_SIZE = Math.max(
|
|
77
|
+
1,
|
|
78
|
+
POSTGRES_MAX_BIND_PARAMETERS - 2
|
|
79
|
+
);
|
|
80
|
+
var POSTGRES_GET_EDGES_ID_CHUNK_SIZE = Math.max(
|
|
81
|
+
1,
|
|
82
|
+
POSTGRES_MAX_BIND_PARAMETERS - 1
|
|
83
|
+
);
|
|
84
|
+
var toNodeRow = chunk23NGZHUN_cjs.createNodeRowMapper(chunk23NGZHUN_cjs.POSTGRES_ROW_MAPPER_CONFIG);
|
|
85
|
+
var toEdgeRow = chunk23NGZHUN_cjs.createEdgeRowMapper(chunk23NGZHUN_cjs.POSTGRES_ROW_MAPPER_CONFIG);
|
|
86
|
+
var toUniqueRow = chunk23NGZHUN_cjs.createUniqueRowMapper(chunk23NGZHUN_cjs.POSTGRES_ROW_MAPPER_CONFIG);
|
|
87
|
+
var toSchemaVersionRow = chunk23NGZHUN_cjs.createSchemaVersionRowMapper(chunk23NGZHUN_cjs.POSTGRES_ROW_MAPPER_CONFIG);
|
|
88
|
+
function toEmbeddingRow(row) {
|
|
89
|
+
let embedding;
|
|
90
|
+
if (typeof row.embedding === "string") {
|
|
91
|
+
const content = row.embedding.slice(1, -1);
|
|
92
|
+
embedding = content === "" ? [] : content.split(",").map((s) => Number.parseFloat(s.trim()));
|
|
93
|
+
} else if (Array.isArray(row.embedding)) {
|
|
94
|
+
embedding = row.embedding;
|
|
95
|
+
} else {
|
|
96
|
+
embedding = [];
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
graph_id: row.graph_id,
|
|
100
|
+
node_kind: row.node_kind,
|
|
101
|
+
node_id: row.node_id,
|
|
102
|
+
field_path: row.field_path,
|
|
103
|
+
embedding,
|
|
104
|
+
dimensions: row.dimensions,
|
|
105
|
+
created_at: chunk23NGZHUN_cjs.formatPostgresTimestamp(row.created_at) ?? "",
|
|
106
|
+
updated_at: chunk23NGZHUN_cjs.formatPostgresTimestamp(row.updated_at) ?? ""
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
var POSTGRES_VECTOR_CAPABILITIES = {
|
|
110
|
+
...chunk23NGZHUN_cjs.POSTGRES_CAPABILITIES,
|
|
111
|
+
vector: {
|
|
112
|
+
supported: true,
|
|
113
|
+
metrics: ["cosine", "l2", "inner_product"],
|
|
114
|
+
indexTypes: ["hnsw", "ivfflat", "none"],
|
|
115
|
+
maxDimensions: 16e3
|
|
116
|
+
// pgvector limit
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
function createPostgresBackend(db, options = {}) {
|
|
120
|
+
const tables2 = options.tables ?? chunk23NGZHUN_cjs.tables2;
|
|
121
|
+
const executionAdapter = createPostgresExecutionAdapter(db);
|
|
122
|
+
const tableNames = {
|
|
123
|
+
nodes: drizzleOrm.getTableName(tables2.nodes),
|
|
124
|
+
edges: drizzleOrm.getTableName(tables2.edges),
|
|
125
|
+
embeddings: drizzleOrm.getTableName(tables2.embeddings)
|
|
126
|
+
};
|
|
127
|
+
const operationStrategy = chunk23NGZHUN_cjs.createPostgresOperationStrategy(tables2);
|
|
128
|
+
const operations = createPostgresOperationBackend({
|
|
129
|
+
db,
|
|
130
|
+
executionAdapter,
|
|
131
|
+
operationStrategy,
|
|
132
|
+
tableNames
|
|
133
|
+
});
|
|
134
|
+
const backend = {
|
|
135
|
+
...operations,
|
|
136
|
+
async setActiveSchema(graphId, version) {
|
|
137
|
+
await backend.transaction(async (txBackend) => {
|
|
138
|
+
await txBackend.setActiveSchema(graphId, version);
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
async transaction(fn, options2) {
|
|
142
|
+
const txConfig = options2?.isolationLevel ? {
|
|
143
|
+
isolationLevel: options2.isolationLevel.replace("_", " ")
|
|
144
|
+
} : void 0;
|
|
145
|
+
return db.transaction(async (tx) => {
|
|
146
|
+
const txBackend = createTransactionBackend({
|
|
147
|
+
db: tx,
|
|
148
|
+
operationStrategy,
|
|
149
|
+
tableNames
|
|
150
|
+
});
|
|
151
|
+
return fn(txBackend);
|
|
152
|
+
}, txConfig);
|
|
153
|
+
},
|
|
154
|
+
async close() {
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
return backend;
|
|
158
|
+
}
|
|
159
|
+
function createPostgresOperationBackend(options) {
|
|
160
|
+
const { db, executionAdapter, operationStrategy, tableNames } = options;
|
|
161
|
+
async function execAll(query) {
|
|
162
|
+
const result = await db.execute(query);
|
|
163
|
+
return result.rows;
|
|
164
|
+
}
|
|
165
|
+
async function execGet(query) {
|
|
166
|
+
const result = await db.execute(query);
|
|
167
|
+
return result.rows[0];
|
|
168
|
+
}
|
|
169
|
+
async function execRun(query) {
|
|
170
|
+
await db.execute(query);
|
|
171
|
+
}
|
|
172
|
+
const commonBackend = chunk23NGZHUN_cjs.createCommonOperationBackend({
|
|
173
|
+
batchConfig: {
|
|
174
|
+
edgeInsertBatchSize: POSTGRES_EDGE_INSERT_BATCH_SIZE,
|
|
175
|
+
getEdgesChunkSize: POSTGRES_GET_EDGES_ID_CHUNK_SIZE,
|
|
176
|
+
getNodesChunkSize: POSTGRES_GET_NODES_ID_CHUNK_SIZE,
|
|
177
|
+
nodeInsertBatchSize: POSTGRES_NODE_INSERT_BATCH_SIZE
|
|
178
|
+
},
|
|
179
|
+
execution: {
|
|
180
|
+
execAll,
|
|
181
|
+
execGet,
|
|
182
|
+
execRun
|
|
183
|
+
},
|
|
184
|
+
nowIso: chunk23NGZHUN_cjs.nowIso,
|
|
185
|
+
operationStrategy,
|
|
186
|
+
rowMappers: {
|
|
187
|
+
toEdgeRow,
|
|
188
|
+
toNodeRow,
|
|
189
|
+
toSchemaVersionRow,
|
|
190
|
+
toUniqueRow
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
const executeCompiled = executionAdapter.executeCompiled;
|
|
194
|
+
const executeRawMethod = executeCompiled === void 0 ? {} : {
|
|
195
|
+
async executeRaw(sqlText, params) {
|
|
196
|
+
return executeCompiled({ params, sql: sqlText });
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
const operationBackend = {
|
|
200
|
+
...commonBackend,
|
|
201
|
+
...executeRawMethod,
|
|
202
|
+
capabilities: POSTGRES_VECTOR_CAPABILITIES,
|
|
203
|
+
dialect: "postgres",
|
|
204
|
+
tableNames,
|
|
205
|
+
// === Embedding Operations ===
|
|
206
|
+
async upsertEmbedding(params) {
|
|
207
|
+
const timestamp = chunk23NGZHUN_cjs.nowIso();
|
|
208
|
+
const query = operationStrategy.buildUpsertEmbedding(params, timestamp);
|
|
209
|
+
await execRun(query);
|
|
210
|
+
},
|
|
211
|
+
async deleteEmbedding(params) {
|
|
212
|
+
const query = operationStrategy.buildDeleteEmbedding(params);
|
|
213
|
+
await execRun(query);
|
|
214
|
+
},
|
|
215
|
+
async getEmbedding(graphId, nodeKind, nodeId, fieldPath) {
|
|
216
|
+
const query = operationStrategy.buildGetEmbedding(
|
|
217
|
+
graphId,
|
|
218
|
+
nodeKind,
|
|
219
|
+
nodeId,
|
|
220
|
+
fieldPath
|
|
221
|
+
);
|
|
222
|
+
const row = await execGet(query);
|
|
223
|
+
return row ? toEmbeddingRow(row) : void 0;
|
|
224
|
+
},
|
|
225
|
+
async vectorSearch(params) {
|
|
226
|
+
const query = operationStrategy.buildVectorSearch(params);
|
|
227
|
+
const rows = await execAll(query);
|
|
228
|
+
return rows.map((row) => ({
|
|
229
|
+
nodeId: row.node_id,
|
|
230
|
+
score: row.score
|
|
231
|
+
}));
|
|
232
|
+
},
|
|
233
|
+
async createVectorIndex(params) {
|
|
234
|
+
const indexOptions = {
|
|
235
|
+
graphId: params.graphId,
|
|
236
|
+
nodeKind: params.nodeKind,
|
|
237
|
+
fieldPath: params.fieldPath,
|
|
238
|
+
dimensions: params.dimensions,
|
|
239
|
+
embeddingsTableName: tableNames.embeddings,
|
|
240
|
+
indexType: params.indexType,
|
|
241
|
+
metric: params.metric,
|
|
242
|
+
...params.indexParams?.m === void 0 ? {} : { hnswM: params.indexParams.m },
|
|
243
|
+
...params.indexParams?.efConstruction === void 0 ? {} : { hnswEfConstruction: params.indexParams.efConstruction },
|
|
244
|
+
...params.indexParams?.lists === void 0 ? {} : { ivfflatLists: params.indexParams.lists }
|
|
245
|
+
};
|
|
246
|
+
const result = await chunk23NGZHUN_cjs.createPostgresVectorIndex(db, indexOptions);
|
|
247
|
+
if (!result.success) {
|
|
248
|
+
throw new Error(
|
|
249
|
+
result.message ?? "Failed to create PostgreSQL vector index"
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
async dropVectorIndex(params) {
|
|
254
|
+
const metrics = POSTGRES_VECTOR_CAPABILITIES.vector?.metrics ?? ["cosine"];
|
|
255
|
+
for (const metric of metrics) {
|
|
256
|
+
const indexName = chunk23NGZHUN_cjs.generateVectorIndexName(
|
|
257
|
+
params.graphId,
|
|
258
|
+
params.nodeKind,
|
|
259
|
+
params.fieldPath,
|
|
260
|
+
metric
|
|
261
|
+
);
|
|
262
|
+
const result = await chunk23NGZHUN_cjs.dropPostgresVectorIndex(db, indexName);
|
|
263
|
+
if (!result.success) {
|
|
264
|
+
throw new Error(
|
|
265
|
+
result.message ?? "Failed to drop PostgreSQL vector index"
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
// === Query Execution ===
|
|
271
|
+
async execute(query) {
|
|
272
|
+
return executionAdapter.execute(query);
|
|
273
|
+
},
|
|
274
|
+
compileSql(query) {
|
|
275
|
+
return executionAdapter.compile(query);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
return operationBackend;
|
|
279
|
+
}
|
|
280
|
+
function createTransactionBackend(options) {
|
|
281
|
+
const txExecutionAdapter = options.executionAdapter ?? createPostgresExecutionAdapter(options.db);
|
|
282
|
+
return createPostgresOperationBackend({
|
|
283
|
+
db: options.db,
|
|
284
|
+
executionAdapter: txExecutionAdapter,
|
|
285
|
+
operationStrategy: options.operationStrategy,
|
|
286
|
+
tableNames: options.tableNames
|
|
287
|
+
});
|
|
288
|
+
}
|
|
14
289
|
|
|
15
|
-
Object.defineProperty(exports, "
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function () { return chunkUYMT4LO2_cjs.generatePostgresDDL; }
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports, "getPostgresMigrationSQL", {
|
|
290
|
+
Object.defineProperty(exports, "createPostgresTables", {
|
|
20
291
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
292
|
+
get: function () { return chunk23NGZHUN_cjs.createPostgresTables; }
|
|
22
293
|
});
|
|
23
|
-
Object.defineProperty(exports, "
|
|
294
|
+
Object.defineProperty(exports, "edges", {
|
|
24
295
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
296
|
+
get: function () { return chunk23NGZHUN_cjs.edges2; }
|
|
26
297
|
});
|
|
27
|
-
Object.defineProperty(exports, "
|
|
298
|
+
Object.defineProperty(exports, "embeddings", {
|
|
28
299
|
enumerable: true,
|
|
29
|
-
get: function () { return
|
|
300
|
+
get: function () { return chunk23NGZHUN_cjs.embeddings2; }
|
|
30
301
|
});
|
|
31
|
-
Object.defineProperty(exports, "
|
|
302
|
+
Object.defineProperty(exports, "generatePostgresDDL", {
|
|
32
303
|
enumerable: true,
|
|
33
|
-
get: function () { return
|
|
304
|
+
get: function () { return chunk23NGZHUN_cjs.generatePostgresDDL; }
|
|
34
305
|
});
|
|
35
|
-
Object.defineProperty(exports, "
|
|
306
|
+
Object.defineProperty(exports, "generatePostgresMigrationSQL", {
|
|
36
307
|
enumerable: true,
|
|
37
|
-
get: function () { return
|
|
308
|
+
get: function () { return chunk23NGZHUN_cjs.generatePostgresMigrationSQL; }
|
|
38
309
|
});
|
|
39
310
|
Object.defineProperty(exports, "nodes", {
|
|
40
311
|
enumerable: true,
|
|
41
|
-
get: function () { return
|
|
312
|
+
get: function () { return chunk23NGZHUN_cjs.nodes2; }
|
|
42
313
|
});
|
|
43
314
|
Object.defineProperty(exports, "schemaVersions", {
|
|
44
315
|
enumerable: true,
|
|
45
|
-
get: function () { return
|
|
316
|
+
get: function () { return chunk23NGZHUN_cjs.schemaVersions2; }
|
|
46
317
|
});
|
|
47
318
|
Object.defineProperty(exports, "tables", {
|
|
48
319
|
enumerable: true,
|
|
49
|
-
get: function () { return
|
|
320
|
+
get: function () { return chunk23NGZHUN_cjs.tables2; }
|
|
50
321
|
});
|
|
51
322
|
Object.defineProperty(exports, "uniques", {
|
|
52
323
|
enumerable: true,
|
|
53
|
-
get: function () { return
|
|
324
|
+
get: function () { return chunk23NGZHUN_cjs.uniques2; }
|
|
54
325
|
});
|
|
326
|
+
exports.createPostgresBackend = createPostgresBackend;
|
|
55
327
|
//# sourceMappingURL=index.cjs.map
|
|
56
328
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
|
1
|
+
{"version":3,"sources":["../../../src/backend/drizzle/execution/postgres-execution.ts","../../../src/backend/drizzle/postgres.ts"],"names":["compileQueryWithDialect","createNodeRowMapper","POSTGRES_ROW_MAPPER_CONFIG","createEdgeRowMapper","createUniqueRowMapper","createSchemaVersionRowMapper","formatPostgresTimestamp","POSTGRES_CAPABILITIES","tables","getTableName","createPostgresOperationStrategy","options","createCommonOperationBackend","nowIso","createPostgresVectorIndex","generateVectorIndexName","d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MAAA,CAAO,QAAA;AAAA,UACP,MAAA,CAAO,SAAA;AAAA,UACP;AAAA,SACF;AACA,QAAA,MAAM,MAAA,GAAS,MAAMC,yCAAA,CAAwB,EAAA,EAAI,SAAS,CAAA;AAC1D,QAAA,IAAI,CAAC,OAAO,OAAA,EAAS;AACnB,UAAA,MAAM,IAAI,KAAA;AAAA,YACR,OAAO,OAAA,IAAW;AAAA,WACpB;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAA;AAAA;AAAA,IAIA,MAAM,QAAW,KAAA,EAAmC;AAClD,MAAA,OAAO,gBAAA,CAAiB,QAAW,KAAK,CAAA;AAAA,IAC1C,CAAA;AAAA,IAEA,WAAW,KAAA,EAAmE;AAC5E,MAAA,OAAO,gBAAA,CAAiB,QAAQ,KAAK,CAAA;AAAA,IACvC;AAAA,GACF;AAEA,EAAA,OAAO,gBAAA;AACT;AAEA,SAAS,yBACP,OAAA,EACoB;AACpB,EAAA,MAAM,kBAAA,GACJ,OAAA,CAAQ,gBAAA,IAAoB,8BAAA,CAA+B,QAAQ,EAAE,CAAA;AAEvE,EAAA,OAAO,8BAAA,CAA+B;AAAA,IACpC,IAAI,OAAA,CAAQ,EAAA;AAAA,IACZ,gBAAA,EAAkB,kBAAA;AAAA,IAClB,mBAAmB,OAAA,CAAQ,iBAAA;AAAA,IAC3B,YAAY,OAAA,CAAQ;AAAA,GACrB,CAAA;AACH","file":"index.cjs","sourcesContent":["import { type SQL } from \"drizzle-orm\";\nimport { type PgDatabase, type PgQueryResultHKT } from \"drizzle-orm/pg-core\";\n\nimport {\n type CompiledSqlQuery,\n compileQueryWithDialect,\n type PreparedSqlStatement,\n type SqlExecutionAdapter,\n} from \"./types\";\n\ntype PgQueryResult = Readonly<{\n rows: readonly unknown[];\n}>;\n\ntype PgQueryClient = Readonly<{\n query: (sqlText: string, params: readonly unknown[]) => Promise<PgQueryResult>;\n}>;\n\ntype PgClientCarrier = Readonly<{\n $client?: PgQueryClient;\n}>;\n\nexport type AnyPgDatabase = PgDatabase<PgQueryResultHKT, Record<string, unknown>>;\n\nexport type PostgresExecutionAdapter = SqlExecutionAdapter;\n\nfunction resolvePgClient(db: AnyPgDatabase): PgQueryClient | undefined {\n const databaseWithClient = db as PgClientCarrier;\n const pgClient = databaseWithClient.$client;\n if (pgClient?.query === undefined) {\n return undefined;\n }\n return pgClient;\n}\n\nasync function executeDrizzleQuery<TRow>(\n db: AnyPgDatabase,\n query: SQL,\n): Promise<readonly TRow[]> {\n const result = (await db.execute(query)) as Readonly<{\n rows: readonly TRow[];\n }>;\n return result.rows;\n}\n\nfunction createPgPreparedStatement(\n pgClient: PgQueryClient,\n sqlText: string,\n): PreparedSqlStatement {\n return {\n async execute<TRow>(params: readonly unknown[]): Promise<readonly TRow[]> {\n const result = await pgClient.query(sqlText, params);\n return result.rows as readonly TRow[];\n },\n };\n}\n\nexport function createPostgresExecutionAdapter(\n db: AnyPgDatabase,\n): PostgresExecutionAdapter {\n const pgClient = resolvePgClient(db);\n\n function compile(query: SQL): CompiledSqlQuery {\n return compileQueryWithDialect(db, query, \"PostgreSQL\");\n }\n\n if (pgClient === undefined) {\n return {\n compile,\n async execute<TRow>(query: SQL): Promise<readonly TRow[]> {\n return executeDrizzleQuery<TRow>(db, query);\n },\n };\n }\n\n const pgQueryClient = pgClient;\n\n async function executeCompiled<TRow>(\n compiledQuery: CompiledSqlQuery,\n ): Promise<readonly TRow[]> {\n const result = await pgQueryClient.query(\n compiledQuery.sql,\n compiledQuery.params,\n );\n return result.rows as readonly TRow[];\n }\n\n return {\n compile,\n async execute<TRow>(query: SQL): Promise<readonly TRow[]> {\n return executeDrizzleQuery<TRow>(db, query);\n },\n executeCompiled,\n prepare(sqlText: string): PreparedSqlStatement {\n return createPgPreparedStatement(pgQueryClient, sqlText);\n },\n };\n}\n","/**\n * PostgreSQL backend adapter for TypeGraph.\n *\n * Works with any Drizzle PostgreSQL database instance:\n * - node-postgres (pg)\n * - PGlite\n * - Neon\n * - Vercel Postgres\n * - Supabase\n *\n * @example\n * ```typescript\n * import { drizzle } from \"drizzle-orm/node-postgres\";\n * import { Pool } from \"pg\";\n * import { createPostgresBackend, tables } from \"@nicia-ai/typegraph/postgres\";\n *\n * const pool = new Pool({ connectionString: process.env.DATABASE_URL });\n * const db = drizzle(pool);\n * const backend = createPostgresBackend(db, { tables });\n * ```\n */\nimport { getTableName, type SQL } from \"drizzle-orm\";\n\nimport type { SqlTableNames } from \"../../query/compiler/schema\";\nimport {\n type BackendCapabilities,\n type CreateVectorIndexParams,\n type DeleteEmbeddingParams,\n type DropVectorIndexParams,\n type EmbeddingRow,\n type GraphBackend,\n POSTGRES_CAPABILITIES,\n type TransactionBackend,\n type TransactionOptions,\n type UpsertEmbeddingParams,\n type VectorSearchParams,\n type VectorSearchResult,\n} from \"../types\";\nimport {\n type AnyPgDatabase,\n createPostgresExecutionAdapter,\n type PostgresExecutionAdapter,\n} from \"./execution/postgres-execution\";\nimport { createCommonOperationBackend } from \"./operation-backend-core\";\nimport { createPostgresOperationStrategy } from \"./operations/strategy\";\nimport {\n createEdgeRowMapper,\n createNodeRowMapper,\n createSchemaVersionRowMapper,\n createUniqueRowMapper,\n formatPostgresTimestamp,\n nowIso,\n POSTGRES_ROW_MAPPER_CONFIG,\n} from \"./row-mappers\";\nimport {\n type PostgresTables,\n tables as defaultTables,\n} from \"./schema/postgres\";\nimport {\n createPostgresVectorIndex,\n dropPostgresVectorIndex,\n generateVectorIndexName,\n type VectorIndexOptions,\n} from \"./vector-index\";\n\n// ============================================================\n// Types\n// ============================================================\n\n/**\n * Options for creating a PostgreSQL backend.\n */\nexport type PostgresBackendOptions = Readonly<{\n /**\n * Custom table definitions. Use createPostgresTables() to customize table names.\n * Defaults to standard TypeGraph table names.\n */\n tables?: PostgresTables;\n}>;\n\nconst POSTGRES_MAX_BIND_PARAMETERS = 65_535;\nconst NODE_INSERT_PARAM_COUNT = 9;\nconst EDGE_INSERT_PARAM_COUNT = 12;\nconst POSTGRES_NODE_INSERT_BATCH_SIZE = Math.max(\n 1,\n Math.floor(POSTGRES_MAX_BIND_PARAMETERS / NODE_INSERT_PARAM_COUNT),\n);\nconst POSTGRES_EDGE_INSERT_BATCH_SIZE = Math.max(\n 1,\n Math.floor(POSTGRES_MAX_BIND_PARAMETERS / EDGE_INSERT_PARAM_COUNT),\n);\nconst POSTGRES_GET_NODES_ID_CHUNK_SIZE = Math.max(\n 1,\n POSTGRES_MAX_BIND_PARAMETERS - 2,\n);\nconst POSTGRES_GET_EDGES_ID_CHUNK_SIZE = Math.max(\n 1,\n POSTGRES_MAX_BIND_PARAMETERS - 1,\n);\n\n// ============================================================\n// Utilities\n// ============================================================\n\nconst toNodeRow = createNodeRowMapper(POSTGRES_ROW_MAPPER_CONFIG);\nconst toEdgeRow = createEdgeRowMapper(POSTGRES_ROW_MAPPER_CONFIG);\nconst toUniqueRow = createUniqueRowMapper(POSTGRES_ROW_MAPPER_CONFIG);\nconst toSchemaVersionRow = createSchemaVersionRowMapper(POSTGRES_ROW_MAPPER_CONFIG);\n\n/**\n * Converts a database row to EmbeddingRow type.\n * Raw SQL returns snake_case column names.\n */\nfunction toEmbeddingRow(row: Record<string, unknown>): EmbeddingRow {\n // pgvector returns embedding as a string '[1,2,3]' or as parsed array\n let embedding: readonly number[];\n if (typeof row.embedding === \"string\") {\n const content = row.embedding.slice(1, -1);\n embedding = content === \"\" ? [] : content.split(\",\").map((s) => Number.parseFloat(s.trim()));\n } else if (Array.isArray(row.embedding)) {\n embedding = row.embedding as number[];\n } else {\n embedding = [];\n }\n\n return {\n graph_id: row.graph_id as string,\n node_kind: row.node_kind as string,\n node_id: row.node_id as string,\n field_path: row.field_path as string,\n embedding,\n dimensions: row.dimensions as number,\n created_at: formatPostgresTimestamp(row.created_at) ?? \"\",\n updated_at: formatPostgresTimestamp(row.updated_at) ?? \"\",\n };\n}\n\n/**\n * PostgreSQL capabilities with vector search support.\n * Extends base POSTGRES_CAPABILITIES with vector operations.\n */\nconst POSTGRES_VECTOR_CAPABILITIES: BackendCapabilities = {\n ...POSTGRES_CAPABILITIES,\n vector: {\n supported: true,\n metrics: [\"cosine\", \"l2\", \"inner_product\"] as const,\n indexTypes: [\"hnsw\", \"ivfflat\", \"none\"] as const,\n maxDimensions: 16_000, // pgvector limit\n },\n};\n\n// ============================================================\n// Backend Factory\n// ============================================================\n\n/**\n * Creates a TypeGraph backend for PostgreSQL databases.\n *\n * Works with any Drizzle PostgreSQL instance regardless of the underlying driver.\n *\n * @param db - A Drizzle PostgreSQL database instance\n * @param options - Backend configuration\n * @returns A GraphBackend implementation\n */\nexport function createPostgresBackend(\n db: AnyPgDatabase,\n options: PostgresBackendOptions = {},\n): GraphBackend {\n const tables = options.tables ?? defaultTables;\n const executionAdapter = createPostgresExecutionAdapter(db);\n const tableNames: SqlTableNames = {\n nodes: getTableName(tables.nodes),\n edges: getTableName(tables.edges),\n embeddings: getTableName(tables.embeddings),\n };\n const operationStrategy = createPostgresOperationStrategy(tables);\n const operations = createPostgresOperationBackend({\n db,\n executionAdapter,\n operationStrategy,\n tableNames,\n });\n\n const backend: GraphBackend = {\n ...operations,\n\n async setActiveSchema(graphId: string, version: number): Promise<void> {\n await backend.transaction(async (txBackend) => {\n await txBackend.setActiveSchema(graphId, version);\n });\n },\n\n async transaction<T>(\n fn: (tx: TransactionBackend) => Promise<T>,\n options?: TransactionOptions,\n ): Promise<T> {\n const txConfig = options?.isolationLevel\n ? {\n isolationLevel: options.isolationLevel.replace(\"_\", \" \") as\n | \"read uncommitted\"\n | \"read committed\"\n | \"repeatable read\"\n | \"serializable\",\n }\n : undefined;\n\n return db.transaction(async (tx) => {\n const txBackend = createTransactionBackend({\n db: tx as AnyPgDatabase,\n operationStrategy,\n tableNames,\n });\n return fn(txBackend);\n }, txConfig);\n },\n\n async close(): Promise<void> {\n // Drizzle doesn't expose a close method\n // Users manage connection lifecycle themselves\n },\n };\n\n return backend;\n}\n\ntype CreatePostgresOperationBackendOptions = Readonly<{\n db: AnyPgDatabase;\n executionAdapter: PostgresExecutionAdapter;\n operationStrategy: ReturnType<typeof createPostgresOperationStrategy>;\n tableNames: SqlTableNames;\n}>;\n\ntype CreatePostgresTransactionBackendOptions = Readonly<{\n db: AnyPgDatabase;\n executionAdapter?: PostgresExecutionAdapter;\n operationStrategy: ReturnType<typeof createPostgresOperationStrategy>;\n tableNames: SqlTableNames;\n}>;\n\nfunction createPostgresOperationBackend(\n options: CreatePostgresOperationBackendOptions,\n): TransactionBackend {\n const { db, executionAdapter, operationStrategy, tableNames } = options;\n\n async function execAll<T>(query: SQL): Promise<T[]> {\n const result = (await db.execute(query)) as Readonly<{\n rows: T[];\n }>;\n return result.rows;\n }\n\n async function execGet<T>(query: SQL): Promise<T | undefined> {\n const result = (await db.execute(query)) as Readonly<{\n rows: T[];\n }>;\n return result.rows[0];\n }\n\n async function execRun(query: SQL): Promise<void> {\n await db.execute(query);\n }\n\n const commonBackend = createCommonOperationBackend({\n batchConfig: {\n edgeInsertBatchSize: POSTGRES_EDGE_INSERT_BATCH_SIZE,\n getEdgesChunkSize: POSTGRES_GET_EDGES_ID_CHUNK_SIZE,\n getNodesChunkSize: POSTGRES_GET_NODES_ID_CHUNK_SIZE,\n nodeInsertBatchSize: POSTGRES_NODE_INSERT_BATCH_SIZE,\n },\n execution: {\n execAll,\n execGet,\n execRun,\n },\n nowIso,\n operationStrategy,\n rowMappers: {\n toEdgeRow,\n toNodeRow,\n toSchemaVersionRow,\n toUniqueRow,\n },\n });\n\n const executeCompiled = executionAdapter.executeCompiled;\n const executeRawMethod: Pick<TransactionBackend, \"executeRaw\"> =\n executeCompiled === undefined ?\n {}\n : {\n async executeRaw<T>(\n sqlText: string,\n params: readonly unknown[],\n ): Promise<readonly T[]> {\n return executeCompiled<T>({ params, sql: sqlText });\n },\n };\n\n const operationBackend: TransactionBackend = {\n ...commonBackend,\n ...executeRawMethod,\n capabilities: POSTGRES_VECTOR_CAPABILITIES,\n dialect: \"postgres\",\n tableNames,\n\n // === Embedding Operations ===\n\n async upsertEmbedding(params: UpsertEmbeddingParams): Promise<void> {\n const timestamp = nowIso();\n const query = operationStrategy.buildUpsertEmbedding(params, timestamp);\n await execRun(query);\n },\n\n async deleteEmbedding(params: DeleteEmbeddingParams): Promise<void> {\n const query = operationStrategy.buildDeleteEmbedding(params);\n await execRun(query);\n },\n\n async getEmbedding(\n graphId: string,\n nodeKind: string,\n nodeId: string,\n fieldPath: string,\n ): Promise<EmbeddingRow | undefined> {\n const query = operationStrategy.buildGetEmbedding(\n graphId,\n nodeKind,\n nodeId,\n fieldPath,\n );\n const row = await execGet<Record<string, unknown>>(query);\n return row ? toEmbeddingRow(row) : undefined;\n },\n\n async vectorSearch(\n params: VectorSearchParams,\n ): Promise<readonly VectorSearchResult[]> {\n const query = operationStrategy.buildVectorSearch(params);\n const rows = await execAll<{ node_id: string; score: number }>(query);\n return rows.map((row) => ({\n nodeId: row.node_id,\n score: row.score,\n }));\n },\n\n async createVectorIndex(params: CreateVectorIndexParams): Promise<void> {\n const indexOptions: VectorIndexOptions = {\n graphId: params.graphId,\n nodeKind: params.nodeKind,\n fieldPath: params.fieldPath,\n dimensions: params.dimensions,\n embeddingsTableName: tableNames.embeddings,\n indexType: params.indexType,\n metric: params.metric,\n ...(params.indexParams?.m === undefined\n ? {}\n : { hnswM: params.indexParams.m }),\n ...(params.indexParams?.efConstruction === undefined\n ? {}\n : { hnswEfConstruction: params.indexParams.efConstruction }),\n ...(params.indexParams?.lists === undefined\n ? {}\n : { ivfflatLists: params.indexParams.lists }),\n };\n\n const result = await createPostgresVectorIndex(db, indexOptions);\n\n if (!result.success) {\n throw new Error(\n result.message ?? \"Failed to create PostgreSQL vector index\",\n );\n }\n },\n\n async dropVectorIndex(params: DropVectorIndexParams): Promise<void> {\n const metrics =\n POSTGRES_VECTOR_CAPABILITIES.vector?.metrics ?? ([\"cosine\"] as const);\n\n for (const metric of metrics) {\n const indexName = generateVectorIndexName(\n params.graphId,\n params.nodeKind,\n params.fieldPath,\n metric,\n );\n const result = await dropPostgresVectorIndex(db, indexName);\n if (!result.success) {\n throw new Error(\n result.message ?? \"Failed to drop PostgreSQL vector index\",\n );\n }\n }\n },\n\n // === Query Execution ===\n\n async execute<T>(query: SQL): Promise<readonly T[]> {\n return executionAdapter.execute<T>(query);\n },\n\n compileSql(query: SQL): Readonly<{ sql: string; params: readonly unknown[] }> {\n return executionAdapter.compile(query);\n },\n };\n\n return operationBackend;\n}\n\nfunction createTransactionBackend(\n options: CreatePostgresTransactionBackendOptions,\n): TransactionBackend {\n const txExecutionAdapter =\n options.executionAdapter ?? createPostgresExecutionAdapter(options.db);\n\n return createPostgresOperationBackend({\n db: options.db,\n executionAdapter: txExecutionAdapter,\n operationStrategy: options.operationStrategy,\n tableNames: options.tableNames,\n });\n}\n\n// Re-export schema utilities\nexport type { PostgresTableNames,PostgresTables } from \"./schema/postgres\";\nexport { createPostgresTables, tables } from \"./schema/postgres\";\n"]}
|
|
@@ -1,13 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { G as GraphBackend } from '../../types-SVDEKnU6.cjs';
|
|
2
|
+
import { PgDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';
|
|
3
|
+
import { P as PostgresTables } from '../../ddl-Bcyb4DW1.cjs';
|
|
4
|
+
export { C as CreatePostgresTablesOptions, b as PostgresTableNames, c as createPostgresTables, e as edges, d as embeddings, f as generatePostgresDDL, h as generatePostgresMigrationSQL, n as nodes, s as schemaVersions, t as tables, u as uniques } from '../../ddl-Bcyb4DW1.cjs';
|
|
5
5
|
import 'drizzle-orm';
|
|
6
|
-
import '../../types-
|
|
6
|
+
import '../../types-DolHw9pJ.cjs';
|
|
7
7
|
import 'zod';
|
|
8
|
-
import '../../types-
|
|
9
|
-
import '
|
|
10
|
-
import '../../
|
|
11
|
-
import '../../ast-D-3bOanX.cjs';
|
|
12
|
-
import '../drizzle/schema/sqlite.cjs';
|
|
8
|
+
import '../../types-BbMn2Ycv.cjs';
|
|
9
|
+
import '../../ast-Cq9qrnNP.cjs';
|
|
10
|
+
import '../../sqlite-FWGZLwDd.cjs';
|
|
13
11
|
import 'drizzle-orm/sqlite-core';
|
|
12
|
+
|
|
13
|
+
type AnyPgDatabase = PgDatabase<PgQueryResultHKT, Record<string, unknown>>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Options for creating a PostgreSQL backend.
|
|
17
|
+
*/
|
|
18
|
+
type PostgresBackendOptions = Readonly<{
|
|
19
|
+
/**
|
|
20
|
+
* Custom table definitions. Use createPostgresTables() to customize table names.
|
|
21
|
+
* Defaults to standard TypeGraph table names.
|
|
22
|
+
*/
|
|
23
|
+
tables?: PostgresTables;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a TypeGraph backend for PostgreSQL databases.
|
|
27
|
+
*
|
|
28
|
+
* Works with any Drizzle PostgreSQL instance regardless of the underlying driver.
|
|
29
|
+
*
|
|
30
|
+
* @param db - A Drizzle PostgreSQL database instance
|
|
31
|
+
* @param options - Backend configuration
|
|
32
|
+
* @returns A GraphBackend implementation
|
|
33
|
+
*/
|
|
34
|
+
declare function createPostgresBackend(db: AnyPgDatabase, options?: PostgresBackendOptions): GraphBackend;
|
|
35
|
+
|
|
36
|
+
export { type PostgresBackendOptions, PostgresTables, createPostgresBackend };
|
|
@@ -1,13 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { G as GraphBackend } from '../../types-D5ggX07j.js';
|
|
2
|
+
import { PgDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';
|
|
3
|
+
import { P as PostgresTables } from '../../ddl-D7DQx8w8.js';
|
|
4
|
+
export { C as CreatePostgresTablesOptions, b as PostgresTableNames, c as createPostgresTables, e as edges, d as embeddings, f as generatePostgresDDL, h as generatePostgresMigrationSQL, n as nodes, s as schemaVersions, t as tables, u as uniques } from '../../ddl-D7DQx8w8.js';
|
|
5
5
|
import 'drizzle-orm';
|
|
6
|
-
import '../../types-
|
|
6
|
+
import '../../types-DolHw9pJ.js';
|
|
7
7
|
import 'zod';
|
|
8
|
-
import '../../types-
|
|
9
|
-
import '
|
|
10
|
-
import '../../
|
|
11
|
-
import '../../ast-CXFx6bF6.js';
|
|
12
|
-
import '../drizzle/schema/sqlite.js';
|
|
8
|
+
import '../../types-C2rhqkg7.js';
|
|
9
|
+
import '../../ast-CG87Zr6p.js';
|
|
10
|
+
import '../../sqlite-CSJ-fgIm.js';
|
|
13
11
|
import 'drizzle-orm/sqlite-core';
|
|
12
|
+
|
|
13
|
+
type AnyPgDatabase = PgDatabase<PgQueryResultHKT, Record<string, unknown>>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Options for creating a PostgreSQL backend.
|
|
17
|
+
*/
|
|
18
|
+
type PostgresBackendOptions = Readonly<{
|
|
19
|
+
/**
|
|
20
|
+
* Custom table definitions. Use createPostgresTables() to customize table names.
|
|
21
|
+
* Defaults to standard TypeGraph table names.
|
|
22
|
+
*/
|
|
23
|
+
tables?: PostgresTables;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a TypeGraph backend for PostgreSQL databases.
|
|
27
|
+
*
|
|
28
|
+
* Works with any Drizzle PostgreSQL instance regardless of the underlying driver.
|
|
29
|
+
*
|
|
30
|
+
* @param db - A Drizzle PostgreSQL database instance
|
|
31
|
+
* @param options - Backend configuration
|
|
32
|
+
* @returns A GraphBackend implementation
|
|
33
|
+
*/
|
|
34
|
+
declare function createPostgresBackend(db: AnyPgDatabase, options?: PostgresBackendOptions): GraphBackend;
|
|
35
|
+
|
|
36
|
+
export { type PostgresBackendOptions, PostgresTables, createPostgresBackend };
|