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/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 E, defaultEncodeLiteral as y, RequireSerializableRetry as b } from "interaqt";
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 w from "pg";
6
- import { PGlite as R } from "@electric-sql/pglite";
7
- import m from "mysql2/promise";
8
- let C = class {
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 C(this), this.logger = this.options?.logger || S;
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), await this.idSystem.setup();
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 || {}), a = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
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: a
84
- }), this.db.prepare(e).all(...a);
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(), a = this.logger.child(n?.logContext || {}), o = `${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);
88
- return a.info({
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: o,
98
+ sql: a,
92
99
  params: i
93
- }), s ? this.db.prepare(o).all(...i) : this.db.prepare(o).run(...i);
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 || {}), a = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i === !1 ? 0 : i === !0 ? 1 : i);
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: a
102
- }), this.db.prepare(`${e} RETURNING ${E}`).all(...a)[0];
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 || {}), a = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
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: a
111
- }), this.db.prepare(e).run(...a);
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, a, o) {
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 = ${o()}
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: O } = w;
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 a = this.quoteIdentifier(n);
172
- await this.db.scheme(`CREATE SEQUENCE IF NOT EXISTS ${a} START WITH 1`, `create sequence ${r.recordName}`);
173
- const o = await this.db.query(
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(o[0]?.max ?? 0), i);
188
- s.set(a, Math.max(s.get(a) ?? 0, c)), this.initialized.add(r.recordName);
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 O({
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(), a = { client: n, depth: 1, isolation: r };
283
- let o = !1;
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(a, t);
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(), o = !0;
299
+ n.release(), a = !0;
293
300
  }
294
301
  throw i;
295
302
  } finally {
296
- o || n.release();
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 || {}), a = t;
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: a
326
- }), (await this.getQueryable().query(e, a)).rows;
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(), a = this.logger.child(n?.logContext || {}), o = `${e} ${s ? `RETURNING "${s}" AS id` : ""}`, i = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c);
330
- return a.info({
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: o,
340
+ sql: a,
334
341
  params: i
335
- }), (await this.getQueryable().query(o, i)).rows;
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 || {}), a = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i);
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: a
350
+ params: o
344
351
  });
345
- const o = `${e} RETURNING "${E}"`;
346
- return (await this.getQueryable().query(o, a)).rows[0];
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 || {}), a = t;
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: a
355
- }), (await this.getQueryable().query(e, a)).rows;
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, a, o) {
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 ${o()} = ANY (SELECT json_array_elements_text(${c}))`,
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]} ${o()}::jsonb`,
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(() => `${o()}::jsonb`).join(",");
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 a;
464
+ let o;
458
465
  switch (e.length) {
459
466
  case 32:
460
- a = (t = /^[0-9a-f]{32}$/i.exec(e)) === null || t === void 0 ? void 0 : t[0];
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
- a = (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("");
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
- a = (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("");
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
- a = (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("");
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 (a) {
473
- const o = new Uint8Array(16);
479
+ if (o) {
480
+ const a = new Uint8Array(16);
474
481
  for (let i = 0; i < 16; i += 4) {
475
- const c = parseInt(a.substring(2 * i, 2 * i + 8), 16);
476
- o[i + 0] = c >>> 24, o[i + 1] = c >>> 16, o[i + 2] = c >>> 8, o[i + 3] = c;
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(o);
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 R(this.database);
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 (a) {
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: a instanceof Error ? a.message : String(a)
759
- }), a;
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(), a = this.logger.child(n?.logContext || {}), o = `${e} ${s ? `RETURNING "${s}" AS id` : ""}`, i = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c);
764
- return a.info({
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: o,
774
+ sql: a,
768
775
  params: i
769
- }), (await this.db.query(o, i)).rows;
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 || {}), a = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i);
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: a
784
+ params: o
778
785
  });
779
- const o = `${e} RETURNING "${E}"`;
786
+ const a = `${e} RETURNING "${m}"`;
780
787
  try {
781
- return (await this.db.query(o, a)).rows[0];
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: o,
787
- params: a,
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, a, o) {
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 ${o()} = ANY (SELECT json_array_elements_text(${c}))`,
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]} ${o()}::jsonb`,
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(() => `${o()}::jsonb`).join(",");
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 Z {
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 m.createConnection({
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 m.createConnection({
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 m.createConnection({
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 || {}), a = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
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: a
928
- }), (await this.db.query(e, a))[0];
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(), a = this.logger.child(n?.logContext || {}), o = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i === !1 ? 0 : i === !0 ? 1 : i);
932
- return a.info({
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: o
937
- }), (await this.db.query(e, o))[0];
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 || {}), a = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c === !1 ? 0 : c === !0 ? 1 : c);
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: a
946
- }), await this.db.query(e, a);
947
- const [o] = await this.db.query("SELECT LAST_INSERT_ID();");
948
- return { id: o[0]["LAST_INSERT_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 || {}), a = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
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: a
957
- }), (await this.db.query(e, a))[0];
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, a, o) {
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(".")}, ${o()}, '$')`,
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(${o()} AS JSON)`,
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(${o()} AS JSON)`).join(",");
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
- Z as MysqlDB,
1010
+ H as MysqlDB,
1004
1011
  z as PGLiteDB,
1005
1012
  G as PostgreSQLDB,
1006
1013
  K as SQLiteDB