interaqt 2.0.1 → 2.0.2

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,9 +1,9 @@
1
1
  import m from "better-sqlite3";
2
- import { sqliteEncodeLiteral as I, dbConsoleLogger as f, asyncInteractionContext as l, ROW_ID_ATTR as p, defaultEncodeLiteral as S, RequireSerializableRetry as N } from "interaqt";
2
+ import { sqliteEncodeLiteral as N, dbConsoleLogger as g, asyncInteractionContext as l, ROW_ID_ATTR as p, defaultEncodeLiteral as S, RequireSerializableRetry as I } from "interaqt";
3
3
  import { AsyncLocalStorage as b } from "node:async_hooks";
4
4
  import { createHash as A } from "node:crypto";
5
- import R from "pg";
6
- import { PGlite as L } from "@electric-sql/pglite";
5
+ import L from "pg";
6
+ import { PGlite as R } from "@electric-sql/pglite";
7
7
  import E from "mysql2/promise";
8
8
  let w = class {
9
9
  constructor(e) {
@@ -44,9 +44,9 @@ class K {
44
44
  name: "sqlite",
45
45
  maxIdentifierLength: 63,
46
46
  supportsCreateIndexIfNotExists: !0,
47
- encodeLiteral: I,
47
+ encodeLiteral: N,
48
48
  constraints: { unique: !0, filteredUnique: !0, nonNull: !1 }
49
- }, this.idSystem = new w(this), this.logger = this.options?.logger || f;
49
+ }, this.idSystem = new w(this), this.logger = this.options?.logger || g;
50
50
  }
51
51
  async open() {
52
52
  this.db = new m(this.file, this.options), await this.idSystem.setup();
@@ -75,40 +75,40 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
75
75
  )`, "setup scoped sequence table");
76
76
  }
77
77
  async query(e, t = [], s = "") {
78
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((i) => i === !1 ? 0 : i === !0 ? 1 : i);
78
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
79
79
  return n.info({
80
80
  type: "query",
81
81
  name: s,
82
82
  sql: e,
83
- params: a
84
- }), this.db.prepare(e).all(...a);
83
+ params: i
84
+ }), this.db.prepare(e).all(...i);
85
85
  }
86
86
  async update(e, t, s, r = "") {
87
- const n = l.getStore(), a = this.logger.child(n?.logContext || {}), i = `${e} ${s ? `RETURNING ${s} AS id` : ""}`, o = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c === !1 ? 0 : c === !0 ? 1 : c);
88
- return a.info({
87
+ const n = l.getStore(), i = this.logger.child(n?.logContext || {}), o = `${e} ${s ? `RETURNING ${s} AS id` : ""}`, a = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c === !1 ? 0 : c === !0 ? 1 : c);
88
+ return i.info({
89
89
  type: "update",
90
90
  name: r,
91
- sql: i,
92
- params: o
93
- }), s ? this.db.prepare(i).all(...o) : this.db.prepare(i).run(...o);
91
+ sql: o,
92
+ params: a
93
+ }), s ? this.db.prepare(o).all(...a) : this.db.prepare(o).run(...a);
94
94
  }
95
95
  async insert(e, t, s = "") {
96
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((o) => typeof o == "object" && o !== null ? JSON.stringify(o) : o === !1 ? 0 : o === !0 ? 1 : o);
96
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t.map((a) => typeof a == "object" && a !== null ? JSON.stringify(a) : a === !1 ? 0 : a === !0 ? 1 : a);
97
97
  return n.info({
98
98
  type: "insert",
99
99
  name: s,
100
100
  sql: e,
101
- params: a
102
- }), this.db.prepare(`${e} RETURNING ${p}`).all(...a)[0];
101
+ params: i
102
+ }), this.db.prepare(`${e} RETURNING ${p}`).all(...i)[0];
103
103
  }
104
104
  async delete(e, t, s = "") {
105
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((i) => i === !1 ? 0 : i === !0 ? 1 : i);
105
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
106
106
  return n.info({
107
107
  type: "delete",
108
108
  name: s,
109
109
  sql: e,
110
- params: a
111
- }), this.db.prepare(e).run(...a);
110
+ params: i
111
+ }), this.db.prepare(e).run(...i);
112
112
  }
113
113
  async scheme(e, t = "") {
114
114
  const s = l.getStore();
@@ -124,13 +124,13 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
124
124
  async getAutoId(e) {
125
125
  return this.idSystem.getAutoId(e);
126
126
  }
127
- parseMatchExpression(e, t, s, r, n, a, i) {
127
+ parseMatchExpression(e, t, s, r, n, i, o) {
128
128
  if (r === "JSON" && t[0].toLowerCase() === "contains")
129
129
  return {
130
130
  fieldValue: `NOT NULL AND EXISTS (
131
131
  SELECT 1
132
132
  FROM json_each(${s})
133
- WHERE json_each.value = ${i()}
133
+ WHERE json_each.value = ${o()}
134
134
  )`,
135
135
  fieldParams: [t[1]]
136
136
  };
@@ -139,7 +139,7 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
139
139
  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
140
  }
141
141
  }
142
- const { Client: d, Pool: C } = R;
142
+ const { Client: d, Pool: C } = L;
143
143
  let O = class {
144
144
  constructor(e) {
145
145
  this.db = e, this.initialized = /* @__PURE__ */ new Set(), this.recordToSequenceName = /* @__PURE__ */ new Map();
@@ -168,24 +168,24 @@ let O = class {
168
168
  for (const r of e) {
169
169
  const n = this.sequenceNameForKey(`${r.tableName}.${r.idField}`, r.tableName);
170
170
  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 i = await this.db.query(
171
+ const i = this.quoteIdentifier(n);
172
+ await this.db.scheme(`CREATE SEQUENCE IF NOT EXISTS ${i} START WITH 1`, `create sequence ${r.recordName}`);
173
+ const o = await this.db.query(
174
174
  `SELECT COALESCE(MAX("${r.idField}"), 0) AS max FROM ${this.quoteIdentifier(r.tableName)}`,
175
175
  [],
176
176
  `read max id for ${r.recordName}`
177
177
  );
178
- let o = 0;
178
+ let a = 0;
179
179
  if (t) {
180
180
  const T = await this.db.query(
181
181
  'SELECT COALESCE(MAX("last"), 0) AS last FROM "_IDS_" WHERE "name" = $1',
182
182
  [r.recordName],
183
183
  `read legacy id for ${r.recordName}`
184
184
  );
185
- o = Number(T[0]?.last ?? 0);
185
+ a = Number(T[0]?.last ?? 0);
186
186
  }
187
- const c = Math.max(Number(i[0]?.max ?? 0), o);
188
- s.set(a, Math.max(s.get(a) ?? 0, c)), this.initialized.add(r.recordName);
187
+ const c = Math.max(Number(o[0]?.max ?? 0), a);
188
+ s.set(i, Math.max(s.get(i) ?? 0, c)), this.initialized.add(r.recordName);
189
189
  }
190
190
  for (const [r, n] of s)
191
191
  n >= 1 && await this.db.query(
@@ -205,7 +205,7 @@ let O = class {
205
205
  ))[0].id;
206
206
  }
207
207
  };
208
- class J {
208
+ class W {
209
209
  constructor(e, t = {}) {
210
210
  this.database = e, this.options = t, this.transactionContext = new b(), this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.transactionCapability = {
211
211
  transactions: !0,
@@ -226,7 +226,7 @@ class J {
226
226
  supportsCreateIndexIfNotExists: !0,
227
227
  encodeLiteral: S,
228
228
  constraints: { unique: !0, filteredUnique: !0, nonNull: !0 }
229
- }, this.idSystem = new O(this), this.logger = this.options?.logger || f, this.db = new d({ ...t });
229
+ }, this.idSystem = new O(this), this.logger = this.options?.logger || g, this.db = new d({ ...t });
230
230
  }
231
231
  async open(e = !1) {
232
232
  this.pool && e && (await this.pool.end(), this.pool = void 0);
@@ -269,7 +269,7 @@ class J {
269
269
  const s = this.transactionContext.getStore();
270
270
  if (s && s.depth > 0) {
271
271
  if (s.isolation !== "SERIALIZABLE" && (e.isolation ?? "READ COMMITTED") === "SERIALIZABLE")
272
- throw new N(`${e.name || "nested transaction"} requires SERIALIZABLE isolation`);
272
+ throw new I(`${e.name || "nested transaction"} requires SERIALIZABLE isolation`);
273
273
  s.depth++;
274
274
  try {
275
275
  return await t();
@@ -279,21 +279,21 @@ class J {
279
279
  }
280
280
  if (!this.pool)
281
281
  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 i = !1;
282
+ const r = e.isolation ?? "READ COMMITTED", n = await this.pool.connect(), i = { client: n, depth: 1, isolation: r };
283
+ let o = !1;
284
284
  try {
285
285
  await n.query(`BEGIN ISOLATION LEVEL ${r}`);
286
- const o = await this.transactionContext.run(a, t);
287
- return await n.query("COMMIT"), o;
288
- } catch (o) {
286
+ const a = await this.transactionContext.run(i, t);
287
+ return await n.query("COMMIT"), a;
288
+ } catch (a) {
289
289
  try {
290
290
  await n.query("ROLLBACK");
291
291
  } finally {
292
- n.release(), i = !0;
292
+ n.release(), o = !0;
293
293
  }
294
- throw o;
294
+ throw a;
295
295
  } finally {
296
- i || n.release();
296
+ o || n.release();
297
297
  }
298
298
  }
299
299
  async setupInternalComputationState() {
@@ -317,42 +317,42 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
317
317
  )`, "setup scoped sequence table");
318
318
  }
319
319
  async query(e, t = [], s = "") {
320
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t;
320
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t;
321
321
  return n.info({
322
322
  type: "query",
323
323
  name: s,
324
324
  sql: e,
325
- params: a
326
- }), (await this.getQueryable().query(e, a)).rows;
325
+ params: i
326
+ }), (await this.getQueryable().query(e, i)).rows;
327
327
  }
328
328
  async update(e, t, s, r = "") {
329
- const n = l.getStore(), a = this.logger.child(n?.logContext || {}), i = `${e} ${s ? `RETURNING "${s}" AS id` : ""}`, o = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c);
330
- return a.info({
329
+ const n = l.getStore(), i = this.logger.child(n?.logContext || {}), o = `${e} ${s ? `RETURNING "${s}" AS id` : ""}`, a = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c);
330
+ return i.info({
331
331
  type: "update",
332
332
  name: r,
333
- sql: i,
334
- params: o
335
- }), (await this.getQueryable().query(i, o)).rows;
333
+ sql: o,
334
+ params: a
335
+ }), (await this.getQueryable().query(o, a)).rows;
336
336
  }
337
337
  async insert(e, t, s = "") {
338
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((o) => typeof o == "object" && o !== null ? JSON.stringify(o) : o);
338
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t.map((a) => typeof a == "object" && a !== null ? JSON.stringify(a) : a);
339
339
  n.info({
340
340
  type: "insert",
341
341
  name: s,
342
342
  sql: e,
343
- params: a
343
+ params: i
344
344
  });
345
- const i = `${e} RETURNING "${p}"`;
346
- return (await this.getQueryable().query(i, a)).rows[0];
345
+ const o = `${e} RETURNING "${p}"`;
346
+ return (await this.getQueryable().query(o, i)).rows[0];
347
347
  }
348
348
  async delete(e, t, s = "") {
349
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t;
349
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t;
350
350
  return n.info({
351
351
  type: "delete",
352
352
  name: s,
353
353
  sql: e,
354
- params: a
355
- }), (await this.getQueryable().query(e, a)).rows;
354
+ params: i
355
+ }), (await this.getQueryable().query(e, i)).rows;
356
356
  }
357
357
  async scheme(e, t = "") {
358
358
  const s = l.getStore();
@@ -371,13 +371,20 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
371
371
  setupRecordSequences(e) {
372
372
  return this.idSystem.setupSequences(e);
373
373
  }
374
- parseMatchExpression(e, t, s, r, n, a, i) {
375
- if (r === "JSON" && t[0].toLowerCase() === "contains") {
376
- const o = s.split(".").map((c) => `"${c}"`).join(".");
377
- return {
378
- fieldValue: `IS NOT NULL AND ${i()} = ANY (SELECT json_array_elements_text(${o}))`,
379
- fieldParams: [t[1]]
380
- };
374
+ parseMatchExpression(e, t, s, r, n, i, o) {
375
+ if (r === "JSON") {
376
+ if (t[0].toLowerCase() === "contains") {
377
+ const a = s.split(".").map((c) => `"${c}"`).join(".");
378
+ return {
379
+ fieldValue: `IS NOT NULL AND ${o()} = ANY (SELECT json_array_elements_text(${a}))`,
380
+ fieldParams: [t[1]]
381
+ };
382
+ }
383
+ if (t[0] === "=" || t[0] === "!=")
384
+ return {
385
+ fieldValue: `IS NOT NULL AND ${s.split(".").map((c) => `"${c}"`).join(".")}::jsonb ${t[0]} ${o()}::jsonb`,
386
+ fieldParams: [JSON.stringify(t[1])]
387
+ };
381
388
  }
382
389
  }
383
390
  getPlaceholder() {
@@ -388,7 +395,7 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
388
395
  return e === "pk" ? "INT GENERATED ALWAYS AS IDENTITY" : e === "id" ? "INT" : t || e === "object" ? "JSON" : e === "string" ? "TEXT" : e === "boolean" ? "BOOLEAN" : e === "number" ? "DOUBLE PRECISION" : e === "timestamp" ? "TIMESTAMP" : e;
389
396
  }
390
397
  }
391
- const g = "0123456789abcdef";
398
+ const f = "0123456789abcdef";
392
399
  class h {
393
400
  /** @param bytes - The 16-byte byte array representation. */
394
401
  constructor(e) {
@@ -439,28 +446,28 @@ class h {
439
446
  */
440
447
  static parse(e) {
441
448
  var t, s, r, n;
442
- let a;
449
+ let i;
443
450
  switch (e.length) {
444
451
  case 32:
445
- a = (t = /^[0-9a-f]{32}$/i.exec(e)) === null || t === void 0 ? void 0 : t[0];
452
+ i = (t = /^[0-9a-f]{32}$/i.exec(e)) === null || t === void 0 ? void 0 : t[0];
446
453
  break;
447
454
  case 36:
448
- 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("");
455
+ i = (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("");
449
456
  break;
450
457
  case 38:
451
- 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("");
458
+ i = (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("");
452
459
  break;
453
460
  case 45:
454
- 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("");
461
+ i = (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("");
455
462
  break;
456
463
  }
457
- if (a) {
458
- const i = new Uint8Array(16);
459
- for (let o = 0; o < 16; o += 4) {
460
- const c = parseInt(a.substring(2 * o, 2 * o + 8), 16);
461
- i[o + 0] = c >>> 24, i[o + 1] = c >>> 16, i[o + 2] = c >>> 8, i[o + 3] = c;
464
+ if (i) {
465
+ const o = new Uint8Array(16);
466
+ for (let a = 0; a < 16; a += 4) {
467
+ const c = parseInt(i.substring(2 * a, 2 * a + 8), 16);
468
+ o[a + 0] = c >>> 24, o[a + 1] = c >>> 16, o[a + 2] = c >>> 8, o[a + 3] = c;
462
469
  }
463
- return new h(i);
470
+ return new h(o);
464
471
  } else
465
472
  throw new SyntaxError("could not parse UUID string");
466
473
  }
@@ -471,7 +478,7 @@ class h {
471
478
  toString() {
472
479
  let e = "";
473
480
  for (let t = 0; t < this.bytes.length; t++)
474
- e += g.charAt(this.bytes[t] >>> 4), e += g.charAt(this.bytes[t] & 15), (t === 3 || t === 5 || t === 7 || t === 9) && (e += "-");
481
+ e += f.charAt(this.bytes[t] >>> 4), e += f.charAt(this.bytes[t] & 15), (t === 3 || t === 5 || t === 7 || t === 9) && (e += "-");
475
482
  return e;
476
483
  }
477
484
  /**
@@ -481,7 +488,7 @@ class h {
481
488
  toHex() {
482
489
  let e = "";
483
490
  for (let t = 0; t < this.bytes.length; t++)
484
- e += g.charAt(this.bytes[t] >>> 4), e += g.charAt(this.bytes[t] & 15);
491
+ e += f.charAt(this.bytes[t] >>> 4), e += f.charAt(this.bytes[t] & 15);
485
492
  return e;
486
493
  }
487
494
  /** @returns The 8-4-4-4-12 canonical hexadecimal string representation. */
@@ -651,7 +658,7 @@ class D {
651
658
  }
652
659
  }
653
660
  let y;
654
- const U = () => $().toString(), $ = () => (y || (y = new q())).generate();
661
+ const $ = () => U().toString(), U = () => (y || (y = new q())).generate();
655
662
  let x = class {
656
663
  constructor(e) {
657
664
  this.db = e;
@@ -660,10 +667,10 @@ let x = class {
660
667
  return this.db.scheme('CREATE Table IF NOT EXISTS "_IDS_" (last INTEGER, name TEXT)');
661
668
  }
662
669
  async getAutoId(e) {
663
- return U();
670
+ return $();
664
671
  }
665
672
  };
666
- class k {
673
+ class v {
667
674
  constructor(e, t = {}) {
668
675
  this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.transactionCapability = {
669
676
  transactions: !0,
@@ -687,7 +694,7 @@ class k {
687
694
  supportsCreateIndexIfNotExists: !0,
688
695
  encodeLiteral: S,
689
696
  constraints: { unique: !0, filteredUnique: !0, nonNull: !0 }
690
- }, this.idSystem = new x(this), this.logger = this.options?.logger || f, this.db = new L(this.database);
697
+ }, this.idSystem = new x(this), this.logger = this.options?.logger || g, this.db = new R(this.database);
691
698
  }
692
699
  async open(e = !1) {
693
700
  if (e) {
@@ -734,44 +741,44 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
734
741
  });
735
742
  try {
736
743
  return (await this.db.query(e, t)).rows;
737
- } catch (a) {
744
+ } catch (i) {
738
745
  throw n.error({
739
746
  type: "query",
740
747
  name: s,
741
748
  sql: e,
742
749
  params: t,
743
- error: a instanceof Error ? a.message : String(a)
744
- }), a;
750
+ error: i instanceof Error ? i.message : String(i)
751
+ }), i;
745
752
  }
746
753
  }
747
754
  async update(e, t, s, r = "") {
748
- const n = l.getStore(), a = this.logger.child(n?.logContext || {}), i = `${e} ${s ? `RETURNING "${s}" AS id` : ""}`, o = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c);
749
- return a.info({
755
+ const n = l.getStore(), i = this.logger.child(n?.logContext || {}), o = `${e} ${s ? `RETURNING "${s}" AS id` : ""}`, a = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c);
756
+ return i.info({
750
757
  type: "update",
751
758
  name: r,
752
- sql: i,
753
- params: o
754
- }), (await this.db.query(i, o)).rows;
759
+ sql: o,
760
+ params: a
761
+ }), (await this.db.query(o, a)).rows;
755
762
  }
756
763
  async insert(e, t, s = "") {
757
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((o) => typeof o == "object" && o !== null ? JSON.stringify(o) : o);
764
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t.map((a) => typeof a == "object" && a !== null ? JSON.stringify(a) : a);
758
765
  n.info({
759
766
  type: "insert",
760
767
  name: s,
761
768
  sql: e,
762
- params: a
769
+ params: i
763
770
  });
764
- const i = `${e} RETURNING "${p}"`;
771
+ const o = `${e} RETURNING "${p}"`;
765
772
  try {
766
- return (await this.db.query(i, a)).rows[0];
767
- } catch (o) {
773
+ return (await this.db.query(o, i)).rows[0];
774
+ } catch (a) {
768
775
  throw n.error({
769
776
  type: "insert",
770
777
  name: s,
771
- sql: i,
772
- params: a,
773
- error: o instanceof Error ? o.message : String(o)
774
- }), o;
778
+ sql: o,
779
+ params: i,
780
+ error: a instanceof Error ? a.message : String(a)
781
+ }), a;
775
782
  }
776
783
  }
777
784
  async delete(e, t, s = "") {
@@ -807,13 +814,20 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
807
814
  async getAutoId(e) {
808
815
  return this.idSystem.getAutoId(e);
809
816
  }
810
- parseMatchExpression(e, t, s, r, n, a, i) {
811
- if (r.toLowerCase() === "json" && t[0].toLowerCase() === "contains") {
812
- const o = s.split(".").map((c) => `"${c}"`).join(".");
813
- return {
814
- fieldValue: `IS NOT NULL AND ${i()} = ANY (SELECT json_array_elements_text(${o}))`,
815
- fieldParams: [t[1]]
816
- };
817
+ parseMatchExpression(e, t, s, r, n, i, o) {
818
+ if (r.toLowerCase() === "json") {
819
+ if (t[0].toLowerCase() === "contains") {
820
+ const a = s.split(".").map((c) => `"${c}"`).join(".");
821
+ return {
822
+ fieldValue: `IS NOT NULL AND ${o()} = ANY (SELECT json_array_elements_text(${a}))`,
823
+ fieldParams: [t[1]]
824
+ };
825
+ }
826
+ if (t[0] === "=" || t[0] === "!=")
827
+ return {
828
+ fieldValue: `IS NOT NULL AND ${s.split(".").map((c) => `"${c}"`).join(".")}::jsonb ${t[0]} ${o()}::jsonb`,
829
+ fieldParams: [JSON.stringify(t[1])]
830
+ };
817
831
  }
818
832
  }
819
833
  getPlaceholder() {
@@ -847,7 +861,7 @@ ON DUPLICATE KEY UPDATE last = LAST_INSERT_ID(last + 1)`,
847
861
  }), t;
848
862
  }
849
863
  }
850
- class W {
864
+ class k {
851
865
  constructor(e, t = {}) {
852
866
  this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.transactionCapability = {
853
867
  transactions: !1,
@@ -864,7 +878,7 @@ class W {
864
878
  supportsCreateIndexIfNotExists: !1,
865
879
  encodeLiteral: S,
866
880
  constraints: { unique: !1, filteredUnique: !1, nonNull: !1 }
867
- }, this.idSystem = new M(this), this.logger = this.options?.logger || f;
881
+ }, this.idSystem = new M(this), this.logger = this.options?.logger || g;
868
882
  }
869
883
  async open(e = !1) {
870
884
  const t = await E.createConnection({
@@ -889,42 +903,42 @@ class W {
889
903
  }), await this.db.connect(), await this.db.query("SET sql_mode='ANSI_QUOTES'"));
890
904
  }
891
905
  async query(e, t = [], s = "") {
892
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((i) => i === !1 ? 0 : i === !0 ? 1 : i);
906
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
893
907
  return n.info({
894
908
  type: "query",
895
909
  name: s,
896
910
  sql: e,
897
- params: a
898
- }), (await this.db.query(e, a))[0];
911
+ params: i
912
+ }), (await this.db.query(e, i))[0];
899
913
  }
900
914
  async update(e, t, s, r = "") {
901
- const n = l.getStore(), a = this.logger.child(n?.logContext || {}), i = t.map((o) => typeof o == "object" && o !== null ? JSON.stringify(o) : o === !1 ? 0 : o === !0 ? 1 : o);
902
- return a.info({
915
+ const n = l.getStore(), i = this.logger.child(n?.logContext || {}), o = t.map((a) => typeof a == "object" && a !== null ? JSON.stringify(a) : a === !1 ? 0 : a === !0 ? 1 : a);
916
+ return i.info({
903
917
  type: "update",
904
918
  name: r,
905
919
  sql: e,
906
- params: i
907
- }), (await this.db.query(e, i))[0];
920
+ params: o
921
+ }), (await this.db.query(e, o))[0];
908
922
  }
909
923
  async insert(e, t, s = "") {
910
- 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);
924
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c === !1 ? 0 : c === !0 ? 1 : c);
911
925
  n.info({
912
926
  type: "insert",
913
927
  name: s,
914
928
  sql: e,
915
- params: a
916
- }), await this.db.query(e, a);
917
- const [i] = await this.db.query("SELECT LAST_INSERT_ID();");
918
- return { id: i[0]["LAST_INSERT_ID()"] };
929
+ params: i
930
+ }), await this.db.query(e, i);
931
+ const [o] = await this.db.query("SELECT LAST_INSERT_ID();");
932
+ return { id: o[0]["LAST_INSERT_ID()"] };
919
933
  }
920
934
  async delete(e, t, s = "") {
921
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((i) => i === !1 ? 0 : i === !0 ? 1 : i);
935
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
922
936
  return n.info({
923
937
  type: "delete",
924
938
  name: s,
925
939
  sql: e,
926
- params: a
927
- }), (await this.db.query(e, a))[0];
940
+ params: i
941
+ }), (await this.db.query(e, i))[0];
928
942
  }
929
943
  async scheme(e, t = "") {
930
944
  const s = l.getStore();
@@ -940,12 +954,19 @@ class W {
940
954
  async getAutoId(e) {
941
955
  return this.idSystem.getAutoId(e);
942
956
  }
943
- parseMatchExpression(e, t, s, r, n, a, i) {
944
- if (r === "JSON" && t[0].toLowerCase() === "contains")
945
- return {
946
- fieldValue: `IS NOT NULL AND JSON_CONTAINS(${s.split(".").map((c) => `"${c}"`).join(".")}, ${i()}, '$')`,
947
- fieldParams: [JSON.stringify(t[1])]
948
- };
957
+ parseMatchExpression(e, t, s, r, n, i, o) {
958
+ if (r === "JSON") {
959
+ if (t[0].toLowerCase() === "contains")
960
+ return {
961
+ fieldValue: `IS NOT NULL AND JSON_CONTAINS(${s.split(".").map((c) => `"${c}"`).join(".")}, ${o()}, '$')`,
962
+ fieldParams: [JSON.stringify(t[1])]
963
+ };
964
+ if (t[0] === "=" || t[0] === "!=")
965
+ return {
966
+ fieldValue: `IS NOT NULL AND ${s.split(".").map((c) => `"${c}"`).join(".")} ${t[0]} CAST(${o()} AS JSON)`,
967
+ fieldParams: [JSON.stringify(t[1])]
968
+ };
969
+ }
949
970
  }
950
971
  getPlaceholder() {
951
972
  return () => "?";
@@ -955,9 +976,9 @@ class W {
955
976
  }
956
977
  }
957
978
  export {
958
- W as MysqlDB,
959
- k as PGLiteDB,
960
- J as PostgreSQLDB,
979
+ k as MysqlDB,
980
+ v as PGLiteDB,
981
+ W as PostgreSQLDB,
961
982
  K as SQLiteDB
962
983
  };
963
984
  //# sourceMappingURL=drivers.js.map