interaqt 2.0.3 → 2.0.4
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/agent/agentspace/knowledge/usage/12-data-querying.md +13 -0
- package/dist/builtins/interaction/activity/ActivityCall.d.ts.map +1 -1
- package/dist/builtins/interaction/activity/ActivityManager.d.ts.map +1 -1
- package/dist/core/Entity.d.ts.map +1 -1
- package/dist/core/Property.d.ts.map +1 -1
- package/dist/core/Relation.d.ts.map +1 -1
- package/dist/drivers/Mysql.d.ts +1 -0
- package/dist/drivers/Mysql.d.ts.map +1 -1
- package/dist/drivers/PGLite.d.ts +1 -0
- package/dist/drivers/PGLite.d.ts.map +1 -1
- package/dist/drivers/PostgreSQL.d.ts +1 -0
- package/dist/drivers/PostgreSQL.d.ts.map +1 -1
- package/dist/drivers/SQLite.d.ts +1 -1
- package/dist/drivers/SQLite.d.ts.map +1 -1
- package/dist/drivers.js +115 -108
- package/dist/drivers.js.map +1 -1
- package/dist/index.js +1094 -1050
- package/dist/index.js.map +1 -1
- package/dist/runtime/Controller.d.ts.map +1 -1
- package/dist/runtime/System.d.ts +1 -0
- package/dist/runtime/System.d.ts.map +1 -1
- package/dist/storage/erstorage/MatchExp.d.ts.map +1 -1
- package/dist/storage/erstorage/QueryExecutor.d.ts.map +1 -1
- package/dist/storage/erstorage/RecordQuery.d.ts.map +1 -1
- package/dist/storage/erstorage/SQLBuilder.d.ts +8 -2
- package/dist/storage/erstorage/SQLBuilder.d.ts.map +1 -1
- package/dist/storage/erstorage/UpdateExecutor.d.ts.map +1 -1
- package/dist/storage/utils.d.ts +8 -0
- package/dist/storage/utils.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/drivers.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import N from "better-sqlite3";
|
|
2
|
-
import { sqliteEncodeLiteral as I, dbConsoleLogger as S, asyncInteractionContext as l, ROW_ID_ATTR as
|
|
2
|
+
import { sqliteEncodeLiteral as I, dbConsoleLogger as S, asyncInteractionContext as l, ROW_ID_ATTR as m, defaultEncodeLiteral as y, RequireSerializableRetry as b } from "interaqt";
|
|
3
3
|
import { AsyncLocalStorage as A } from "node:async_hooks";
|
|
4
4
|
import { createHash as L } from "node:crypto";
|
|
5
|
-
import
|
|
6
|
-
import { PGlite as
|
|
7
|
-
import
|
|
8
|
-
let
|
|
5
|
+
import R from "pg";
|
|
6
|
+
import { PGlite as w } from "@electric-sql/pglite";
|
|
7
|
+
import E from "mysql2/promise";
|
|
8
|
+
let O = class {
|
|
9
9
|
constructor(e) {
|
|
10
10
|
this.db = e;
|
|
11
11
|
}
|
|
@@ -46,10 +46,17 @@ class K {
|
|
|
46
46
|
supportsCreateIndexIfNotExists: !0,
|
|
47
47
|
encodeLiteral: I,
|
|
48
48
|
constraints: { unique: !0, filteredUnique: !0, nonNull: !1 }
|
|
49
|
-
}, this.idSystem = new
|
|
49
|
+
}, this.idSystem = new O(this), this.logger = this.options?.logger || S;
|
|
50
50
|
}
|
|
51
|
-
async open() {
|
|
52
|
-
this.db = new N(this.file, this.options),
|
|
51
|
+
async open(e = !1) {
|
|
52
|
+
if (this.db = new N(this.file, this.options), e) {
|
|
53
|
+
const t = this.db.prepare(
|
|
54
|
+
"SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%'"
|
|
55
|
+
).all();
|
|
56
|
+
for (const s of t)
|
|
57
|
+
this.db.prepare(`DROP TABLE IF EXISTS "${s.name.replace(/"/g, '""')}"`).run();
|
|
58
|
+
}
|
|
59
|
+
await this.idSystem.setup();
|
|
53
60
|
}
|
|
54
61
|
async openForSchemaRead() {
|
|
55
62
|
this.db = new N(this.file, this.options);
|
|
@@ -75,40 +82,40 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
|
|
|
75
82
|
)`, "setup scoped sequence table");
|
|
76
83
|
}
|
|
77
84
|
async query(e, t = [], s = "") {
|
|
78
|
-
const r = l.getStore(), n = this.logger.child(r?.logContext || {}),
|
|
85
|
+
const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((a) => a === !1 ? 0 : a === !0 ? 1 : a);
|
|
79
86
|
return n.info({
|
|
80
87
|
type: "query",
|
|
81
88
|
name: s,
|
|
82
89
|
sql: e,
|
|
83
|
-
params:
|
|
84
|
-
}), this.db.prepare(e).all(...
|
|
90
|
+
params: o
|
|
91
|
+
}), this.db.prepare(e).all(...o);
|
|
85
92
|
}
|
|
86
93
|
async update(e, t, s, r = "") {
|
|
87
|
-
const n = l.getStore(),
|
|
88
|
-
return
|
|
94
|
+
const n = l.getStore(), o = this.logger.child(n?.logContext || {}), a = `${e} ${s ? `RETURNING ${s} AS id` : ""}`, i = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c === !1 ? 0 : c === !0 ? 1 : c);
|
|
95
|
+
return o.info({
|
|
89
96
|
type: "update",
|
|
90
97
|
name: r,
|
|
91
|
-
sql:
|
|
98
|
+
sql: a,
|
|
92
99
|
params: i
|
|
93
|
-
}), s ? this.db.prepare(
|
|
100
|
+
}), s ? this.db.prepare(a).all(...i) : this.db.prepare(a).run(...i);
|
|
94
101
|
}
|
|
95
102
|
async insert(e, t, s = "") {
|
|
96
|
-
const r = l.getStore(), n = this.logger.child(r?.logContext || {}),
|
|
103
|
+
const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i === !1 ? 0 : i === !0 ? 1 : i);
|
|
97
104
|
return n.info({
|
|
98
105
|
type: "insert",
|
|
99
106
|
name: s,
|
|
100
107
|
sql: e,
|
|
101
|
-
params:
|
|
102
|
-
}), this.db.prepare(`${e} RETURNING ${
|
|
108
|
+
params: o
|
|
109
|
+
}), this.db.prepare(`${e} RETURNING ${m}`).all(...o)[0];
|
|
103
110
|
}
|
|
104
111
|
async delete(e, t, s = "") {
|
|
105
|
-
const r = l.getStore(), n = this.logger.child(r?.logContext || {}),
|
|
112
|
+
const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((a) => a === !1 ? 0 : a === !0 ? 1 : a);
|
|
106
113
|
return n.info({
|
|
107
114
|
type: "delete",
|
|
108
115
|
name: s,
|
|
109
116
|
sql: e,
|
|
110
|
-
params:
|
|
111
|
-
}), this.db.prepare(e).run(...
|
|
117
|
+
params: o
|
|
118
|
+
}), this.db.prepare(e).run(...o);
|
|
112
119
|
}
|
|
113
120
|
async scheme(e, t = "") {
|
|
114
121
|
const s = l.getStore();
|
|
@@ -124,13 +131,13 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
|
|
|
124
131
|
async getAutoId(e) {
|
|
125
132
|
return this.idSystem.getAutoId(e);
|
|
126
133
|
}
|
|
127
|
-
parseMatchExpression(e, t, s, r, n,
|
|
134
|
+
parseMatchExpression(e, t, s, r, n, o, a) {
|
|
128
135
|
if (r === "JSON" && t[0].toLowerCase() === "contains")
|
|
129
136
|
return {
|
|
130
137
|
fieldValue: `NOT NULL AND EXISTS (
|
|
131
138
|
SELECT 1
|
|
132
139
|
FROM json_each(${s})
|
|
133
|
-
WHERE json_each.value = ${
|
|
140
|
+
WHERE json_each.value = ${a()}
|
|
134
141
|
)`,
|
|
135
142
|
fieldParams: [t[1]]
|
|
136
143
|
};
|
|
@@ -139,7 +146,7 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
|
|
|
139
146
|
return e === "pk" ? "INTEGER PRIMARY KEY" : e === "id" ? "INT" : t || e === "object" || e === "json" ? "JSON" : e === "string" ? "TEXT" : e === "boolean" ? "INT(2)" : e === "number" || e === "timestamp" ? "INT" : e;
|
|
140
147
|
}
|
|
141
148
|
}
|
|
142
|
-
const { Client: g, Pool:
|
|
149
|
+
const { Client: g, Pool: C } = R;
|
|
143
150
|
let q = class {
|
|
144
151
|
constructor(e) {
|
|
145
152
|
this.db = e, this.initialized = /* @__PURE__ */ new Set(), this.recordToSequenceName = /* @__PURE__ */ new Map();
|
|
@@ -168,9 +175,9 @@ let q = class {
|
|
|
168
175
|
for (const r of e) {
|
|
169
176
|
const n = this.sequenceNameForKey(`${r.tableName}.${r.idField}`, r.tableName);
|
|
170
177
|
this.recordToSequenceName.set(r.recordName, n);
|
|
171
|
-
const
|
|
172
|
-
await this.db.scheme(`CREATE SEQUENCE IF NOT EXISTS ${
|
|
173
|
-
const
|
|
178
|
+
const o = this.quoteIdentifier(n);
|
|
179
|
+
await this.db.scheme(`CREATE SEQUENCE IF NOT EXISTS ${o} START WITH 1`, `create sequence ${r.recordName}`);
|
|
180
|
+
const a = await this.db.query(
|
|
174
181
|
`SELECT COALESCE(MAX("${r.idField}"), 0) AS max FROM ${this.quoteIdentifier(r.tableName)}`,
|
|
175
182
|
[],
|
|
176
183
|
`read max id for ${r.recordName}`
|
|
@@ -184,8 +191,8 @@ let q = class {
|
|
|
184
191
|
);
|
|
185
192
|
i = Number(u[0]?.last ?? 0);
|
|
186
193
|
}
|
|
187
|
-
const c = Math.max(Number(
|
|
188
|
-
s.set(
|
|
194
|
+
const c = Math.max(Number(a[0]?.max ?? 0), i);
|
|
195
|
+
s.set(o, Math.max(s.get(o) ?? 0, c)), this.initialized.add(r.recordName);
|
|
189
196
|
}
|
|
190
197
|
for (const [r, n] of s)
|
|
191
198
|
n >= 1 && await this.db.query(
|
|
@@ -207,7 +214,7 @@ let q = class {
|
|
|
207
214
|
};
|
|
208
215
|
class G {
|
|
209
216
|
constructor(e, t = {}) {
|
|
210
|
-
this.database = e, this.options = t, this.transactionContext = new A(), this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.transactionCapability = {
|
|
217
|
+
this.database = e, this.options = t, this.transactionContext = new A(), this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.returnsParsedJSON = !0, this.transactionCapability = {
|
|
211
218
|
transactions: !0,
|
|
212
219
|
isolationLevels: ["READ COMMITTED", "SERIALIZABLE"],
|
|
213
220
|
transactionBoundConnection: !0,
|
|
@@ -245,7 +252,7 @@ class G {
|
|
|
245
252
|
}));
|
|
246
253
|
}
|
|
247
254
|
createPool() {
|
|
248
|
-
const e = new
|
|
255
|
+
const e = new C({
|
|
249
256
|
...this.options,
|
|
250
257
|
database: this.database
|
|
251
258
|
});
|
|
@@ -279,21 +286,21 @@ class G {
|
|
|
279
286
|
}
|
|
280
287
|
if (!this.pool)
|
|
281
288
|
throw new Error("PostgreSQL pool is not initialized. Call open() before starting a transaction.");
|
|
282
|
-
const r = e.isolation ?? "READ COMMITTED", n = await this.pool.connect(),
|
|
283
|
-
let
|
|
289
|
+
const r = e.isolation ?? "READ COMMITTED", n = await this.pool.connect(), o = { client: n, depth: 1, isolation: r };
|
|
290
|
+
let a = !1;
|
|
284
291
|
try {
|
|
285
292
|
await n.query(`BEGIN ISOLATION LEVEL ${r}`);
|
|
286
|
-
const i = await this.transactionContext.run(
|
|
293
|
+
const i = await this.transactionContext.run(o, t);
|
|
287
294
|
return await n.query("COMMIT"), i;
|
|
288
295
|
} catch (i) {
|
|
289
296
|
try {
|
|
290
297
|
await n.query("ROLLBACK");
|
|
291
298
|
} finally {
|
|
292
|
-
n.release(),
|
|
299
|
+
n.release(), a = !0;
|
|
293
300
|
}
|
|
294
301
|
throw i;
|
|
295
302
|
} finally {
|
|
296
|
-
|
|
303
|
+
a || n.release();
|
|
297
304
|
}
|
|
298
305
|
}
|
|
299
306
|
async setupInternalComputationState() {
|
|
@@ -317,42 +324,42 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
|
|
|
317
324
|
)`, "setup scoped sequence table");
|
|
318
325
|
}
|
|
319
326
|
async query(e, t = [], s = "") {
|
|
320
|
-
const r = l.getStore(), n = this.logger.child(r?.logContext || {}),
|
|
327
|
+
const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t;
|
|
321
328
|
return n.info({
|
|
322
329
|
type: "query",
|
|
323
330
|
name: s,
|
|
324
331
|
sql: e,
|
|
325
|
-
params:
|
|
326
|
-
}), (await this.getQueryable().query(e,
|
|
332
|
+
params: o
|
|
333
|
+
}), (await this.getQueryable().query(e, o)).rows;
|
|
327
334
|
}
|
|
328
335
|
async update(e, t, s, r = "") {
|
|
329
|
-
const n = l.getStore(),
|
|
330
|
-
return
|
|
336
|
+
const n = l.getStore(), o = this.logger.child(n?.logContext || {}), a = `${e} ${s ? `RETURNING "${s}" AS id` : ""}`, i = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c);
|
|
337
|
+
return o.info({
|
|
331
338
|
type: "update",
|
|
332
339
|
name: r,
|
|
333
|
-
sql:
|
|
340
|
+
sql: a,
|
|
334
341
|
params: i
|
|
335
|
-
}), (await this.getQueryable().query(
|
|
342
|
+
}), (await this.getQueryable().query(a, i)).rows;
|
|
336
343
|
}
|
|
337
344
|
async insert(e, t, s = "") {
|
|
338
|
-
const r = l.getStore(), n = this.logger.child(r?.logContext || {}),
|
|
345
|
+
const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i);
|
|
339
346
|
n.info({
|
|
340
347
|
type: "insert",
|
|
341
348
|
name: s,
|
|
342
349
|
sql: e,
|
|
343
|
-
params:
|
|
350
|
+
params: o
|
|
344
351
|
});
|
|
345
|
-
const
|
|
346
|
-
return (await this.getQueryable().query(
|
|
352
|
+
const a = `${e} RETURNING "${m}"`;
|
|
353
|
+
return (await this.getQueryable().query(a, o)).rows[0];
|
|
347
354
|
}
|
|
348
355
|
async delete(e, t, s = "") {
|
|
349
|
-
const r = l.getStore(), n = this.logger.child(r?.logContext || {}),
|
|
356
|
+
const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t;
|
|
350
357
|
return n.info({
|
|
351
358
|
type: "delete",
|
|
352
359
|
name: s,
|
|
353
360
|
sql: e,
|
|
354
|
-
params:
|
|
355
|
-
}), (await this.getQueryable().query(e,
|
|
361
|
+
params: o
|
|
362
|
+
}), (await this.getQueryable().query(e, o)).rows;
|
|
356
363
|
}
|
|
357
364
|
async scheme(e, t = "") {
|
|
358
365
|
const s = l.getStore();
|
|
@@ -371,23 +378,23 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
|
|
|
371
378
|
setupRecordSequences(e) {
|
|
372
379
|
return this.idSystem.setupSequences(e);
|
|
373
380
|
}
|
|
374
|
-
parseMatchExpression(e, t, s, r, n,
|
|
381
|
+
parseMatchExpression(e, t, s, r, n, o, a) {
|
|
375
382
|
if (r === "JSON") {
|
|
376
383
|
if (t[0].toLowerCase() === "contains") {
|
|
377
384
|
const c = s.split(".").map((u) => `"${u}"`).join(".");
|
|
378
385
|
return {
|
|
379
|
-
fieldValue: `IS NOT NULL AND ${
|
|
386
|
+
fieldValue: `IS NOT NULL AND ${a()} = ANY (SELECT json_array_elements_text(${c}))`,
|
|
380
387
|
fieldParams: [t[1]]
|
|
381
388
|
};
|
|
382
389
|
}
|
|
383
390
|
if (t[0] === "=" || t[0] === "!=")
|
|
384
391
|
return {
|
|
385
|
-
fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")}::jsonb ${t[0]} ${
|
|
392
|
+
fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")}::jsonb ${t[0]} ${a()}::jsonb`,
|
|
386
393
|
fieldParams: [JSON.stringify(t[1])]
|
|
387
394
|
};
|
|
388
395
|
const i = t[0].toLowerCase();
|
|
389
396
|
if ((i === "in" || i === "not in") && Array.isArray(t[1]) && t[1].length > 0) {
|
|
390
|
-
const c = s.split(".").map((h) => `"${h}"`).join("."), u = t[1].map(() => `${
|
|
397
|
+
const c = s.split(".").map((h) => `"${h}"`).join("."), u = t[1].map(() => `${a()}::jsonb`).join(",");
|
|
391
398
|
return {
|
|
392
399
|
fieldValue: `IS NOT NULL AND ${c}::jsonb ${i === "in" ? "IN" : "NOT IN"} (${u})`,
|
|
393
400
|
fieldParams: t[1].map((h) => JSON.stringify(h))
|
|
@@ -454,28 +461,28 @@ class f {
|
|
|
454
461
|
*/
|
|
455
462
|
static parse(e) {
|
|
456
463
|
var t, s, r, n;
|
|
457
|
-
let
|
|
464
|
+
let o;
|
|
458
465
|
switch (e.length) {
|
|
459
466
|
case 32:
|
|
460
|
-
|
|
467
|
+
o = (t = /^[0-9a-f]{32}$/i.exec(e)) === null || t === void 0 ? void 0 : t[0];
|
|
461
468
|
break;
|
|
462
469
|
case 36:
|
|
463
|
-
|
|
470
|
+
o = (s = /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i.exec(e)) === null || s === void 0 ? void 0 : s.slice(1, 6).join("");
|
|
464
471
|
break;
|
|
465
472
|
case 38:
|
|
466
|
-
|
|
473
|
+
o = (r = /^\{([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})\}$/i.exec(e)) === null || r === void 0 ? void 0 : r.slice(1, 6).join("");
|
|
467
474
|
break;
|
|
468
475
|
case 45:
|
|
469
|
-
|
|
476
|
+
o = (n = /^urn:uuid:([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i.exec(e)) === null || n === void 0 ? void 0 : n.slice(1, 6).join("");
|
|
470
477
|
break;
|
|
471
478
|
}
|
|
472
|
-
if (
|
|
473
|
-
const
|
|
479
|
+
if (o) {
|
|
480
|
+
const a = new Uint8Array(16);
|
|
474
481
|
for (let i = 0; i < 16; i += 4) {
|
|
475
|
-
const c = parseInt(
|
|
476
|
-
|
|
482
|
+
const c = parseInt(o.substring(2 * i, 2 * i + 8), 16);
|
|
483
|
+
a[i + 0] = c >>> 24, a[i + 1] = c >>> 16, a[i + 2] = c >>> 8, a[i + 3] = c;
|
|
477
484
|
}
|
|
478
|
-
return new f(
|
|
485
|
+
return new f(a);
|
|
479
486
|
} else
|
|
480
487
|
throw new SyntaxError("could not parse UUID string");
|
|
481
488
|
}
|
|
@@ -680,7 +687,7 @@ let P = class {
|
|
|
680
687
|
};
|
|
681
688
|
class z {
|
|
682
689
|
constructor(e, t = {}) {
|
|
683
|
-
this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.transactionCapability = {
|
|
690
|
+
this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.returnsParsedJSON = !0, this.transactionCapability = {
|
|
684
691
|
transactions: !0,
|
|
685
692
|
isolationLevels: ["READ COMMITTED", "SERIALIZABLE"],
|
|
686
693
|
transactionBoundConnection: !1,
|
|
@@ -702,7 +709,7 @@ class z {
|
|
|
702
709
|
supportsCreateIndexIfNotExists: !0,
|
|
703
710
|
encodeLiteral: y,
|
|
704
711
|
constraints: { unique: !0, filteredUnique: !0, nonNull: !0 }
|
|
705
|
-
}, this.idSystem = new P(this), this.logger = this.options?.logger || S, this.db = new
|
|
712
|
+
}, this.idSystem = new P(this), this.logger = this.options?.logger || S, this.db = new w(this.database);
|
|
706
713
|
}
|
|
707
714
|
async open(e = !1) {
|
|
708
715
|
if (e) {
|
|
@@ -749,42 +756,42 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
|
|
|
749
756
|
});
|
|
750
757
|
try {
|
|
751
758
|
return (await this.db.query(e, t)).rows;
|
|
752
|
-
} catch (
|
|
759
|
+
} catch (o) {
|
|
753
760
|
throw n.error({
|
|
754
761
|
type: "query",
|
|
755
762
|
name: s,
|
|
756
763
|
sql: e,
|
|
757
764
|
params: t,
|
|
758
|
-
error:
|
|
759
|
-
}),
|
|
765
|
+
error: o instanceof Error ? o.message : String(o)
|
|
766
|
+
}), o;
|
|
760
767
|
}
|
|
761
768
|
}
|
|
762
769
|
async update(e, t, s, r = "") {
|
|
763
|
-
const n = l.getStore(),
|
|
764
|
-
return
|
|
770
|
+
const n = l.getStore(), o = this.logger.child(n?.logContext || {}), a = `${e} ${s ? `RETURNING "${s}" AS id` : ""}`, i = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c);
|
|
771
|
+
return o.info({
|
|
765
772
|
type: "update",
|
|
766
773
|
name: r,
|
|
767
|
-
sql:
|
|
774
|
+
sql: a,
|
|
768
775
|
params: i
|
|
769
|
-
}), (await this.db.query(
|
|
776
|
+
}), (await this.db.query(a, i)).rows;
|
|
770
777
|
}
|
|
771
778
|
async insert(e, t, s = "") {
|
|
772
|
-
const r = l.getStore(), n = this.logger.child(r?.logContext || {}),
|
|
779
|
+
const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i);
|
|
773
780
|
n.info({
|
|
774
781
|
type: "insert",
|
|
775
782
|
name: s,
|
|
776
783
|
sql: e,
|
|
777
|
-
params:
|
|
784
|
+
params: o
|
|
778
785
|
});
|
|
779
|
-
const
|
|
786
|
+
const a = `${e} RETURNING "${m}"`;
|
|
780
787
|
try {
|
|
781
|
-
return (await this.db.query(
|
|
788
|
+
return (await this.db.query(a, o)).rows[0];
|
|
782
789
|
} catch (i) {
|
|
783
790
|
throw n.error({
|
|
784
791
|
type: "insert",
|
|
785
792
|
name: s,
|
|
786
|
-
sql:
|
|
787
|
-
params:
|
|
793
|
+
sql: a,
|
|
794
|
+
params: o,
|
|
788
795
|
error: i instanceof Error ? i.message : String(i)
|
|
789
796
|
}), i;
|
|
790
797
|
}
|
|
@@ -822,23 +829,23 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
|
|
|
822
829
|
async getAutoId(e) {
|
|
823
830
|
return this.idSystem.getAutoId(e);
|
|
824
831
|
}
|
|
825
|
-
parseMatchExpression(e, t, s, r, n,
|
|
832
|
+
parseMatchExpression(e, t, s, r, n, o, a) {
|
|
826
833
|
if (r.toLowerCase() === "json") {
|
|
827
834
|
if (t[0].toLowerCase() === "contains") {
|
|
828
835
|
const c = s.split(".").map((u) => `"${u}"`).join(".");
|
|
829
836
|
return {
|
|
830
|
-
fieldValue: `IS NOT NULL AND ${
|
|
837
|
+
fieldValue: `IS NOT NULL AND ${a()} = ANY (SELECT json_array_elements_text(${c}))`,
|
|
831
838
|
fieldParams: [t[1]]
|
|
832
839
|
};
|
|
833
840
|
}
|
|
834
841
|
if (t[0] === "=" || t[0] === "!=")
|
|
835
842
|
return {
|
|
836
|
-
fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")}::jsonb ${t[0]} ${
|
|
843
|
+
fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")}::jsonb ${t[0]} ${a()}::jsonb`,
|
|
837
844
|
fieldParams: [JSON.stringify(t[1])]
|
|
838
845
|
};
|
|
839
846
|
const i = t[0].toLowerCase();
|
|
840
847
|
if ((i === "in" || i === "not in") && Array.isArray(t[1]) && t[1].length > 0) {
|
|
841
|
-
const c = s.split(".").map((h) => `"${h}"`).join("."), u = t[1].map(() => `${
|
|
848
|
+
const c = s.split(".").map((h) => `"${h}"`).join("."), u = t[1].map(() => `${a()}::jsonb`).join(",");
|
|
842
849
|
return {
|
|
843
850
|
fieldValue: `IS NOT NULL AND ${c}::jsonb ${i === "in" ? "IN" : "NOT IN"} (${u})`,
|
|
844
851
|
fieldParams: t[1].map((h) => JSON.stringify(h))
|
|
@@ -877,9 +884,9 @@ ON DUPLICATE KEY UPDATE last = LAST_INSERT_ID(last + 1)`,
|
|
|
877
884
|
}), t;
|
|
878
885
|
}
|
|
879
886
|
}
|
|
880
|
-
class
|
|
887
|
+
class H {
|
|
881
888
|
constructor(e, t = {}) {
|
|
882
|
-
this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.transactionCapability = {
|
|
889
|
+
this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.returnsParsedJSON = !0, this.transactionCapability = {
|
|
883
890
|
transactions: !1,
|
|
884
891
|
isolationLevels: [],
|
|
885
892
|
transactionBoundConnection: !1,
|
|
@@ -897,7 +904,7 @@ class Z {
|
|
|
897
904
|
}, this.idSystem = new M(this), this.logger = this.options?.logger || S;
|
|
898
905
|
}
|
|
899
906
|
async open(e = !1) {
|
|
900
|
-
const t = await
|
|
907
|
+
const t = await E.createConnection({
|
|
901
908
|
...this.options
|
|
902
909
|
});
|
|
903
910
|
await t.connect();
|
|
@@ -907,54 +914,54 @@ class Z {
|
|
|
907
914
|
} finally {
|
|
908
915
|
await t.end();
|
|
909
916
|
}
|
|
910
|
-
this.db = await
|
|
917
|
+
this.db = await E.createConnection({
|
|
911
918
|
...this.options,
|
|
912
919
|
database: this.database
|
|
913
920
|
}), await this.db.connect(), await this.db.query("SET sql_mode='ANSI_QUOTES'"), await this.idSystem.setup();
|
|
914
921
|
}
|
|
915
922
|
async openForSchemaRead() {
|
|
916
|
-
this.db || (this.db = await
|
|
923
|
+
this.db || (this.db = await E.createConnection({
|
|
917
924
|
...this.options,
|
|
918
925
|
database: this.database
|
|
919
926
|
}), await this.db.connect(), await this.db.query("SET sql_mode='ANSI_QUOTES'"));
|
|
920
927
|
}
|
|
921
928
|
async query(e, t = [], s = "") {
|
|
922
|
-
const r = l.getStore(), n = this.logger.child(r?.logContext || {}),
|
|
929
|
+
const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((a) => a === !1 ? 0 : a === !0 ? 1 : a);
|
|
923
930
|
return n.info({
|
|
924
931
|
type: "query",
|
|
925
932
|
name: s,
|
|
926
933
|
sql: e,
|
|
927
|
-
params:
|
|
928
|
-
}), (await this.db.query(e,
|
|
934
|
+
params: o
|
|
935
|
+
}), (await this.db.query(e, o))[0];
|
|
929
936
|
}
|
|
930
937
|
async update(e, t, s, r = "") {
|
|
931
|
-
const n = l.getStore(),
|
|
932
|
-
return
|
|
938
|
+
const n = l.getStore(), o = this.logger.child(n?.logContext || {}), a = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i === !1 ? 0 : i === !0 ? 1 : i);
|
|
939
|
+
return o.info({
|
|
933
940
|
type: "update",
|
|
934
941
|
name: r,
|
|
935
942
|
sql: e,
|
|
936
|
-
params:
|
|
937
|
-
}), (await this.db.query(e,
|
|
943
|
+
params: a
|
|
944
|
+
}), (await this.db.query(e, a))[0];
|
|
938
945
|
}
|
|
939
946
|
async insert(e, t, s = "") {
|
|
940
|
-
const r = l.getStore(), n = this.logger.child(r?.logContext || {}),
|
|
947
|
+
const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c === !1 ? 0 : c === !0 ? 1 : c);
|
|
941
948
|
n.info({
|
|
942
949
|
type: "insert",
|
|
943
950
|
name: s,
|
|
944
951
|
sql: e,
|
|
945
|
-
params:
|
|
946
|
-
}), await this.db.query(e,
|
|
947
|
-
const [
|
|
948
|
-
return { id:
|
|
952
|
+
params: o
|
|
953
|
+
}), await this.db.query(e, o);
|
|
954
|
+
const [a] = await this.db.query("SELECT LAST_INSERT_ID();");
|
|
955
|
+
return { id: a[0]["LAST_INSERT_ID()"] };
|
|
949
956
|
}
|
|
950
957
|
async delete(e, t, s = "") {
|
|
951
|
-
const r = l.getStore(), n = this.logger.child(r?.logContext || {}),
|
|
958
|
+
const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((a) => a === !1 ? 0 : a === !0 ? 1 : a);
|
|
952
959
|
return n.info({
|
|
953
960
|
type: "delete",
|
|
954
961
|
name: s,
|
|
955
962
|
sql: e,
|
|
956
|
-
params:
|
|
957
|
-
}), (await this.db.query(e,
|
|
963
|
+
params: o
|
|
964
|
+
}), (await this.db.query(e, o))[0];
|
|
958
965
|
}
|
|
959
966
|
async scheme(e, t = "") {
|
|
960
967
|
const s = l.getStore();
|
|
@@ -970,21 +977,21 @@ class Z {
|
|
|
970
977
|
async getAutoId(e) {
|
|
971
978
|
return this.idSystem.getAutoId(e);
|
|
972
979
|
}
|
|
973
|
-
parseMatchExpression(e, t, s, r, n,
|
|
980
|
+
parseMatchExpression(e, t, s, r, n, o, a) {
|
|
974
981
|
if (r === "JSON") {
|
|
975
982
|
if (t[0].toLowerCase() === "contains")
|
|
976
983
|
return {
|
|
977
|
-
fieldValue: `IS NOT NULL AND JSON_CONTAINS(${s.split(".").map((u) => `"${u}"`).join(".")}, ${
|
|
984
|
+
fieldValue: `IS NOT NULL AND JSON_CONTAINS(${s.split(".").map((u) => `"${u}"`).join(".")}, ${a()}, '$')`,
|
|
978
985
|
fieldParams: [JSON.stringify(t[1])]
|
|
979
986
|
};
|
|
980
987
|
if (t[0] === "=" || t[0] === "!=")
|
|
981
988
|
return {
|
|
982
|
-
fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")} ${t[0]} CAST(${
|
|
989
|
+
fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")} ${t[0]} CAST(${a()} AS JSON)`,
|
|
983
990
|
fieldParams: [JSON.stringify(t[1])]
|
|
984
991
|
};
|
|
985
992
|
const i = t[0].toLowerCase();
|
|
986
993
|
if ((i === "in" || i === "not in") && Array.isArray(t[1]) && t[1].length > 0) {
|
|
987
|
-
const c = s.split(".").map((h) => `"${h}"`).join("."), u = t[1].map(() => `CAST(${
|
|
994
|
+
const c = s.split(".").map((h) => `"${h}"`).join("."), u = t[1].map(() => `CAST(${a()} AS JSON)`).join(",");
|
|
988
995
|
return {
|
|
989
996
|
fieldValue: `IS NOT NULL AND ${c} ${i === "in" ? "IN" : "NOT IN"} (${u})`,
|
|
990
997
|
fieldParams: t[1].map((h) => JSON.stringify(h))
|
|
@@ -1000,7 +1007,7 @@ class Z {
|
|
|
1000
1007
|
}
|
|
1001
1008
|
}
|
|
1002
1009
|
export {
|
|
1003
|
-
|
|
1010
|
+
H as MysqlDB,
|
|
1004
1011
|
z as PGLiteDB,
|
|
1005
1012
|
G as PostgreSQLDB,
|
|
1006
1013
|
K as SQLiteDB
|