@nongt/visql 0.4.2 → 0.5.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.
@@ -1,142 +1,153 @@
1
- var gt = Object.defineProperty;
2
- var ht = (t, e, r) => e in t ? gt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var b = (t, e, r) => ht(t, typeof e != "symbol" ? e + "" : e, r);
4
- import { q as L, F as Dt, G as Ot, g as M, o as Y, d as G, t as J, h as Nt, w as k, H as St, k as bt, b as Rt, i as It } from "./schema-z95dxLxu.js";
5
- import { ag as D, aA as K, aB as Ct, aC as Lt, aD as Mt, aj as wt, V as Ft, ap as qt, aE as A, al as Ut, a7 as dt, aF as vt, aG as z, $ as Bt } from "./issueLocation-CWUdTtCh.js";
6
- import { s as Z } from "./calendarDate-CYlr9TvX.js";
7
- class jt extends Error {
8
- constructor(r, n, s, i) {
9
- const a = i ? `"${n}" (as "${i}")` : `"${n}"`;
1
+ var qt = Object.defineProperty;
2
+ var Ut = (t, e, r) => e in t ? qt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var M = (t, e, r) => Ut(t, typeof e != "symbol" ? e + "" : e, r);
4
+ import { q as U, g as B, F as vt, G as Bt, o as K, d as nt, t as ft, h as jt, w as lt, H as _t, k as Ht, b as Yt, i as Pt } from "./schema-z95dxLxu.js";
5
+ import { ag as R, aA as k, aB as Gt, aC as xt, aD as kt, aj as Qt, V as Xt, ap as Vt, aE as A, al as Wt, a7 as Jt, aF as Kt, aG as $t, $ as zt } from "./issueLocation-CWUdTtCh.js";
6
+ import { s as Et } from "./calendarDate-CYlr9TvX.js";
7
+ class Zt extends Error {
8
+ constructor(r, n, s, o) {
9
+ const a = o ? `"${n}" (as "${o}")` : `"${n}"`;
10
10
  super(`scopeQuery: the query at ${r.length ? r.join(".") : "the top"} reads ${a} but can't reach "${s}", which the condition names`);
11
11
  /** Where the body is, as keys into the query (validateQuery's
12
12
  * `pathSegments` style). */
13
- b(this, "path");
13
+ M(this, "path");
14
14
  /** The table it reads that needs scope. */
15
- b(this, "table");
15
+ M(this, "table");
16
16
  /** The alias that copy of the table goes by, when it has one (a self
17
17
  * join reads a table more than once, issue 216). */
18
- b(this, "alias");
19
- this.name = "ScopeError", this.path = r, this.table = n, i && (this.alias = i);
18
+ M(this, "alias");
19
+ this.name = "ScopeError", this.path = r, this.table = n, o && (this.alias = o);
20
20
  }
21
21
  }
22
- const q = (t) => Object.prototype.toString.call(t) === "[object Object]", tt = (t) => Array.isArray(t.joins) && q(t.from);
23
- function w(t, e, r) {
22
+ const H = (t) => Object.prototype.toString.call(t) === "[object Object]", yt = (t) => Array.isArray(t.joins) && H(t.from);
23
+ function j(t, e, r) {
24
24
  if (Array.isArray(t)) {
25
- const a = t.map((o, c) => w(o, [...e, c], r));
26
- return a.every((o, c) => o === t[c]) ? t : a;
25
+ const a = t.map((i, c) => j(i, [...e, c], r));
26
+ return a.every((i, c) => i === t[c]) ? t : a;
27
27
  }
28
- if (!q(t)) return t;
28
+ if (!H(t)) return t;
29
29
  let n = !1;
30
- const s = Object.entries(t).map(([a, o]) => {
31
- const c = w(o, [...e, a], r);
32
- return c !== o && (n = !0), [a, c];
33
- }), i = n ? Object.fromEntries(s) : t;
34
- return tt(i) ? r(i, e) : i;
30
+ const s = Object.entries(t).map(([a, i]) => {
31
+ const c = j(i, [...e, a], r);
32
+ return c !== i && (n = !0), [a, c];
33
+ }), o = n ? Object.fromEntries(s) : t;
34
+ return yt(o) ? r(o, e) : o;
35
35
  }
36
- const et = (t, e) => L(t).flatMap((r) => r.table !== void 0 && e.requires(r.table) ? [{ table: r.table, ...r.alias ? { alias: r.alias } : {}, ref: r.alias ?? r.table }] : []), rt = (t) => L(t).flatMap((e) => {
36
+ const pt = (t, e) => U(t).flatMap((r) => r.table !== void 0 && e.requires(r.table) ? [{ table: r.table, ...r.alias ? { alias: r.alias } : {}, ref: r.alias ?? r.table }] : []), Tt = (t) => U(t).flatMap((e) => {
37
37
  const r = e.alias ?? e.table;
38
38
  return r === void 0 ? [] : [r];
39
39
  });
40
- function v(t, e) {
40
+ function Q(t, e) {
41
41
  if (t.type === "field") {
42
42
  const r = t.table && e.get(t.table);
43
43
  return r ? { ...t, table: r } : t;
44
44
  }
45
- return Y(t, (r) => v(r, e));
46
- }
47
- const nt = (t) => t ? t.type === "logical" && t.operator === "AND" ? t.operands : [t] : [];
48
- function _t(t, e) {
49
- var s, i;
50
- if (e.type !== "binary" || ((s = e.left) == null ? void 0 : s.type) !== "field" || ((i = e.right) == null ? void 0 : i.type) !== "field")
51
- return !1;
52
- const r = [e.left.table, e.right.table], n = { ...e, left: e.right, right: e.left };
53
- return t.joins.some((a) => r.includes(a.alias ?? a.table) && nt(a.on).some((o) => M(o, e) || M(o, n)));
54
- }
55
- function st(t, e, r, n, s = new Set(rt(e))) {
56
- const i = /* @__PURE__ */ new Map([[r.table, r.ref]]), a = [];
57
- let o;
58
- return K(n.condition).forEach((c) => {
59
- if (o || i.has(c)) return;
60
- const u = Dt(t, [...i.keys()], c);
61
- if (!u) {
62
- o = c;
63
- return;
64
- }
65
- u.forEach((f) => {
66
- const l = Ot(t, [...i.keys()], f);
67
- if (!l) return;
68
- const $ = (m) => v(l.on, new Map([...i, [f, m]])), T = L(e).flatMap((m) => m.table === f ? [m.alias ?? f] : []).find((m) => _t(e, $(m)));
69
- if (T) {
70
- i.set(f, T);
71
- return;
72
- }
73
- let y = f;
74
- for (let m = 2; s.has(y); m += 1) y = `${f}_${m}`;
75
- s.add(y), i.set(f, y), a.push({
76
- id: Ct(),
77
- table: f,
78
- ...y !== f ? { alias: y } : {},
79
- joinType: l.joinType,
80
- on: $(y)
81
- });
82
- });
83
- }), { joins: a, condition: v(n.condition, i), ...o ? { missing: o } : {} };
45
+ return K(t, (r) => Q(r, e));
46
+ }
47
+ const At = (t) => t ? t.type === "logical" && t.operator === "AND" ? t.operands : [t] : [], te = (t) => t.joinType === "inner" || t.joinType === "left";
48
+ function ee(t, e, r, n, s) {
49
+ const o = e.type === "binary" && e.left && e.right ? { ...e, left: e.right, right: e.left } : e, a = { forward: !1, back: !1 };
50
+ return t.joins.forEach((i) => {
51
+ const c = i.alias ?? i.table;
52
+ if (c !== r && c !== n || !te(i) || !At(i.on).some((f) => B(f, e) || B(f, o))) return;
53
+ const u = i.joinType === "inner";
54
+ c === r ? (a.forward = !0, a.back || (a.back = u)) : (a.back = !0, a.forward || (a.forward = u || s));
55
+ }), a;
56
+ }
57
+ const st = (t) => t.some((e, r) => t.slice(0, r).every((n) => n.forward) && t.slice(r).every((n) => n.back)) || t.every((e) => e.forward);
58
+ function mt(t, e, r, n, s = new Set(Tt(e))) {
59
+ const o = k(n.condition), a = U(e), i = (c) => {
60
+ const u = /* @__PURE__ */ new Map([[r.table, r.ref]]), f = /* @__PURE__ */ new Map(), l = [], $ = new Set(s), p = (m) => {
61
+ const O = f.get(m);
62
+ return O ? [...p(O.ref), O.tie] : [];
63
+ }, g = (m, O, P) => {
64
+ if (O === m.length) return st(p(u.get(P)));
65
+ const h = m[O], L = Bt(t, [...u.keys()], h);
66
+ if (!L) return !1;
67
+ const Z = u.get(k(L.on).find((y) => y !== h)), tt = (y) => Q(L.on, new Map([...u, [h, y]])), et = o.includes(h), rt = (y, S) => {
68
+ u.set(h, y), f.set(y, { ref: Z, tie: S });
69
+ }, Ft = (y, S) => (rt(y, S), st(p(y)) && g(m, O + 1, P) ? !0 : (u.delete(h), f.delete(y), !1));
70
+ if (a.some((y) => {
71
+ if (y.table !== h) return !1;
72
+ const S = y.alias ?? h, G = ee(e, tt(S), Z, S, et);
73
+ return (G.forward || G.back) && Ft(S, G);
74
+ })) return !0;
75
+ if (!c) return !1;
76
+ let N = h;
77
+ for (let y = 2; $.has(N); y += 1) N = `${h}_${y}`;
78
+ return $.add(N), rt(N, { back: !0, forward: L.joinType === "inner" || et }), l.push({
79
+ id: Gt(),
80
+ table: h,
81
+ ...N !== h ? { alias: N } : {},
82
+ joinType: L.joinType,
83
+ on: tt(N)
84
+ }), g(m, O + 1, P);
85
+ };
86
+ let v;
87
+ if (o.every((m) => {
88
+ if (v || u.has(m)) return !0;
89
+ const O = vt(t, [...u.keys()], m);
90
+ return O ? g(O, 0, m) : (v = m, !0);
91
+ }))
92
+ return $.forEach((m) => s.add(m)), { joins: l, condition: Q(n.condition, u), ...v ? { missing: v } : {} };
93
+ };
94
+ return i(!1) ?? i(!0);
84
95
  }
85
- function it(t, e) {
86
- return nt(t).some((r) => M(r, e));
96
+ function gt(t, e) {
97
+ return At(t).some((r) => B(r, e));
87
98
  }
88
- function Ht(t, e) {
99
+ function re(t, e) {
89
100
  return (t == null ? void 0 : t.type) === "logical" && t.operator === "AND" ? { ...t, operands: [...t.operands, e] } : t ? { type: "logical", operator: "AND", operands: [t, e] } : e;
90
101
  }
91
- function x(t, e, r, n, s) {
92
- return et(e, r).reduce((i, a) => {
93
- const o = st(t, i, a, r, s);
94
- if (o.missing) throw new jt(n, a.table, o.missing, a.alias);
95
- const c = it(i.where, o.condition);
96
- return o.joins.length === 0 && c ? i : {
97
- ...i,
98
- joins: [...i.joins, ...o.joins],
99
- where: c ? i.where : Ht(i.where, o.condition)
102
+ function ot(t, e, r, n, s) {
103
+ return pt(e, r).reduce((o, a) => {
104
+ const i = mt(t, o, a, r, s);
105
+ if (i.missing) throw new Zt(n, a.table, i.missing, a.alias);
106
+ const c = gt(o.where, i.condition);
107
+ return i.joins.length === 0 && c ? o : {
108
+ ...o,
109
+ joins: [...o.joins, ...i.joins],
110
+ where: c ? o.where : re(o.where, i.condition)
100
111
  };
101
112
  }, e);
102
113
  }
103
- function Q(t) {
104
- const e = /* @__PURE__ */ new Map(), r = (n, s, i, a) => {
114
+ function it(t) {
115
+ const e = /* @__PURE__ */ new Map(), r = (n, s, o, a) => {
105
116
  if (Array.isArray(n)) {
106
117
  n.forEach((c, u) => r(c, [...s, u], void 0, a));
107
118
  return;
108
119
  }
109
- if (!q(n)) return;
110
- let o = a;
111
- tt(n) && (o = i ?? /* @__PURE__ */ new Set(), e.set(JSON.stringify(s), o), rt(n).forEach((c) => o.add(c))), Object.entries(n).forEach(([c, u]) => r(
120
+ if (!H(n)) return;
121
+ let i = a;
122
+ yt(n) && (i = o ?? /* @__PURE__ */ new Set(), e.set(JSON.stringify(s), i), Tt(n).forEach((c) => i.add(c))), Object.entries(n).forEach(([c, u]) => r(
112
123
  u,
113
124
  [...s, c],
114
- n.type === "exists" && c === "query" ? o : void 0,
115
- o
125
+ n.type === "exists" && c === "query" ? i : void 0,
126
+ i
116
127
  ));
117
128
  };
118
129
  return r(t, [], void 0, /* @__PURE__ */ new Set()), e;
119
130
  }
120
- function ge(t, e, r) {
121
- const n = x(
131
+ function ve(t, e, r) {
132
+ const n = ot(
122
133
  t,
123
134
  e,
124
135
  r,
125
136
  [],
126
- Q(e).get("[]")
127
- ), s = D(t, e, n), i = Q(s), a = w(s, [], (o, c) => c.length === 0 ? o : x(t, o, r, c, i.get(JSON.stringify(c))));
128
- return D(t, s, a);
137
+ it(e).get("[]")
138
+ ), s = R(t, e, n), o = it(s), a = j(s, [], (i, c) => c.length === 0 ? i : ot(t, i, r, c, o.get(JSON.stringify(c))));
139
+ return R(t, s, a);
129
140
  }
130
- function he(t, e, r) {
131
- if (!q(t) || !Array.isArray(t.tables))
141
+ function Be(t, e, r) {
142
+ if (!H(t) || !Array.isArray(t.tables))
132
143
  throw new TypeError("unscopedBodies takes (schema, query, rule) since 0.4.0");
133
144
  const n = [];
134
- return w(e, [], (s, i) => (et(s, r).forEach((a) => {
135
- const o = st(t, s, a, r);
136
- (o.missing || o.joins.length > 0 || !it(s.where, o.condition)) && n.push({ path: i, table: a.table, ...a.alias ? { alias: a.alias } : {} });
145
+ return j(e, [], (s, o) => (pt(s, r).forEach((a) => {
146
+ const i = mt(t, s, a, r);
147
+ (i.missing || i.joins.length > 0 || !gt(s.where, i.condition)) && n.push({ path: o, table: a.table, ...a.alias ? { alias: a.alias } : {} });
137
148
  }), s)), n;
138
149
  }
139
- const Yt = (t) => typeof t == "object" && t !== null && !(t instanceof Date), X = {
150
+ const ne = (t) => typeof t == "object" && t !== null && !(t instanceof Date), at = {
140
151
  /** A column: `expr.field('orders', 'status')`. */
141
152
  field: (t, e) => ({ type: "field", table: t, column: e }),
142
153
  /** A literal value, written into the SQL (as a bound parameter by
@@ -203,7 +214,7 @@ const Yt = (t) => typeof t == "object" && t !== null && !(t instanceof Date), X
203
214
  type: "binary",
204
215
  operator: "IN",
205
216
  left: t,
206
- right: Array.isArray(e) ? X.list(...e) : e
217
+ right: Array.isArray(e) ? at.list(...e) : e
207
218
  }),
208
219
  /** `left BETWEEN low AND high` (issue 169), both bounds included: each a
209
220
  * value or an expression (a param, a relative date). NOT BETWEEN:
@@ -212,13 +223,13 @@ const Yt = (t) => typeof t == "object" && t !== null && !(t instanceof Date), X
212
223
  type: "binary",
213
224
  operator: "BETWEEN",
214
225
  left: t,
215
- right: X.list(e, r)
226
+ right: at.list(e, r)
216
227
  }),
217
228
  /** IN's values: each a value (`expr.list(1, 2)`) or an expression
218
229
  * (`expr.list(expr.param('a'), expr.param('b'))`). */
219
230
  list: (...t) => ({
220
231
  type: "list",
221
- items: t.map((e) => Yt(e) ? e : { type: "literal", value: e })
232
+ items: t.map((e) => ne(e) ? e : { type: "literal", value: e })
222
233
  }),
223
234
  /** A query of its own for IN to compare with, selecting `select` — one
224
235
  * column. Its tables are its own: it sees nothing of the query around
@@ -227,91 +238,91 @@ const Yt = (t) => typeof t == "object" && t !== null && !(t instanceof Date), X
227
238
  * 'customer_id') }))`. */
228
239
  subquery: ({ select: t, ...e }) => ({
229
240
  type: "subquery",
230
- id: G(),
231
- query: { joins: [], ...e, select: [{ id: G(), expression: t }] }
241
+ id: nt(),
242
+ query: { joins: [], ...e, select: [{ id: nt(), expression: t }] }
232
243
  })
233
244
  };
234
- function De(t, e, r) {
245
+ function je(t, e, r) {
235
246
  return A(t, e, { type: "setBaseTable", table: r });
236
247
  }
237
- function Oe(t, e, r, n = {}) {
248
+ function _e(t, e, r, n = {}) {
238
249
  const s = { type: "addJoin", table: r, ...n };
239
250
  return A(t, e, s);
240
251
  }
241
- function Ne(t, e, r) {
252
+ function He(t, e, r) {
242
253
  return A(t, e, { type: "removeJoin", joinId: r });
243
254
  }
244
- function Pt(t, e, r, n = {}) {
245
- const s = Lt(e), i = K(r);
246
- if (s && i.some((u) => u !== s.alias)) {
247
- if (i.includes(s.alias))
255
+ function se(t, e, r, n = {}) {
256
+ const s = xt(e), o = k(r);
257
+ if (s && o.some((u) => u !== s.alias)) {
258
+ if (o.includes(s.alias))
248
259
  throw new Error("addCondition: a condition names both the union and tables of its branches: add it in two parts");
249
260
  return s.query.union.forEach((u) => {
250
- const f = u.from.table, l = new Set(L(u).map(J)), $ = Mt(t, f), T = i.find((y) => !l.has(y) && !$.has(y));
251
- if (T)
252
- throw new Error(`addCondition: "${T}" can't be reached from "${f}", one of the union's tables: a condition must reach every branch`);
253
- }), s.query.union.reduce((u, f, l) => wt(
261
+ const f = u.from.table, l = new Set(U(u).map(ft)), $ = kt(t, f), p = o.find((g) => !l.has(g) && !$.has(g));
262
+ if (p)
263
+ throw new Error(`addCondition: "${p}" can't be reached from "${f}", one of the union's tables: a condition must reach every branch`);
264
+ }), s.query.union.reduce((u, f, l) => Qt(
254
265
  u,
255
- [Ft(s.id, l)],
256
- ($) => Pt(t, $, r, n)
266
+ [Xt(s.id, l)],
267
+ ($) => se(t, $, r, n)
257
268
  ), e);
258
269
  }
259
- const a = n.operator ?? "AND", { where: o } = e;
270
+ const a = n.operator ?? "AND", { where: i } = e;
260
271
  let c;
261
- return o ? o.type === "logical" && o.operator === a ? c = { ...o, operands: [...o.operands, r] } : c = { type: "logical", operator: a, operands: [o, r] } : c = r, D(t, e, qt(t, e, c));
272
+ return i ? i.type === "logical" && i.operator === a ? c = { ...i, operands: [...i.operands, r] } : c = { type: "logical", operator: a, operands: [i, r] } : c = r, R(t, e, Vt(t, e, c));
262
273
  }
263
- function Se(t, e, r, n) {
264
- const s = A(t, e, { type: "addSelectItem" }), i = s.select[s.select.length - 1].id, a = A(t, s, {
274
+ function Ye(t, e, r, n) {
275
+ const s = A(t, e, { type: "addSelectItem" }), o = s.select[s.select.length - 1].id, a = A(t, s, {
265
276
  type: "setSelectExpression",
266
- selectId: i,
277
+ selectId: o,
267
278
  expression: r
268
- }), o = n === void 0 ? a : A(t, a, { type: "setSelectAlias", selectId: i, alias: n });
269
- return D(t, e, o);
279
+ }), i = n === void 0 ? a : A(t, a, { type: "setSelectAlias", selectId: o, alias: n });
280
+ return R(t, e, i);
270
281
  }
271
- function be(t, e, r) {
272
- const n = A(t, e, { type: "addGroupByItem" }), { id: s } = n.groupBy[n.groupBy.length - 1], i = A(t, n, {
282
+ function Pe(t, e, r) {
283
+ const n = A(t, e, { type: "addGroupByItem" }), { id: s } = n.groupBy[n.groupBy.length - 1], o = A(t, n, {
273
284
  type: "setGroupByExpression",
274
285
  groupById: s,
275
286
  expression: r
276
287
  });
277
- return D(t, e, i);
288
+ return R(t, e, o);
278
289
  }
279
- function Re(t, e, r) {
280
- return D(t, e, Ut(t, e, r));
290
+ function Ge(t, e, r) {
291
+ return R(t, e, Wt(t, e, r));
281
292
  }
282
- function Ie(t, e, r, n = "asc") {
283
- const s = A(t, e, { type: "addOrderByItem" }), { id: i } = s.orderBy[s.orderBy.length - 1], a = A(t, s, {
293
+ function xe(t, e, r, n = "asc") {
294
+ const s = A(t, e, { type: "addOrderByItem" }), { id: o } = s.orderBy[s.orderBy.length - 1], a = A(t, s, {
284
295
  type: "setOrderByExpression",
285
- orderById: i,
296
+ orderById: o,
286
297
  expression: r
287
- }), o = A(t, a, {
298
+ }), i = A(t, a, {
288
299
  type: "setOrderByDirection",
289
- orderById: i,
300
+ orderById: o,
290
301
  direction: n
291
302
  });
292
- return D(t, e, o);
303
+ return R(t, e, i);
293
304
  }
294
- function Ce(t, e, r) {
305
+ function ke(t, e, r) {
295
306
  let n = e;
296
307
  return "limit" in r && (n = A(t, n, { type: "setLimit", limit: r.limit })), "offset" in r && (n = A(t, n, { type: "setOffset", offset: r.offset })), n;
297
308
  }
298
- function Le(t, e, r) {
309
+ function Qe(t, e, r) {
299
310
  return A(t, e, { type: "setDistinct", distinct: r });
300
311
  }
301
- function Me(t) {
302
- if (!Nt(t)) throw new Error(`query "${t.id}" has no base table yet`);
312
+ function Xe(t) {
313
+ if (!jt(t)) throw new Error(`query "${t.id}" has no base table yet`);
303
314
  return t;
304
315
  }
305
- const B = 4;
306
- class S extends Error {
316
+ const X = 4;
317
+ class w extends Error {
307
318
  constructor(r, n) {
308
319
  super(n);
309
- b(this, "kind");
320
+ M(this, "kind");
310
321
  this.name = "QueryFormatError", this.kind = r;
311
322
  }
312
323
  }
313
- const C = (t) => typeof t == "object" && t !== null && !Array.isArray(t);
314
- function Gt(t) {
324
+ const q = (t) => typeof t == "object" && t !== null && !Array.isArray(t);
325
+ function oe(t) {
315
326
  const e = [];
316
327
  let r = 0;
317
328
  for (; r < t.length; ) {
@@ -330,83 +341,83 @@ function Gt(t) {
330
341
  }
331
342
  return e;
332
343
  }
333
- function xt(t) {
344
+ function ie(t) {
334
345
  const e = (r) => {
335
346
  if (Array.isArray(r)) return r.map(e);
336
- if (!C(r)) return r;
337
- const n = Object.fromEntries(Object.entries(r).map(([a, o]) => [a, e(o)])), { right: s } = n;
338
- if (n.type !== "binary" || n.operator !== "IN" || !C(s) || s.type === "subquery" || s.type === "list") return n;
339
- const i = s.type === "literal" && typeof s.value == "string" ? Gt(s.value).map((a) => ({ type: "literal", value: a })) : [s];
340
- return { ...n, right: { type: "list", items: i } };
347
+ if (!q(r)) return r;
348
+ const n = Object.fromEntries(Object.entries(r).map(([a, i]) => [a, e(i)])), { right: s } = n;
349
+ if (n.type !== "binary" || n.operator !== "IN" || !q(s) || s.type === "subquery" || s.type === "list") return n;
350
+ const o = s.type === "literal" && typeof s.value == "string" ? oe(s.value).map((a) => ({ type: "literal", value: a })) : [s];
351
+ return { ...n, right: { type: "list", items: o } };
341
352
  };
342
353
  return e(t);
343
354
  }
344
- const Qt = (t) => t, Xt = (t) => t, Vt = [xt, Qt, Xt];
345
- function Wt(t, e, r) {
355
+ const ae = (t) => t, ue = (t) => t, ce = [ie, ae, ue];
356
+ function fe(t, e, r) {
346
357
  return r.slice(e - 1).reduce((n, s) => s(n), t);
347
358
  }
348
- function F(t, e) {
349
- return Array.isArray(t) ? t.map((r) => F(r, e)) : C(t) ? t.type === "literal" ? e(t) : Object.fromEntries(Object.entries(t).map(([r, n]) => [r, F(n, e)])) : t;
359
+ function _(t, e) {
360
+ return Array.isArray(t) ? t.map((r) => _(r, e)) : q(t) ? t.type === "literal" ? e(t) : Object.fromEntries(Object.entries(t).map(([r, n]) => [r, _(n, e)])) : t;
350
361
  }
351
- function Jt(t) {
362
+ function le(t) {
352
363
  return t.value instanceof Date ? { ...t, value: t.value.toISOString(), valueType: "date" } : typeof t.value == "bigint" ? { ...t, value: String(t.value), valueType: "bigint" } : t;
353
364
  }
354
- function kt(t) {
365
+ function $e(t) {
355
366
  if (t.valueType === void 0) return t;
356
367
  const { valueType: e, ...r } = t, n = String(r.value);
357
368
  let s;
358
369
  if (e === "date") {
359
370
  if (s = new Date(n), Number.isNaN(s.getTime()))
360
- throw new S("invalid", `not a date: ${JSON.stringify(n)}`);
371
+ throw new w("invalid", `not a date: ${JSON.stringify(n)}`);
361
372
  } else if (e === "bigint" && /^-?\d+$/.test(n))
362
373
  s = BigInt(n);
363
374
  else {
364
- const i = String(e);
365
- throw new S("invalid", `can't read a ${i} from ${JSON.stringify(n)}`);
375
+ const o = String(e);
376
+ throw new w("invalid", `can't read a ${o} from ${JSON.stringify(n)}`);
366
377
  }
367
378
  return { ...r, value: s };
368
379
  }
369
- function we(t) {
380
+ function Ve(t) {
370
381
  return {
371
- version: B,
372
- query: F(t, Jt)
382
+ version: X,
383
+ query: _(t, le)
373
384
  };
374
385
  }
375
- function Fe(t) {
376
- if (!C(t))
377
- throw new S("invalid", "a stored query is an object");
386
+ function We(t) {
387
+ if (!q(t))
388
+ throw new w("invalid", "a stored query is an object");
378
389
  const { version: e } = t;
379
390
  if (typeof e != "number" || !Number.isInteger(e) || e < 1)
380
- throw new S("invalid", "a stored query has a whole-number version from 1");
381
- if (e > B)
382
- throw new S(
391
+ throw new w("invalid", "a stored query has a whole-number version from 1");
392
+ if (e > X)
393
+ throw new w(
383
394
  "newerVersion",
384
- `stored in format ${e}; this version reads up to ${B}`
395
+ `stored in format ${e}; this version reads up to ${X}`
385
396
  );
386
- const r = Wt(t.query, e, Vt);
387
- if (!C(r) || typeof r.id != "string")
388
- throw new S("invalid", "a stored query has a query with a string id");
389
- return F(r, kt);
397
+ const r = fe(t.query, e, ce);
398
+ if (!q(r) || typeof r.id != "string")
399
+ throw new w("invalid", "a stored query has a query with a string id");
400
+ return _(r, $e);
390
401
  }
391
- function j(t, e) {
402
+ function V(t, e) {
392
403
  const r = new Map(e == null ? void 0 : e.tableOf), n = new Set(e == null ? void 0 : e.aliases), s = new Set(e == null ? void 0 : e.derived);
393
- return t.forEach(({ table: i, alias: a }) => {
394
- if (i === void 0) {
404
+ return t.forEach(({ table: o, alias: a }) => {
405
+ if (o === void 0) {
395
406
  a && s.add(a);
396
407
  return;
397
408
  }
398
- if (r.set(i, i), a) {
399
- r.set(a, i), n.add(a), s.delete(a);
409
+ if (r.set(o, o), a) {
410
+ r.set(a, o), n.add(a), s.delete(a);
400
411
  return;
401
412
  }
402
- n.delete(i), s.delete(i);
413
+ n.delete(o), s.delete(o);
403
414
  }), { tableOf: r, aliases: n, derived: s };
404
415
  }
405
- function Kt(t, e, r) {
406
- const n = t.on && I(t.on, e, r);
407
- return t.query ? { ...t, on: n, query: St(t.query, (s) => U(s, r)) } : t.shared !== void 0 ? { ...t, on: n } : { ...t, on: n, table: r(t.table) };
416
+ function Ee(t, e, r) {
417
+ const n = t.on && F(t.on, e, r);
418
+ return t.query ? { ...t, on: n, query: _t(t.query, (s) => Y(s, r)) } : t.shared !== void 0 ? { ...t, on: n } : { ...t, on: n, table: r(t.table) };
408
419
  }
409
- function I(t, e, r) {
420
+ function F(t, e, r) {
410
421
  if (t.type === "field") {
411
422
  if (!t.table || e.derived.has(t.table)) return t;
412
423
  const n = e.tableOf.get(t.table) ?? t.table;
@@ -416,27 +427,27 @@ function I(t, e, r) {
416
427
  ...t.column ? { column: r(n, t.column) } : {}
417
428
  };
418
429
  }
419
- if (t.type === "subquery") return { ...t, query: U(t.query, r) };
430
+ if (t.type === "subquery") return { ...t, query: Y(t.query, r) };
420
431
  if (t.type === "exists") {
421
- const { query: n } = t, s = [n.from, ...n.joins], i = j(s), a = j(s, e);
432
+ const { query: n } = t, s = [n.from, ...n.joins], o = V(s), a = V(s, e);
422
433
  return {
423
434
  ...t,
424
- link: I(t.link, a, r),
435
+ link: F(t.link, a, r),
425
436
  query: {
426
437
  ...n,
427
438
  from: { ...n.from, table: r(n.from.table) },
428
- joins: n.joins.map((o) => Kt(o, i, r)),
429
- ...n.where ? { where: I(n.where, i, r) } : {}
439
+ joins: n.joins.map((i) => Ee(i, o, r)),
440
+ ...n.where ? { where: F(n.where, o, r) } : {}
430
441
  }
431
442
  };
432
443
  }
433
- return Y(t, (n) => I(n, e, r));
444
+ return K(t, (n) => F(n, e, r));
434
445
  }
435
- function U(t, e) {
436
- const r = j([t.from, ...t.joins]), n = k(
446
+ function Y(t, e) {
447
+ const r = V([t.from, ...t.joins]), n = lt(
437
448
  t,
438
- (s) => I(s, r, e),
439
- (s) => U(s, e)
449
+ (s) => F(s, r, e),
450
+ (s) => Y(s, e)
440
451
  );
441
452
  return {
442
453
  ...n,
@@ -444,11 +455,11 @@ function U(t, e) {
444
455
  joins: n.joins.map((s) => s.table === void 0 ? s : { ...s, table: e(s.table) })
445
456
  };
446
457
  }
447
- function _(t, e) {
448
- if (Array.isArray(t)) return t.map((s) => _(s, e));
458
+ function W(t, e) {
459
+ if (Array.isArray(t)) return t.map((s) => W(s, e));
449
460
  if (typeof t != "object" || t === null || t instanceof Date) return t;
450
461
  const r = Object.fromEntries(Object.entries(t).map(
451
- ([s, i]) => [s, _(i, e)]
462
+ ([s, o]) => [s, W(o, e)]
452
463
  ));
453
464
  if (!("from" in r) || !Array.isArray(r.joins)) return r;
454
465
  const n = (s) => s.table !== void 0 && !s.alias && e(s.table) !== s.table ? { ...s, alias: s.table } : s;
@@ -458,44 +469,44 @@ function _(t, e) {
458
469
  joins: r.joins.map(n)
459
470
  };
460
471
  }
461
- function zt(t, e) {
462
- return U(_(t, e), e);
472
+ function ye(t, e) {
473
+ return Y(W(t, e), e);
463
474
  }
464
- const Zt = /^(\d{2}):(\d{2})(?::(\d{2}))?$/, V = /YYYY|MM|DD|HH|mm|ss/g, N = (t, e = 2) => String(t).padStart(e, "0");
465
- function ot(t, e) {
475
+ const pe = /^(\d{2}):(\d{2})(?::(\d{2}))?$/, ut = /YYYY|MM|DD|HH|mm|ss/g, C = (t, e = 2) => String(t).padStart(e, "0");
476
+ function ht(t, e) {
466
477
  let r;
467
- const n = typeof t == "string" ? Zt.exec(t.trim()) : null;
478
+ const n = typeof t == "string" ? pe.exec(t.trim()) : null;
468
479
  if (n)
469
480
  r = { HH: n[1], mm: n[2], ss: n[3] ?? "00" };
470
481
  else {
471
- const a = typeof t == "string" ? dt(t, "dateTime") : t;
482
+ const a = typeof t == "string" ? Jt(t, "dateTime") : t;
472
483
  a instanceof Date && (r = {
473
- YYYY: N(a.getUTCFullYear(), 4),
474
- MM: N(a.getUTCMonth() + 1),
475
- DD: N(a.getUTCDate()),
476
- HH: N(a.getUTCHours()),
477
- mm: N(a.getUTCMinutes()),
478
- ss: N(a.getUTCSeconds())
484
+ YYYY: C(a.getUTCFullYear(), 4),
485
+ MM: C(a.getUTCMonth() + 1),
486
+ DD: C(a.getUTCDate()),
487
+ HH: C(a.getUTCHours()),
488
+ mm: C(a.getUTCMinutes()),
489
+ ss: C(a.getUTCSeconds())
479
490
  });
480
491
  }
481
492
  if (!r) return t;
482
493
  const s = r;
483
- return (e.match(V) ?? []).some((a) => s[a] === void 0) ? t : e.replace(V, (a) => s[a]);
494
+ return (e.match(ut) ?? []).some((a) => s[a] === void 0) ? t : e.replace(ut, (a) => s[a]);
484
495
  }
485
- function at(t, e) {
496
+ function Ot(t, e) {
486
497
  const r = /* @__PURE__ */ new Map(), n = (s) => {
487
- const i = /* @__PURE__ */ new Map();
488
- L(s).forEach((u) => i.set(J(u), u.table));
498
+ const o = /* @__PURE__ */ new Map();
499
+ U(s).forEach((u) => o.set(ft(u), u.table));
489
500
  const a = (u) => {
490
501
  if ((u == null ? void 0 : u.type) !== "field" || !u.table || !u.column) return;
491
- const f = i.has(u.table) ? i.get(u.table) : u.table, l = f === void 0 ? void 0 : bt(e, f), $ = l == null ? void 0 : l.columns.find((T) => T.name === u.column);
502
+ const f = o.has(u.table) ? o.get(u.table) : u.table, l = f === void 0 ? void 0 : Ht(e, f), $ = l == null ? void 0 : l.columns.find((p) => p.name === u.column);
492
503
  return $ == null ? void 0 : $.format;
493
- }, o = (u, f) => {
504
+ }, i = (u, f) => {
494
505
  switch (u.type) {
495
506
  case "literal":
496
- return { ...u, value: ot(u.value, f) };
507
+ return { ...u, value: ht(u.value, f) };
497
508
  case "list":
498
- return { ...u, items: u.items.map((l) => o(l, f)) };
509
+ return { ...u, items: u.items.map((l) => i(l, f)) };
499
510
  case "param":
500
511
  return r.has(u.name) || r.set(u.name, f), u;
501
512
  default:
@@ -503,25 +514,25 @@ function at(t, e) {
503
514
  }
504
515
  }, c = (u) => {
505
516
  if (u.type === "subquery") return { ...u, query: n(u.query) };
506
- const f = Y(u, c);
517
+ const f = K(u, c);
507
518
  if (f.type !== "binary" || !f.right) return f;
508
519
  const l = a(f.left), $ = a(f.right);
509
520
  return {
510
521
  ...f,
511
- left: $ ? o(f.left, $) : f.left,
512
- right: l ? o(f.right, l) : f.right
522
+ left: $ ? i(f.left, $) : f.left,
523
+ right: l ? i(f.right, l) : f.right
513
524
  };
514
525
  };
515
- return k(s, c, (u) => n(u));
526
+ return lt(s, c, (u) => n(u));
516
527
  };
517
528
  return { query: n(t), params: r };
518
529
  }
519
- const qe = ["mysql", "mssql", "postgres"], Ue = {
530
+ const Je = ["mysql", "mssql", "postgres"], Ke = {
520
531
  mysql: "MySQL",
521
532
  mssql: "SQL Server",
522
533
  postgres: "PostgreSQL"
523
534
  };
524
- function g(t, e) {
535
+ function D(t, e) {
525
536
  const r = t.replace(/[\uE000-\uE003]/g, "");
526
537
  switch (e) {
527
538
  case "mysql":
@@ -534,36 +545,36 @@ function g(t, e) {
534
545
  return `"${r.replace(/"/g, '""')}"`;
535
546
  }
536
547
  }
537
- const te = /^[A-Za-z_][A-Za-z0-9_]*$/, ut = (t) => `${t}`, ee = /\uE000(\d+)\uE000/g;
538
- let O;
539
- function de(t, e) {
540
- O = { ...t, writing: [] };
548
+ const Te = /^[A-Za-z_][A-Za-z0-9_]*$/, Dt = (t) => `${t}`, Ae = /\uE000(\d+)\uE000/g;
549
+ let I;
550
+ function ze(t, e) {
551
+ I = { ...t, writing: [] };
541
552
  try {
542
553
  return e();
543
554
  } finally {
544
- O = void 0;
555
+ I = void 0;
545
556
  }
546
557
  }
547
- function ct(t, e, r) {
558
+ function Nt(t, e, r) {
548
559
  if (typeof t != "object" || t === null || t instanceof Date) return;
549
560
  let n;
550
- return Object.entries(t).some(([s, i]) => {
561
+ return Object.entries(t).some(([s, o]) => {
551
562
  const a = [...r, Array.isArray(t) ? Number(s) : s];
552
- return n = i === e ? a : ct(i, e, a), n !== void 0;
563
+ return n = o === e ? a : Nt(o, e, a), n !== void 0;
553
564
  }), n;
554
565
  }
555
- function p(t, e) {
556
- if (!O) return e();
557
- const { writing: r, paths: n } = O, s = r[r.length - 1], i = typeof t == "string" ? [t] : ct(s.value, t, s.path);
558
- if (!i) return e();
559
- r.push({ value: t, path: i });
566
+ function T(t, e) {
567
+ if (!I) return e();
568
+ const { writing: r, paths: n } = I, s = r[r.length - 1], o = typeof t == "string" ? [t] : Nt(s.value, t, s.path);
569
+ if (!o) return e();
570
+ r.push({ value: t, path: o });
560
571
  try {
561
- return `${n.push(i) - 1}${e()}`;
572
+ return `${n.push(o) - 1}${e()}`;
562
573
  } finally {
563
574
  r.pop();
564
575
  }
565
576
  }
566
- const re = {
577
+ const me = {
567
578
  mysql: {
568
579
  text: "CHAR",
569
580
  integer: "SIGNED",
@@ -592,24 +603,24 @@ const re = {
592
603
  boolean: "boolean"
593
604
  }
594
605
  };
595
- function ne(t, e) {
606
+ function ge(t, e) {
596
607
  var n;
597
- const r = (n = re[e]) == null ? void 0 : n[t];
608
+ const r = (n = me[e]) == null ? void 0 : n[t];
598
609
  return r ? e === "postgres" ? `NULL::${r}` : `CAST(NULL AS ${r})` : "NULL";
599
610
  }
600
- function ft(t, e, r) {
611
+ function St(t, e, r) {
601
612
  if (t == null) return "NULL";
602
613
  if (r)
603
- return r.values.push(t), ut(r.values.length - 1);
614
+ return r.values.push(t), Dt(r.values.length - 1);
604
615
  if (typeof t == "boolean")
605
616
  return e === "mssql" ? t ? "1" : "0" : t ? "TRUE" : "FALSE";
606
617
  if (typeof t == "string") {
607
- const n = O ? t.replace(/[\uE001-\uE003]/g, "") : t;
618
+ const n = I ? t.replace(/[\uE001-\uE003]/g, "") : t;
608
619
  return n === "" ? "''" : `'${n.replace(/'/g, "''")}'`;
609
620
  }
610
- return typeof t == "number" || typeof t == "bigint" ? String(t) : t instanceof Date ? `'${Z(t)}'` : String(t);
621
+ return typeof t == "number" || typeof t == "bigint" ? String(t) : t instanceof Date ? `'${Et(t)}'` : String(t);
611
622
  }
612
- function se(t, e) {
623
+ function he(t, e) {
613
624
  switch (t) {
614
625
  case "!=":
615
626
  return e === "mssql" ? "<>" : "!=";
@@ -621,10 +632,10 @@ function se(t, e) {
621
632
  return t;
622
633
  }
623
634
  }
624
- function h(t) {
635
+ function b(t) {
625
636
  return (t == null ? void 0 : t.type) === "literal" && typeof t.value == "string" && /^[A-Za-z_]+$/.test(t.value) ? t.value.toUpperCase() : "DAY";
626
637
  }
627
- const d = {
638
+ const x = {
628
639
  YEAR: "year",
629
640
  QUARTER: "quarter",
630
641
  MONTH: "month",
@@ -634,43 +645,43 @@ const d = {
634
645
  MINUTE: "minute",
635
646
  SECOND: "second",
636
647
  MILLISECOND: "millisecond"
637
- }, ie = {
648
+ }, Oe = {
638
649
  // ---- Date arithmetic ----
639
650
  DATE_ADD: ([t, e], r, n, s) => {
640
651
  var a;
641
- const i = h(r[2]);
652
+ const o = b(r[2]);
642
653
  switch (n) {
643
654
  case "mysql":
644
- return i === "MILLISECOND" ? `DATE_ADD(${t}, INTERVAL (${e}) * 1000 MICROSECOND)` : `DATE_ADD(${t}, INTERVAL ${e} ${i})`;
655
+ return o === "MILLISECOND" ? `DATE_ADD(${t}, INTERVAL (${e}) * 1000 MICROSECOND)` : `DATE_ADD(${t}, INTERVAL ${e} ${o})`;
645
656
  case "postgres": {
646
- const o = d[i] ?? i.toLowerCase();
647
- return !s && ((a = r[1]) == null ? void 0 : a.type) === "literal" && typeof r[1].value == "number" ? `(${t} + INTERVAL '${r[1].value} ${o}')` : `(${t} + (${e} * INTERVAL '1 ${o}'))`;
657
+ const i = x[o] ?? o.toLowerCase();
658
+ return !s && ((a = r[1]) == null ? void 0 : a.type) === "literal" && typeof r[1].value == "number" ? `(${t} + INTERVAL '${r[1].value} ${i}')` : `(${t} + (${e} * INTERVAL '1 ${i}'))`;
648
659
  }
649
660
  case "mssql":
650
- return `DATEADD(${i}, ${e}, ${t})`;
661
+ return `DATEADD(${o}, ${e}, ${t})`;
651
662
  default:
652
- return `DATE_ADD(${t}, ${e}, ${h(r[2])})`;
663
+ return `DATE_ADD(${t}, ${e}, ${b(r[2])})`;
653
664
  }
654
665
  },
655
666
  DATE_SUB: ([t, e], r, n, s) => {
656
667
  var a;
657
- const i = h(r[2]);
668
+ const o = b(r[2]);
658
669
  switch (n) {
659
670
  case "mysql":
660
- return i === "MILLISECOND" ? `DATE_SUB(${t}, INTERVAL (${e}) * 1000 MICROSECOND)` : `DATE_SUB(${t}, INTERVAL ${e} ${i})`;
671
+ return o === "MILLISECOND" ? `DATE_SUB(${t}, INTERVAL (${e}) * 1000 MICROSECOND)` : `DATE_SUB(${t}, INTERVAL ${e} ${o})`;
661
672
  case "postgres": {
662
- const o = d[i] ?? i.toLowerCase();
663
- return !s && ((a = r[1]) == null ? void 0 : a.type) === "literal" && typeof r[1].value == "number" ? `(${t} - INTERVAL '${r[1].value} ${o}')` : `(${t} - (${e} * INTERVAL '1 ${o}'))`;
673
+ const i = x[o] ?? o.toLowerCase();
674
+ return !s && ((a = r[1]) == null ? void 0 : a.type) === "literal" && typeof r[1].value == "number" ? `(${t} - INTERVAL '${r[1].value} ${i}')` : `(${t} - (${e} * INTERVAL '1 ${i}'))`;
664
675
  }
665
676
  case "mssql":
666
- return `DATEADD(${i}, -(${e}), ${t})`;
677
+ return `DATEADD(${o}, -(${e}), ${t})`;
667
678
  default:
668
- return `DATE_SUB(${t}, ${e}, ${h(r[2])})`;
679
+ return `DATE_SUB(${t}, ${e}, ${b(r[2])})`;
669
680
  }
670
681
  },
671
682
  // ---- Date diff ----
672
683
  DATEDIFF: ([t, e], r, n) => {
673
- const s = h(r[2]);
684
+ const s = b(r[2]);
674
685
  switch (n) {
675
686
  case "mysql":
676
687
  return `TIMESTAMPDIFF(${s}, ${t}, ${e})`;
@@ -681,12 +692,12 @@ const d = {
681
692
  case "YEAR":
682
693
  return `EXTRACT(YEAR FROM age(${e}, ${t}))::integer`;
683
694
  case "QUARTER": {
684
- const i = `EXTRACT(YEAR FROM age(${e}, ${t}))`, a = `EXTRACT(MONTH FROM age(${e}, ${t}))`;
685
- return `FLOOR((${i} * 12 + ${a}) / 3)::integer`;
695
+ const o = `EXTRACT(YEAR FROM age(${e}, ${t}))`, a = `EXTRACT(MONTH FROM age(${e}, ${t}))`;
696
+ return `FLOOR((${o} * 12 + ${a}) / 3)::integer`;
686
697
  }
687
698
  case "MONTH": {
688
- const i = `EXTRACT(YEAR FROM age(${e}, ${t}))`, a = `EXTRACT(MONTH FROM age(${e}, ${t}))`;
689
- return `(${i} * 12 + ${a})::integer`;
699
+ const o = `EXTRACT(YEAR FROM age(${e}, ${t}))`, a = `EXTRACT(MONTH FROM age(${e}, ${t}))`;
700
+ return `(${o} * 12 + ${a})::integer`;
690
701
  }
691
702
  case "WEEK":
692
703
  return `FLOOR((${e}::date - ${t}::date) / 7)`;
@@ -709,7 +720,7 @@ const d = {
709
720
  },
710
721
  // ---- Date extract ----
711
722
  EXTRACT: ([t], e, r) => {
712
- const n = h(e[1]);
723
+ const n = b(e[1]);
713
724
  switch (r) {
714
725
  case "mysql":
715
726
  return n === "MILLISECOND" ? `FLOOR(MICROSECOND(${t}) / 1000)` : `EXTRACT(${n} FROM ${t})`;
@@ -723,7 +734,7 @@ const d = {
723
734
  },
724
735
  // ---- Date truncation ----
725
736
  DATE_TRUNC: ([t], e, r) => {
726
- const n = h(e[1]);
737
+ const n = b(e[1]);
727
738
  switch (r) {
728
739
  case "mysql":
729
740
  switch (n) {
@@ -749,7 +760,7 @@ const d = {
749
760
  return `/* unknown unit: ${n} */`;
750
761
  }
751
762
  case "postgres":
752
- return `DATE_TRUNC('${d[n] ?? n.toLowerCase()}', ${t})`;
763
+ return `DATE_TRUNC('${x[n] ?? n.toLowerCase()}', ${t})`;
753
764
  case "mssql":
754
765
  switch (n) {
755
766
  case "YEAR":
@@ -793,72 +804,72 @@ const d = {
793
804
  // ---- String aggregation (issue 137) ----
794
805
  // The separator goes into the SQL as a literal even in parameterized SQL:
795
806
  // MySQL's SEPARATOR takes nothing else.
796
- STRING_AGG: ([t = "??"], e, r, n, s, i) => {
797
- const a = e[1] ?? { type: "literal", value: ", " }, o = a.type === "literal" && typeof a.value == "string" ? ft(a.value, r) : "??", c = s.distinct ? "DISTINCT " : "", u = ($) => {
798
- var T;
799
- return (T = s.orderBy) != null && T.length ? `ORDER BY ${s.orderBy.map((y) => `${$(y)} ${y.direction === "desc" ? "DESC" : "ASC"}`).join(", ")}` : "";
800
- }, f = ($) => i($.expression), l = ($) => $ ? ` ${$}` : "";
807
+ STRING_AGG: ([t = "??"], e, r, n, s, o) => {
808
+ const a = e[1] ?? { type: "literal", value: ", " }, i = a.type === "literal" && typeof a.value == "string" ? St(a.value, r) : "??", c = s.distinct ? "DISTINCT " : "", u = ($) => {
809
+ var p;
810
+ return (p = s.orderBy) != null && p.length ? `ORDER BY ${s.orderBy.map((g) => `${$(g)} ${g.direction === "desc" ? "DESC" : "ASC"}`).join(", ")}` : "";
811
+ }, f = ($) => o($.expression), l = ($) => $ ? ` ${$}` : "";
801
812
  switch (r) {
802
813
  case "mysql":
803
- return `GROUP_CONCAT(${c}${t}${l(u(f))} SEPARATOR ${o})`;
814
+ return `GROUP_CONCAT(${c}${t}${l(u(f))} SEPARATOR ${i})`;
804
815
  case "postgres": {
805
- const $ = `CAST(${t} AS TEXT)`, T = u((y) => {
806
- if (!s.distinct) return f(y);
807
- if (M(y.expression, e[0])) return $;
816
+ const $ = `CAST(${t} AS TEXT)`, p = u((g) => {
817
+ if (!s.distinct) return f(g);
818
+ if (B(g.expression, e[0])) return $;
808
819
  throw new Error("PostgreSQL orders STRING_AGG of different values by the value only");
809
820
  });
810
- return `STRING_AGG(${c}${$}, ${o}${l(T)})`;
821
+ return `STRING_AGG(${c}${$}, ${i}${l(p)})`;
811
822
  }
812
823
  case "mssql": {
813
824
  if (s.distinct)
814
825
  throw new Error("SQL Server's STRING_AGG can't join only different values");
815
- const $ = u(f), T = $ ? ` WITHIN GROUP (${$})` : "";
816
- return `STRING_AGG(CAST(${t} AS NVARCHAR(MAX)), ${o})${T}`;
826
+ const $ = u(f), p = $ ? ` WITHIN GROUP (${$})` : "";
827
+ return `STRING_AGG(CAST(${t} AS NVARCHAR(MAX)), ${i})${p}`;
817
828
  }
818
829
  default:
819
- return `STRING_AGG(${c}${t}, ${o}${l(u(f))})`;
830
+ return `STRING_AGG(${c}${t}, ${i}${l(u(f))})`;
820
831
  }
821
832
  }
822
833
  };
823
- function R(t) {
834
+ function d(t) {
824
835
  return t.type === "binary" || t.type === "logical" || t.type === "if" || t.type === "case";
825
836
  }
826
837
  function E(t, e, r, n) {
827
- return p(t, () => oe(t, e, r, n));
838
+ return T(t, () => De(t, e, r, n));
828
839
  }
829
- function W(t, e, r, n) {
830
- const s = (i) => {
831
- if (!i) return "??";
832
- const a = E(i, e, r, n);
833
- return R(i) ? `(${a})` : a;
840
+ function ct(t, e, r, n) {
841
+ const s = (o) => {
842
+ if (!o) return "??";
843
+ const a = E(o, e, r, n);
844
+ return d(o) ? `(${a})` : a;
834
845
  };
835
- return p(t, () => {
836
- const [i, a] = t.type === "list" ? t.items : [t];
837
- return `${s(i)} AND ${s(a)}`;
846
+ return T(t, () => {
847
+ const [o, a] = t.type === "list" ? t.items : [t];
848
+ return `${s(o)} AND ${s(a)}`;
838
849
  });
839
850
  }
840
- function oe(t, e, r, n) {
851
+ function De(t, e, r, n) {
841
852
  var a;
842
- const s = " ".repeat(r), i = " ".repeat(r + 1);
853
+ const s = " ".repeat(r), o = " ".repeat(r + 1);
843
854
  switch (t.type) {
844
855
  case "literal":
845
- return t.value === "" && !t.empty ? "??" : t.value === null && t.as ? ne(t.as, e) : ft(t.value, e, n);
856
+ return t.value === "" && !t.empty ? "??" : t.value === null && t.as ? ge(t.as, e) : St(t.value, e, n);
846
857
  case "param": {
847
- if (!n) return te.test(t.name) ? `:${t.name}` : "??";
858
+ if (!n) return Te.test(t.name) ? `:${t.name}` : "??";
848
859
  if (!n.named.has(t.name))
849
860
  throw new Error(`no value for parameter "${t.name}"`);
850
- return n.values.push(n.named.get(t.name)), ut(n.values.length - 1);
861
+ return n.values.push(n.named.get(t.name)), Dt(n.values.length - 1);
851
862
  }
852
863
  case "field": {
853
864
  if (!t.column) return "??";
854
- const o = g(t.column, e);
855
- return t.table ? `${g(t.table, e)}.${o}` : o;
865
+ const i = D(t.column, e);
866
+ return t.table ? `${D(t.table, e)}.${i}` : i;
856
867
  }
857
868
  case "function": {
858
- const o = t.args.map((l) => E(l, e, r, n)), c = ie[t.name.toUpperCase()];
869
+ const i = t.args.map((l) => E(l, e, r, n)), c = Oe[t.name.toUpperCase()];
859
870
  if (c)
860
871
  return c(
861
- o,
872
+ i,
862
873
  t.args,
863
874
  e,
864
875
  n !== void 0,
@@ -866,218 +877,218 @@ function oe(t, e, r, n) {
866
877
  (l) => E(l, e, r, n)
867
878
  );
868
879
  const u = /^[A-Za-z_][A-Za-z0-9_.]*$/.test(t.name) || t.name === "" ? t.name : "??";
869
- if (o.length === 0 && u.toUpperCase() === "COUNT") return `${u}(*)`;
870
- const f = t.distinct && o.length > 0 ? "DISTINCT " : "";
871
- return `${u}(${f}${o.join(", ")})`;
880
+ if (i.length === 0 && u.toUpperCase() === "COUNT") return `${u}(*)`;
881
+ const f = t.distinct && i.length > 0 ? "DISTINCT " : "";
882
+ return `${u}(${f}${i.join(", ")})`;
872
883
  }
873
884
  case "binary": {
874
- const o = t.operator ? se(t.operator, e) : "=", c = E(t.left, e, r, n), u = R(t.left) ? `(${c})` : c;
875
- if (Bt(t.operator)) return `${u} ${o}`;
876
- if (!t.right) return `${u} ${o} ??`;
877
- if (o === "BETWEEN")
878
- return `${u} BETWEEN ${W(t.right, e, r, n)}`;
879
- if (o === "IN")
885
+ const i = t.operator ? he(t.operator, e) : "=", c = E(t.left, e, r, n), u = d(t.left) ? `(${c})` : c;
886
+ if (zt(t.operator)) return `${u} ${i}`;
887
+ if (!t.right) return `${u} ${i} ??`;
888
+ if (i === "BETWEEN")
889
+ return `${u} BETWEEN ${ct(t.right, e, r, n)}`;
890
+ if (i === "IN")
880
891
  return t.right.type === "list" ? `${u} IN ${E(t.right, e, r, n)}` : `${u} IN (${E(t.right, e, r, n)})`;
881
- const f = E(t.right, e, r, n), l = R(t.right) ? `(${f})` : f;
882
- return `${u} ${o} ${l}`;
892
+ const f = E(t.right, e, r, n), l = d(t.right) ? `(${f})` : f;
893
+ return `${u} ${i} ${l}`;
883
894
  }
884
895
  case "logical": {
885
896
  if (t.operands.length === 0) return "/* empty */";
886
897
  if (t.operands.length === 1)
887
898
  return E(t.operands[0], e, r, n);
888
- const o = `
899
+ const i = `
889
900
  ${s}${t.operator} `;
890
901
  return t.operands.map((c) => {
891
902
  if (c.type === "logical") {
892
903
  const u = E(c, e, r + 1, n);
893
904
  return `(
894
- ${i}${u}
905
+ ${o}${u}
895
906
  ${s})`;
896
907
  }
897
908
  return E(c, e, r, n);
898
- }).join(o);
909
+ }).join(i);
899
910
  }
900
911
  case "not": {
901
- const { operand: o } = t;
902
- if (o.type === "binary" && o.operator === "IN" && ((a = o.right) == null ? void 0 : a.type) === "subquery") {
903
- const c = E(o.left, e, r, n);
904
- return `${R(o.left) ? `(${c})` : c} NOT IN (${E(o.right, e, r, n)})`;
912
+ const { operand: i } = t;
913
+ if (i.type === "binary" && i.operator === "IN" && ((a = i.right) == null ? void 0 : a.type) === "subquery") {
914
+ const c = E(i.left, e, r, n);
915
+ return `${d(i.left) ? `(${c})` : c} NOT IN (${E(i.right, e, r, n)})`;
905
916
  }
906
- if (o.type === "binary" && o.operator === "BETWEEN" && o.right) {
907
- const c = E(o.left, e, r, n);
908
- return `${R(o.left) ? `(${c})` : c} NOT BETWEEN ${W(o.right, e, r, n)}`;
917
+ if (i.type === "binary" && i.operator === "BETWEEN" && i.right) {
918
+ const c = E(i.left, e, r, n);
919
+ return `${d(i.left) ? `(${c})` : c} NOT BETWEEN ${ct(i.right, e, r, n)}`;
909
920
  }
910
- if (o.type === "logical" || o.type === "not") {
911
- const c = E(o, e, r + 1, n);
921
+ if (i.type === "logical" || i.type === "not") {
922
+ const c = E(i, e, r + 1, n);
912
923
  return `NOT (
913
- ${i}${c}
924
+ ${o}${c}
914
925
  ${s})`;
915
926
  }
916
- return `NOT ${E(o, e, r, n)}`;
927
+ return `NOT ${E(i, e, r, n)}`;
917
928
  }
918
929
  case "if": {
919
- const o = t.condition ? E(t.condition, e, r, n) : "??", c = t.then ? E(t.then, e, r, n) : "??", u = t.else ? E(t.else, e, r, n) : "NULL";
920
- return e === "mysql" ? `IF(${o}, ${c}, ${u})` : e === "mssql" ? `IIF(${o}, ${c}, ${u})` : `CASE WHEN ${o} THEN ${c} ELSE ${u} END`;
930
+ const i = t.condition ? E(t.condition, e, r, n) : "??", c = t.then ? E(t.then, e, r, n) : "??", u = t.else ? E(t.else, e, r, n) : "NULL";
931
+ return e === "mysql" ? `IF(${i}, ${c}, ${u})` : e === "mssql" ? `IIF(${i}, ${c}, ${u})` : `CASE WHEN ${i} THEN ${c} ELSE ${u} END`;
921
932
  }
922
933
  case "case": {
923
- const o = t.subject ? ` ${E(t.subject, e, r, n)}` : "", c = t.branches.map((f) => {
934
+ const i = t.subject ? ` ${E(t.subject, e, r, n)}` : "", c = t.branches.map((f) => {
924
935
  const l = E(f.when, e, r + 1, n), $ = E(f.then, e, r + 1, n);
925
- return `${i}WHEN ${l} THEN ${$}`;
936
+ return `${o}WHEN ${l} THEN ${$}`;
926
937
  }).join(`
927
938
  `), u = t.else ? `
928
- ${i}ELSE ${E(t.else, e, r + 1, n)}` : "";
929
- return `CASE${o}
939
+ ${o}ELSE ${E(t.else, e, r + 1, n)}` : "";
940
+ return `CASE${i}
930
941
  ${c}${u}
931
942
  ${s}END`;
932
943
  }
933
944
  // EXISTS (SELECT 1 FROM … WHERE <link> AND <where>): the subquery written
934
945
  // in place, one level in, so its params fall in reading order.
935
946
  case "exists": {
936
- const { query: o, link: c } = t, u = ($) => $.type === "logical" && $.operator === "AND" ? $.operands : [$], f = o.where ? { type: "logical", operator: "AND", operands: [...u(c), ...u(o.where)] } : c;
947
+ const { query: i, link: c } = t, u = ($) => $.type === "logical" && $.operator === "AND" ? $.operands : [$], f = i.where ? { type: "logical", operator: "AND", operands: [...u(c), ...u(i.where)] } : c;
937
948
  return `EXISTS (
938
949
  ${[
939
950
  "SELECT 1",
940
951
  // The clauses below write their expressions with formatNode.
941
952
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
942
- Tt(o.from, e),
953
+ wt(i.from, e),
943
954
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
944
- ...o.joins.map(($) => pt($, e, n)),
955
+ ...i.joins.map(($) => Lt($, e, n)),
945
956
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
946
- lt(f, e, n)
957
+ bt(f, e, n)
947
958
  ].join(`
948
- `).replace(/^/gm, i)}
959
+ `).replace(/^/gm, o)}
949
960
  ${s})`;
950
961
  }
951
962
  // IN's right side (issue 122): its query, on lines of its own, inside the
952
963
  // parentheses IN writes around it.
953
964
  // An empty list is unfinished, like a value not filled in.
954
965
  case "list":
955
- return `(${t.items.map((o) => E(o, e, r, n)).join(", ") || "??"})`;
966
+ return `(${t.items.map((i) => E(i, e, r, n)).join(", ") || "??"})`;
956
967
  case "subquery":
957
968
  return `
958
- ${P(t.query, e, n).join(`
959
- `).replace(/^/gm, i)}
969
+ ${z(t.query, e, n).join(`
970
+ `).replace(/^/gm, o)}
960
971
  ${s}`;
961
972
  default:
962
973
  return "/* unknown */";
963
974
  }
964
975
  }
965
- function lt(t, e, r) {
976
+ function bt(t, e, r) {
966
977
  return `WHERE
967
978
  ${E(t, e, 1, r)}`;
968
979
  }
969
- const ae = {
980
+ const Ne = {
970
981
  inner: "INNER JOIN",
971
982
  left: "LEFT JOIN",
972
983
  right: "RIGHT JOIN",
973
984
  full: "FULL JOIN",
974
985
  cross: "CROSS JOIN"
975
986
  };
976
- let $t = /* @__PURE__ */ new Map();
977
- function Et(t, e, r) {
978
- return t.shared !== void 0 ? g($t.get(t.shared) ?? "??", e) : t.query ? `(
979
- ${yt(t.query, e, r).replace(/^/gm, " ")}
980
- )` : g(t.table, e);
981
- }
982
- function yt(t, e, r) {
983
- return Rt(t).map((n) => P(n, e, r).join(`
984
- `)).join(It(t) && !t.all ? `
987
+ let Rt = /* @__PURE__ */ new Map();
988
+ function It(t, e, r) {
989
+ return t.shared !== void 0 ? D(Rt.get(t.shared) ?? "??", e) : t.query ? `(
990
+ ${Ct(t.query, e, r).replace(/^/gm, " ")}
991
+ )` : D(t.table, e);
992
+ }
993
+ function Ct(t, e, r) {
994
+ return Yt(t).map((n) => z(n, e, r).join(`
995
+ `)).join(Pt(t) && !t.all ? `
985
996
  UNION
986
997
  ` : `
987
998
  UNION ALL
988
999
  `);
989
1000
  }
990
- function ue(t, e, r) {
1001
+ function Se(t, e, r) {
991
1002
  return t.length === 0 ? [] : [`WITH
992
- ${t.map((s) => p(s, () => {
993
- const i = yt(s.query, e, r).replace(/^/gm, " ");
994
- return ` ${g(s.name, e)} AS (
995
- ${i}
1003
+ ${t.map((s) => T(s, () => {
1004
+ const o = Ct(s.query, e, r).replace(/^/gm, " ");
1005
+ return ` ${D(s.name, e)} AS (
1006
+ ${o}
996
1007
  )`;
997
1008
  })).join(`,
998
1009
  `)}`];
999
1010
  }
1000
- function Tt(t, e, r) {
1001
- const n = t.alias ? ` AS ${g(t.alias, e)}` : "";
1002
- return `FROM ${p(t, () => `${Et(t, e, r)}${n}`)}`;
1011
+ function wt(t, e, r) {
1012
+ const n = t.alias ? ` AS ${D(t.alias, e)}` : "";
1013
+ return `FROM ${T(t, () => `${It(t, e, r)}${n}`)}`;
1003
1014
  }
1004
- function pt(t, e, r) {
1005
- return p(t, () => {
1006
- const n = Et(t, e, r), s = t.alias ? ` AS ${g(t.alias, e)}` : "";
1015
+ function Lt(t, e, r) {
1016
+ return T(t, () => {
1017
+ const n = It(t, e, r), s = t.alias ? ` AS ${D(t.alias, e)}` : "";
1007
1018
  if (t.joinType === "cross") return `CROSS JOIN ${n}${s}`;
1008
- const i = t.on ? E(t.on, e, 1, r) : "/* unconfigured */";
1009
- return `${ae[t.joinType]} ${n}${s}
1010
- ON ${i}`;
1019
+ const o = t.on ? E(t.on, e, 1, r) : "/* unconfigured */";
1020
+ return `${Ne[t.joinType]} ${n}${s}
1021
+ ON ${o}`;
1011
1022
  });
1012
1023
  }
1013
- function ce(t, e, r, n = "SELECT") {
1014
- if (t.length === 0) return `${n} ${p(t, () => "*")}`;
1015
- const s = t.map((i) => p(i, () => {
1016
- const a = E(i.expression, e, 1, r), o = i.alias ? ` AS ${g(i.alias, e)}` : "";
1017
- return `${a}${o}`;
1024
+ function be(t, e, r, n = "SELECT") {
1025
+ if (t.length === 0) return `${n} ${T(t, () => "*")}`;
1026
+ const s = t.map((o) => T(o, () => {
1027
+ const a = E(o.expression, e, 1, r), i = o.alias ? ` AS ${D(o.alias, e)}` : "";
1028
+ return `${a}${i}`;
1018
1029
  }));
1019
1030
  return `${n}
1020
1031
  ${s.join(`,
1021
1032
  `)}`;
1022
1033
  }
1023
- function fe(t, e, r) {
1034
+ function Re(t, e, r) {
1024
1035
  return `GROUP BY
1025
- ${t.map((s) => p(
1036
+ ${t.map((s) => T(
1026
1037
  s,
1027
1038
  () => E(s.expression, e, 1, r)
1028
1039
  )).join(`,
1029
1040
  `)}`;
1030
1041
  }
1031
- function le(t, e, r) {
1042
+ function Ie(t, e, r) {
1032
1043
  return `HAVING
1033
1044
  ${E(t, e, 1, r)}`;
1034
1045
  }
1035
- function $e(t, e, r, n) {
1046
+ function Ce(t, e, r, n) {
1036
1047
  return `ORDER BY
1037
- ${t.map((i) => p(i, () => `${E(n(i.expression), e, 1, r)} ${i.direction === "desc" ? "DESC" : "ASC"}`)).join(`,
1048
+ ${t.map((o) => T(o, () => `${E(n(o.expression), e, 1, r)} ${o.direction === "desc" ? "DESC" : "ASC"}`)).join(`,
1038
1049
  `)}`;
1039
1050
  }
1040
- const H = (t) => t !== void 0 && Number.isInteger(t) && t >= 0 ? t : void 0;
1041
- function At(t, e) {
1042
- const r = e.resolveName ? zt(t, e.resolveName) : t;
1043
- return e.defaultLimit !== void 0 && H(r.limit) === void 0 ? { ...r, limit: e.defaultLimit } : r;
1051
+ const J = (t) => t !== void 0 && Number.isInteger(t) && t >= 0 ? t : void 0;
1052
+ function Mt(t, e) {
1053
+ const r = e.resolveName ? ye(t, e.resolveName) : t;
1054
+ return e.defaultLimit !== void 0 && J(r.limit) === void 0 ? { ...r, limit: e.defaultLimit } : r;
1044
1055
  }
1045
- const Ee = "18446744073709551615";
1046
- function P(t, e, r, n = `SELECT${t.distinct ? " DISTINCT" : ""}`) {
1056
+ const we = "18446744073709551615";
1057
+ function z(t, e, r, n = `SELECT${t.distinct ? " DISTINCT" : ""}`) {
1047
1058
  const s = [
1048
- ce(t.select, e, r, n),
1049
- Tt(t.from, e, r),
1050
- ...t.joins.map((a) => pt(a, e, r))
1059
+ be(t.select, e, r, n),
1060
+ wt(t.from, e, r),
1061
+ ...t.joins.map((a) => Lt(a, e, r))
1051
1062
  ];
1052
- t.where && s.push(lt(t.where, e, r));
1053
- const i = t.groupBy ?? [];
1054
- if (i.length > 0 && s.push(fe(i, e, r)), t.having) {
1055
- const a = e === "mysql" ? z(t.having, t) : t.having;
1056
- s.push(le(a, e, r));
1063
+ t.where && s.push(bt(t.where, e, r));
1064
+ const o = t.groupBy ?? [];
1065
+ if (o.length > 0 && s.push(Re(o, e, r)), t.having) {
1066
+ const a = e === "mysql" ? $t(t.having, t) : t.having;
1067
+ s.push(Ie(a, e, r));
1057
1068
  }
1058
1069
  return s;
1059
1070
  }
1060
- function mt(t, e, r) {
1061
- O && (O.writing = [{ value: t, path: [] }]), $t = new Map((t.shared ?? []).map((f) => [f.id, f.name]));
1062
- const n = ue(t.shared ?? [], e, r), s = H(t.limit), i = H(t.offset) || void 0, a = t.orderBy ?? [], o = e === "mssql" && s !== void 0 && i === void 0, c = `SELECT${t.distinct ? " DISTINCT" : ""}${o ? ` ${p("limit", () => `TOP (${s})`)}` : ""}`, u = P(t, e, r, c);
1063
- if (a.length > 0 && u.push($e(a, e, r, (f) => e === "mysql" ? z(f, t) : f)), e === "mssql") {
1064
- if (i !== void 0) {
1071
+ function dt(t, e, r) {
1072
+ I && (I.writing = [{ value: t, path: [] }]), Rt = new Map((t.shared ?? []).map((f) => [f.id, f.name]));
1073
+ const n = Se(t.shared ?? [], e, r), s = J(t.limit), o = J(t.offset) || void 0, a = t.orderBy ?? [], i = e === "mssql" && s !== void 0 && o === void 0, c = `SELECT${t.distinct ? " DISTINCT" : ""}${i ? ` ${T("limit", () => `TOP (${s})`)}` : ""}`, u = z(t, e, r, c);
1074
+ if (a.length > 0 && u.push(Ce(a, e, r, (f) => e === "mysql" ? $t(f, t) : f)), e === "mssql") {
1075
+ if (o !== void 0) {
1065
1076
  a.length === 0 && u.push("ORDER BY (SELECT NULL)");
1066
- const f = s !== void 0 ? ` ${p("limit", () => `FETCH NEXT ${s} ROWS ONLY`)}` : "";
1067
- u.push(`${p("offset", () => `OFFSET ${i} ROWS`)}${f}`);
1077
+ const f = s !== void 0 ? ` ${T("limit", () => `FETCH NEXT ${s} ROWS ONLY`)}` : "";
1078
+ u.push(`${T("offset", () => `OFFSET ${o} ROWS`)}${f}`);
1068
1079
  }
1069
- } else if (s !== void 0 || i !== void 0) {
1070
- const f = s !== void 0 || e === "mysql" ? p(s !== void 0 ? "limit" : {}, () => `LIMIT ${s ?? Ee}`) : "", l = i !== void 0 ? p("offset", () => `OFFSET ${i}`) : "";
1080
+ } else if (s !== void 0 || o !== void 0) {
1081
+ const f = s !== void 0 || e === "mysql" ? T(s !== void 0 ? "limit" : {}, () => `LIMIT ${s ?? we}`) : "", l = o !== void 0 ? T("offset", () => `OFFSET ${o}`) : "";
1071
1082
  u.push([f, l].filter(Boolean).join(" "));
1072
1083
  }
1073
1084
  return [...n, ...u].join(`
1074
1085
  `);
1075
1086
  }
1076
- function ve(t, e, r = {}) {
1077
- const n = r.values ? vt(t, r.values) : t, s = r.schema ? at(n, r.schema).query : n;
1078
- return mt(At(s, r), e);
1087
+ function Ze(t, e, r = {}) {
1088
+ const n = r.values ? Kt(t, r.values) : t, s = r.schema ? Ot(n, r.schema).query : n;
1089
+ return dt(Mt(s, r), e);
1079
1090
  }
1080
- function ye(t, e) {
1091
+ function Le(t, e) {
1081
1092
  switch (t) {
1082
1093
  case "mysql":
1083
1094
  return "?";
@@ -1089,42 +1100,42 @@ function ye(t, e) {
1089
1100
  return "?";
1090
1101
  }
1091
1102
  }
1092
- function Be(t, e, r = {}) {
1093
- const n = r.schema ? at(t, r.schema) : { query: t, params: /* @__PURE__ */ new Map() }, s = {
1103
+ function tr(t, e, r = {}) {
1104
+ const n = r.schema ? Ot(t, r.schema) : { query: t, params: /* @__PURE__ */ new Map() }, s = {
1094
1105
  values: [],
1095
1106
  named: new Map(Object.entries(r.values ?? {}).map(([u, f]) => {
1096
1107
  const l = n.params.get(u);
1097
- return [u, l ? ot(f, l) : f];
1108
+ return [u, l ? ht(f, l) : f];
1098
1109
  }))
1099
- }, i = At(n.query, r), a = mt(i, e, s), o = [];
1100
- return { sql: a.replace(ee, (u, f) => {
1110
+ }, o = Mt(n.query, r), a = dt(o, e, s), i = [];
1111
+ return { sql: a.replace(Ae, (u, f) => {
1101
1112
  const l = s.values[Number(f)];
1102
- return o.push(l instanceof Date ? Z(l) : l), ye(e, o.length);
1103
- }), params: o };
1113
+ return i.push(l instanceof Date ? Et(l) : l), Le(e, i.length);
1114
+ }), params: i };
1104
1115
  }
1105
1116
  export {
1106
- qe as D,
1107
- B as Q,
1108
- jt as S,
1109
- Be as a,
1110
- ve as b,
1111
- Pt as c,
1112
- be as d,
1113
- Oe as e,
1114
- Ie as f,
1115
- Se as g,
1116
- X as h,
1117
- Me as i,
1118
- De as j,
1119
- Le as k,
1120
- Re as l,
1121
- Ce as m,
1122
- S as n,
1123
- Fe as o,
1124
- we as p,
1125
- Ue as q,
1126
- Ne as r,
1127
- ge as s,
1128
- he as u,
1129
- de as w
1117
+ Je as D,
1118
+ X as Q,
1119
+ Zt as S,
1120
+ tr as a,
1121
+ Ze as b,
1122
+ se as c,
1123
+ Pe as d,
1124
+ _e as e,
1125
+ xe as f,
1126
+ Ye as g,
1127
+ at as h,
1128
+ Xe as i,
1129
+ je as j,
1130
+ Qe as k,
1131
+ Ge as l,
1132
+ ke as m,
1133
+ w as n,
1134
+ We as o,
1135
+ Ve as p,
1136
+ Ke as q,
1137
+ He as r,
1138
+ ve as s,
1139
+ Be as u,
1140
+ ze as w
1130
1141
  };