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