@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.
- 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-BRJV9MUQ.js → core-api-DzslKd1R.js} +437 -426
- 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,142 +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 c =
|
|
32
|
-
return c !==
|
|
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 c =
|
|
96
|
-
return
|
|
97
|
-
...
|
|
98
|
-
joins: [...
|
|
99
|
-
where: c ?
|
|
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 e = /* @__PURE__ */ new Map(), r = (n, s,
|
|
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 (!
|
|
110
|
-
let
|
|
111
|
-
|
|
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" ?
|
|
115
|
-
|
|
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
|
|
121
|
-
const n =
|
|
131
|
+
function ve(t, e, r) {
|
|
132
|
+
const n = ot(
|
|
122
133
|
t,
|
|
123
134
|
e,
|
|
124
135
|
r,
|
|
125
136
|
[],
|
|
126
|
-
|
|
127
|
-
), s =
|
|
128
|
-
return
|
|
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
|
|
131
|
-
if (!
|
|
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
|
|
135
|
-
const
|
|
136
|
-
(
|
|
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
|
|
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) ?
|
|
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:
|
|
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) =>
|
|
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:
|
|
231
|
-
query: { joins: [], ...e, select: [{ id:
|
|
241
|
+
id: nt(),
|
|
242
|
+
query: { joins: [], ...e, select: [{ id: nt(), expression: t }] }
|
|
232
243
|
})
|
|
233
244
|
};
|
|
234
|
-
function
|
|
245
|
+
function je(t, e, r) {
|
|
235
246
|
return A(t, e, { type: "setBaseTable", table: r });
|
|
236
247
|
}
|
|
237
|
-
function
|
|
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
|
|
252
|
+
function He(t, e, r) {
|
|
242
253
|
return A(t, e, { type: "removeJoin", joinId: r });
|
|
243
254
|
}
|
|
244
|
-
function
|
|
245
|
-
const s =
|
|
246
|
-
if (s &&
|
|
247
|
-
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))
|
|
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(
|
|
251
|
-
if (
|
|
252
|
-
throw new Error(`addCondition: "${
|
|
253
|
-
}), s.query.union.reduce((u, f, l) =>
|
|
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
|
-
[
|
|
256
|
-
($) =>
|
|
266
|
+
[Xt(s.id, l)],
|
|
267
|
+
($) => se(t, $, r, n)
|
|
257
268
|
), e);
|
|
258
269
|
}
|
|
259
|
-
const a = n.operator ?? "AND", { where:
|
|
270
|
+
const a = n.operator ?? "AND", { where: i } = e;
|
|
260
271
|
let c;
|
|
261
|
-
return
|
|
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
|
|
264
|
-
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, {
|
|
265
276
|
type: "setSelectExpression",
|
|
266
|
-
selectId:
|
|
277
|
+
selectId: o,
|
|
267
278
|
expression: r
|
|
268
|
-
}),
|
|
269
|
-
return
|
|
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
|
|
272
|
-
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, {
|
|
273
284
|
type: "setGroupByExpression",
|
|
274
285
|
groupById: s,
|
|
275
286
|
expression: r
|
|
276
287
|
});
|
|
277
|
-
return
|
|
288
|
+
return R(t, e, o);
|
|
278
289
|
}
|
|
279
|
-
function
|
|
280
|
-
return
|
|
290
|
+
function Ge(t, e, r) {
|
|
291
|
+
return R(t, e, Wt(t, e, r));
|
|
281
292
|
}
|
|
282
|
-
function
|
|
283
|
-
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, {
|
|
284
295
|
type: "setOrderByExpression",
|
|
285
|
-
orderById:
|
|
296
|
+
orderById: o,
|
|
286
297
|
expression: r
|
|
287
|
-
}),
|
|
298
|
+
}), i = A(t, a, {
|
|
288
299
|
type: "setOrderByDirection",
|
|
289
|
-
orderById:
|
|
300
|
+
orderById: o,
|
|
290
301
|
direction: n
|
|
291
302
|
});
|
|
292
|
-
return
|
|
303
|
+
return R(t, e, i);
|
|
293
304
|
}
|
|
294
|
-
function
|
|
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
|
|
309
|
+
function Qe(t, e, r) {
|
|
299
310
|
return A(t, e, { type: "setDistinct", distinct: r });
|
|
300
311
|
}
|
|
301
|
-
function
|
|
302
|
-
if (!
|
|
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
|
|
306
|
-
class
|
|
316
|
+
const X = 4;
|
|
317
|
+
class w extends Error {
|
|
307
318
|
constructor(r, n) {
|
|
308
319
|
super(n);
|
|
309
|
-
|
|
320
|
+
M(this, "kind");
|
|
310
321
|
this.name = "QueryFormatError", this.kind = r;
|
|
311
322
|
}
|
|
312
323
|
}
|
|
313
|
-
const
|
|
314
|
-
function
|
|
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
|
|
344
|
+
function ie(t) {
|
|
334
345
|
const e = (r) => {
|
|
335
346
|
if (Array.isArray(r)) return r.map(e);
|
|
336
|
-
if (!
|
|
337
|
-
const n = Object.fromEntries(Object.entries(r).map(([a,
|
|
338
|
-
if (n.type !== "binary" || n.operator !== "IN" || !
|
|
339
|
-
const
|
|
340
|
-
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 } };
|
|
341
352
|
};
|
|
342
353
|
return e(t);
|
|
343
354
|
}
|
|
344
|
-
const
|
|
345
|
-
function
|
|
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
|
|
349
|
-
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;
|
|
350
361
|
}
|
|
351
|
-
function
|
|
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
|
|
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
|
|
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
|
|
365
|
-
throw new
|
|
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
|
|
380
|
+
function Ve(t) {
|
|
370
381
|
return {
|
|
371
|
-
version:
|
|
372
|
-
query:
|
|
382
|
+
version: X,
|
|
383
|
+
query: _(t, le)
|
|
373
384
|
};
|
|
374
385
|
}
|
|
375
|
-
function
|
|
376
|
-
if (!
|
|
377
|
-
throw new
|
|
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
|
|
381
|
-
if (e >
|
|
382
|
-
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(
|
|
383
394
|
"newerVersion",
|
|
384
|
-
`stored in format ${e}; this version reads up to ${
|
|
395
|
+
`stored in format ${e}; this version reads up to ${X}`
|
|
385
396
|
);
|
|
386
|
-
const r =
|
|
387
|
-
if (!
|
|
388
|
-
throw new
|
|
389
|
-
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);
|
|
390
401
|
}
|
|
391
|
-
function
|
|
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:
|
|
394
|
-
if (
|
|
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(
|
|
399
|
-
r.set(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(
|
|
413
|
+
n.delete(o), s.delete(o);
|
|
403
414
|
}), { tableOf: r, aliases: n, derived: s };
|
|
404
415
|
}
|
|
405
|
-
function
|
|
406
|
-
const n = t.on &&
|
|
407
|
-
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) };
|
|
408
419
|
}
|
|
409
|
-
function
|
|
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:
|
|
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],
|
|
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:
|
|
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((
|
|
429
|
-
...n.where ? { where:
|
|
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
|
|
444
|
+
return K(t, (n) => F(n, e, r));
|
|
434
445
|
}
|
|
435
|
-
function
|
|
436
|
-
const r =
|
|
446
|
+
function Y(t, e) {
|
|
447
|
+
const r = V([t.from, ...t.joins]), n = lt(
|
|
437
448
|
t,
|
|
438
|
-
(s) =>
|
|
439
|
-
(s) =>
|
|
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
|
|
448
|
-
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));
|
|
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,
|
|
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
|
|
462
|
-
return
|
|
472
|
+
function ye(t, e) {
|
|
473
|
+
return Y(W(t, e), e);
|
|
463
474
|
}
|
|
464
|
-
const
|
|
465
|
-
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) {
|
|
466
477
|
let r;
|
|
467
|
-
const n = typeof t == "string" ?
|
|
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" ?
|
|
482
|
+
const a = typeof t == "string" ? Jt(t, "dateTime") : t;
|
|
472
483
|
a instanceof Date && (r = {
|
|
473
|
-
YYYY:
|
|
474
|
-
MM:
|
|
475
|
-
DD:
|
|
476
|
-
HH:
|
|
477
|
-
mm:
|
|
478
|
-
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())
|
|
479
490
|
});
|
|
480
491
|
}
|
|
481
492
|
if (!r) return t;
|
|
482
493
|
const s = r;
|
|
483
|
-
return (e.match(
|
|
494
|
+
return (e.match(ut) ?? []).some((a) => s[a] === void 0) ? t : e.replace(ut, (a) => s[a]);
|
|
484
495
|
}
|
|
485
|
-
function
|
|
496
|
+
function Ot(t, e) {
|
|
486
497
|
const r = /* @__PURE__ */ new Map(), n = (s) => {
|
|
487
|
-
const
|
|
488
|
-
|
|
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 =
|
|
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
|
-
},
|
|
504
|
+
}, i = (u, f) => {
|
|
494
505
|
switch (u.type) {
|
|
495
506
|
case "literal":
|
|
496
|
-
return { ...u, value:
|
|
507
|
+
return { ...u, value: ht(u.value, f) };
|
|
497
508
|
case "list":
|
|
498
|
-
return { ...u, items: u.items.map((l) =>
|
|
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 =
|
|
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: $ ?
|
|
512
|
-
right: l ?
|
|
522
|
+
left: $ ? i(f.left, $) : f.left,
|
|
523
|
+
right: l ? i(f.right, l) : f.right
|
|
513
524
|
};
|
|
514
525
|
};
|
|
515
|
-
return
|
|
526
|
+
return lt(s, c, (u) => n(u));
|
|
516
527
|
};
|
|
517
528
|
return { query: n(t), params: r };
|
|
518
529
|
}
|
|
519
|
-
const
|
|
530
|
+
const Je = ["mysql", "mssql", "postgres"], Ke = {
|
|
520
531
|
mysql: "MySQL",
|
|
521
532
|
mssql: "SQL Server",
|
|
522
533
|
postgres: "PostgreSQL"
|
|
523
534
|
};
|
|
524
|
-
function
|
|
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
|
|
538
|
-
let
|
|
539
|
-
function
|
|
540
|
-
|
|
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
|
-
|
|
555
|
+
I = void 0;
|
|
545
556
|
}
|
|
546
557
|
}
|
|
547
|
-
function
|
|
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,
|
|
561
|
+
return Object.entries(t).some(([s, o]) => {
|
|
551
562
|
const a = [...r, Array.isArray(t) ? Number(s) : s];
|
|
552
|
-
return n =
|
|
563
|
+
return n = o === e ? a : Nt(o, e, a), n !== void 0;
|
|
553
564
|
}), n;
|
|
554
565
|
}
|
|
555
|
-
function
|
|
556
|
-
if (!
|
|
557
|
-
const { writing: r, paths: n } =
|
|
558
|
-
if (!
|
|
559
|
-
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 });
|
|
560
571
|
try {
|
|
561
|
-
return `${n.push(
|
|
572
|
+
return `${n.push(o) - 1}${e()}`;
|
|
562
573
|
} finally {
|
|
563
574
|
r.pop();
|
|
564
575
|
}
|
|
565
576
|
}
|
|
566
|
-
const
|
|
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
|
|
606
|
+
function ge(t, e) {
|
|
596
607
|
var n;
|
|
597
|
-
const r = (n =
|
|
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
|
|
611
|
+
function St(t, e, r) {
|
|
601
612
|
if (t == null) return "NULL";
|
|
602
613
|
if (r)
|
|
603
|
-
return r.values.push(t),
|
|
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 =
|
|
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 ? `'${
|
|
621
|
+
return typeof t == "number" || typeof t == "bigint" ? String(t) : t instanceof Date ? `'${Et(t)}'` : String(t);
|
|
611
622
|
}
|
|
612
|
-
function
|
|
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
|
|
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
|
|
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
|
-
},
|
|
648
|
+
}, Oe = {
|
|
638
649
|
// ---- Date arithmetic ----
|
|
639
650
|
DATE_ADD: ([t, e], r, n, s) => {
|
|
640
651
|
var a;
|
|
641
|
-
const
|
|
652
|
+
const o = b(r[2]);
|
|
642
653
|
switch (n) {
|
|
643
654
|
case "mysql":
|
|
644
|
-
return
|
|
655
|
+
return o === "MILLISECOND" ? `DATE_ADD(${t}, INTERVAL (${e}) * 1000 MICROSECOND)` : `DATE_ADD(${t}, INTERVAL ${e} ${o})`;
|
|
645
656
|
case "postgres": {
|
|
646
|
-
const
|
|
647
|
-
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}'))`;
|
|
648
659
|
}
|
|
649
660
|
case "mssql":
|
|
650
|
-
return `DATEADD(${
|
|
661
|
+
return `DATEADD(${o}, ${e}, ${t})`;
|
|
651
662
|
default:
|
|
652
|
-
return `DATE_ADD(${t}, ${e}, ${
|
|
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
|
|
668
|
+
const o = b(r[2]);
|
|
658
669
|
switch (n) {
|
|
659
670
|
case "mysql":
|
|
660
|
-
return
|
|
671
|
+
return o === "MILLISECOND" ? `DATE_SUB(${t}, INTERVAL (${e}) * 1000 MICROSECOND)` : `DATE_SUB(${t}, INTERVAL ${e} ${o})`;
|
|
661
672
|
case "postgres": {
|
|
662
|
-
const
|
|
663
|
-
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}'))`;
|
|
664
675
|
}
|
|
665
676
|
case "mssql":
|
|
666
|
-
return `DATEADD(${
|
|
677
|
+
return `DATEADD(${o}, -(${e}), ${t})`;
|
|
667
678
|
default:
|
|
668
|
-
return `DATE_SUB(${t}, ${e}, ${
|
|
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 =
|
|
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
|
|
685
|
-
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`;
|
|
686
697
|
}
|
|
687
698
|
case "MONTH": {
|
|
688
|
-
const
|
|
689
|
-
return `(${
|
|
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 =
|
|
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 =
|
|
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('${
|
|
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,
|
|
797
|
-
const a = e[1] ?? { type: "literal", value: ", " },
|
|
798
|
-
var
|
|
799
|
-
return (
|
|
800
|
-
}, f = ($) =>
|
|
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 ${
|
|
814
|
+
return `GROUP_CONCAT(${c}${t}${l(u(f))} SEPARATOR ${i})`;
|
|
804
815
|
case "postgres": {
|
|
805
|
-
const $ = `CAST(${t} AS TEXT)`,
|
|
806
|
-
if (!s.distinct) return f(
|
|
807
|
-
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 $;
|
|
808
819
|
throw new Error("PostgreSQL orders STRING_AGG of different values by the value only");
|
|
809
820
|
});
|
|
810
|
-
return `STRING_AGG(${c}${$}, ${
|
|
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),
|
|
816
|
-
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}`;
|
|
817
828
|
}
|
|
818
829
|
default:
|
|
819
|
-
return `STRING_AGG(${c}${t}, ${
|
|
830
|
+
return `STRING_AGG(${c}${t}, ${i}${l(u(f))})`;
|
|
820
831
|
}
|
|
821
832
|
}
|
|
822
833
|
};
|
|
823
|
-
function
|
|
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
|
|
838
|
+
return T(t, () => De(t, e, r, n));
|
|
828
839
|
}
|
|
829
|
-
function
|
|
830
|
-
const s = (
|
|
831
|
-
if (!
|
|
832
|
-
const a = E(
|
|
833
|
-
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;
|
|
834
845
|
};
|
|
835
|
-
return
|
|
836
|
-
const [
|
|
837
|
-
return `${s(
|
|
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
|
|
851
|
+
function De(t, e, r, n) {
|
|
841
852
|
var a;
|
|
842
|
-
const s = " ".repeat(r),
|
|
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 ?
|
|
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
|
|
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)),
|
|
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
|
|
855
|
-
return t.table ? `${
|
|
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
|
|
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
|
-
|
|
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 (
|
|
870
|
-
const f = t.distinct &&
|
|
871
|
-
return `${u}(${f}${
|
|
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
|
|
875
|
-
if (
|
|
876
|
-
if (!t.right) return `${u} ${
|
|
877
|
-
if (
|
|
878
|
-
return `${u} BETWEEN ${
|
|
879
|
-
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")
|
|
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 =
|
|
882
|
-
return `${u} ${
|
|
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
|
|
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
|
-
${
|
|
905
|
+
${o}${u}
|
|
895
906
|
${s})`;
|
|
896
907
|
}
|
|
897
908
|
return E(c, e, r, n);
|
|
898
|
-
}).join(
|
|
909
|
+
}).join(i);
|
|
899
910
|
}
|
|
900
911
|
case "not": {
|
|
901
|
-
const { operand:
|
|
902
|
-
if (
|
|
903
|
-
const c = E(
|
|
904
|
-
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)})`;
|
|
905
916
|
}
|
|
906
|
-
if (
|
|
907
|
-
const c = E(
|
|
908
|
-
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)}`;
|
|
909
920
|
}
|
|
910
|
-
if (
|
|
911
|
-
const c = E(
|
|
921
|
+
if (i.type === "logical" || i.type === "not") {
|
|
922
|
+
const c = E(i, e, r + 1, n);
|
|
912
923
|
return `NOT (
|
|
913
|
-
${
|
|
924
|
+
${o}${c}
|
|
914
925
|
${s})`;
|
|
915
926
|
}
|
|
916
|
-
return `NOT ${E(
|
|
927
|
+
return `NOT ${E(i, e, r, n)}`;
|
|
917
928
|
}
|
|
918
929
|
case "if": {
|
|
919
|
-
const
|
|
920
|
-
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`;
|
|
921
932
|
}
|
|
922
933
|
case "case": {
|
|
923
|
-
const
|
|
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 `${
|
|
936
|
+
return `${o}WHEN ${l} THEN ${$}`;
|
|
926
937
|
}).join(`
|
|
927
938
|
`), u = t.else ? `
|
|
928
|
-
${
|
|
929
|
-
return `CASE${
|
|
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:
|
|
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
|
-
|
|
953
|
+
wt(i.from, e),
|
|
943
954
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
944
|
-
...
|
|
955
|
+
...i.joins.map(($) => Lt($, e, n)),
|
|
945
956
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
946
|
-
|
|
957
|
+
bt(f, e, n)
|
|
947
958
|
].join(`
|
|
948
|
-
`).replace(/^/gm,
|
|
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((
|
|
966
|
+
return `(${t.items.map((i) => E(i, e, r, n)).join(", ") || "??"})`;
|
|
956
967
|
case "subquery":
|
|
957
968
|
return `
|
|
958
|
-
${
|
|
959
|
-
`).replace(/^/gm,
|
|
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
|
|
976
|
+
function bt(t, e, r) {
|
|
966
977
|
return `WHERE
|
|
967
978
|
${E(t, e, 1, r)}`;
|
|
968
979
|
}
|
|
969
|
-
const
|
|
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
|
|
977
|
-
function
|
|
978
|
-
return t.shared !== void 0 ?
|
|
979
|
-
${
|
|
980
|
-
)` :
|
|
981
|
-
}
|
|
982
|
-
function
|
|
983
|
-
return
|
|
984
|
-
`)).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 ? `
|
|
985
996
|
UNION
|
|
986
997
|
` : `
|
|
987
998
|
UNION ALL
|
|
988
999
|
`);
|
|
989
1000
|
}
|
|
990
|
-
function
|
|
1001
|
+
function Se(t, e, r) {
|
|
991
1002
|
return t.length === 0 ? [] : [`WITH
|
|
992
|
-
${t.map((s) =>
|
|
993
|
-
const
|
|
994
|
-
return ` ${
|
|
995
|
-
${
|
|
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
|
|
1001
|
-
const n = t.alias ? ` AS ${
|
|
1002
|
-
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}`)}`;
|
|
1003
1014
|
}
|
|
1004
|
-
function
|
|
1005
|
-
return
|
|
1006
|
-
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)}` : "";
|
|
1007
1018
|
if (t.joinType === "cross") return `CROSS JOIN ${n}${s}`;
|
|
1008
|
-
const
|
|
1009
|
-
return `${
|
|
1010
|
-
ON ${
|
|
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
|
|
1014
|
-
if (t.length === 0) return `${n} ${
|
|
1015
|
-
const s = t.map((
|
|
1016
|
-
const a = E(
|
|
1017
|
-
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}`;
|
|
1018
1029
|
}));
|
|
1019
1030
|
return `${n}
|
|
1020
1031
|
${s.join(`,
|
|
1021
1032
|
`)}`;
|
|
1022
1033
|
}
|
|
1023
|
-
function
|
|
1034
|
+
function Re(t, e, r) {
|
|
1024
1035
|
return `GROUP BY
|
|
1025
|
-
${t.map((s) =>
|
|
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
|
|
1042
|
+
function Ie(t, e, r) {
|
|
1032
1043
|
return `HAVING
|
|
1033
1044
|
${E(t, e, 1, r)}`;
|
|
1034
1045
|
}
|
|
1035
|
-
function
|
|
1046
|
+
function Ce(t, e, r, n) {
|
|
1036
1047
|
return `ORDER BY
|
|
1037
|
-
${t.map((
|
|
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
|
|
1041
|
-
function
|
|
1042
|
-
const r = e.resolveName ?
|
|
1043
|
-
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;
|
|
1044
1055
|
}
|
|
1045
|
-
const
|
|
1046
|
-
function
|
|
1056
|
+
const we = "18446744073709551615";
|
|
1057
|
+
function z(t, e, r, n = `SELECT${t.distinct ? " DISTINCT" : ""}`) {
|
|
1047
1058
|
const s = [
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
...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))
|
|
1051
1062
|
];
|
|
1052
|
-
t.where && s.push(
|
|
1053
|
-
const
|
|
1054
|
-
if (
|
|
1055
|
-
const a = e === "mysql" ?
|
|
1056
|
-
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));
|
|
1057
1068
|
}
|
|
1058
1069
|
return s;
|
|
1059
1070
|
}
|
|
1060
|
-
function
|
|
1061
|
-
|
|
1062
|
-
const n =
|
|
1063
|
-
if (a.length > 0 && u.push(
|
|
1064
|
-
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) {
|
|
1065
1076
|
a.length === 0 && u.push("ORDER BY (SELECT NULL)");
|
|
1066
|
-
const f = s !== void 0 ? ` ${
|
|
1067
|
-
u.push(`${
|
|
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 ||
|
|
1070
|
-
const f = s !== void 0 || e === "mysql" ?
|
|
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
|
|
1077
|
-
const n = r.values ?
|
|
1078
|
-
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);
|
|
1079
1090
|
}
|
|
1080
|
-
function
|
|
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
|
|
1093
|
-
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 = {
|
|
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 ?
|
|
1108
|
+
return [u, l ? ht(f, l) : f];
|
|
1098
1109
|
}))
|
|
1099
|
-
},
|
|
1100
|
-
return { sql: a.replace(
|
|
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
|
|
1103
|
-
}), params:
|
|
1113
|
+
return i.push(l instanceof Date ? Et(l) : l), Le(e, i.length);
|
|
1114
|
+
}), params: i };
|
|
1104
1115
|
}
|
|
1105
1116
|
export {
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
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
|
};
|