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