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