sumak 0.0.4 → 0.0.6

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.
Files changed (121) hide show
  1. package/README.md +409 -5
  2. package/dist/ast/expression.d.mts +26 -0
  3. package/dist/ast/expression.mjs +140 -0
  4. package/dist/ast/nodes.d.mts +309 -0
  5. package/dist/ast/nodes.mjs +59 -0
  6. package/dist/ast/transformer.d.mts +10 -0
  7. package/dist/ast/transformer.mjs +140 -0
  8. package/dist/ast/typed-expression.d.mts +37 -0
  9. package/dist/ast/typed-expression.mjs +77 -0
  10. package/dist/ast/visitor.d.mts +13 -0
  11. package/dist/ast/visitor.mjs +11 -0
  12. package/dist/builder/delete.d.mts +20 -0
  13. package/dist/builder/delete.mjs +113 -0
  14. package/dist/builder/eb.d.mts +312 -0
  15. package/dist/builder/eb.mjs +641 -0
  16. package/dist/builder/expression.d.mts +5 -0
  17. package/dist/builder/expression.mjs +10 -0
  18. package/dist/builder/insert.d.mts +40 -0
  19. package/dist/builder/insert.mjs +146 -0
  20. package/dist/builder/merge.d.mts +20 -0
  21. package/dist/builder/merge.mjs +100 -0
  22. package/dist/builder/raw.d.mts +2 -0
  23. package/dist/builder/raw.mjs +4 -0
  24. package/dist/builder/select.d.mts +41 -0
  25. package/dist/builder/select.mjs +280 -0
  26. package/dist/builder/typed-delete.d.mts +49 -0
  27. package/dist/builder/typed-delete.mjs +89 -0
  28. package/dist/builder/typed-insert.d.mts +86 -0
  29. package/dist/builder/typed-insert.mjs +159 -0
  30. package/dist/builder/typed-merge.d.mts +31 -0
  31. package/dist/builder/typed-merge.mjs +93 -0
  32. package/dist/builder/typed-select.d.mts +164 -0
  33. package/dist/builder/typed-select.mjs +309 -0
  34. package/dist/builder/typed-update.d.mts +59 -0
  35. package/dist/builder/typed-update.mjs +110 -0
  36. package/dist/builder/update.d.mts +20 -0
  37. package/dist/builder/update.mjs +121 -0
  38. package/dist/dialect/mssql.d.mts +2 -0
  39. package/dist/dialect/mssql.mjs +9 -0
  40. package/dist/dialect/mysql.d.mts +2 -0
  41. package/dist/dialect/mysql.mjs +9 -0
  42. package/dist/dialect/pg.d.mts +2 -0
  43. package/dist/dialect/pg.mjs +9 -0
  44. package/dist/dialect/sqlite.d.mts +2 -0
  45. package/dist/dialect/sqlite.mjs +9 -0
  46. package/dist/dialect/types.d.mts +6 -0
  47. package/dist/dialect/types.mjs +1 -0
  48. package/dist/errors.d.mts +12 -0
  49. package/dist/errors.mjs +24 -0
  50. package/dist/index.d.mts +50 -806
  51. package/dist/index.mjs +48 -3
  52. package/dist/mssql.d.mts +2 -2
  53. package/dist/mssql.mjs +2 -1
  54. package/dist/mysql.d.mts +2 -2
  55. package/dist/mysql.mjs +2 -1
  56. package/dist/pg.d.mts +2 -2
  57. package/dist/pg.mjs +2 -1
  58. package/dist/plugin/camel-case.d.mts +11 -0
  59. package/dist/plugin/camel-case.mjs +16 -0
  60. package/dist/plugin/hooks.d.mts +72 -0
  61. package/dist/plugin/hooks.mjs +49 -0
  62. package/dist/plugin/plugin-manager.d.mts +17 -0
  63. package/dist/plugin/plugin-manager.mjs +37 -0
  64. package/dist/plugin/soft-delete.d.mts +27 -0
  65. package/dist/plugin/soft-delete.mjs +52 -0
  66. package/dist/plugin/types.d.mts +19 -0
  67. package/dist/plugin/types.mjs +1 -0
  68. package/dist/plugin/with-schema.d.mts +21 -0
  69. package/dist/plugin/with-schema.mjs +53 -0
  70. package/dist/printer/base.d.mts +49 -0
  71. package/dist/printer/base.mjs +472 -0
  72. package/dist/printer/document.d.mts +45 -0
  73. package/dist/printer/document.mjs +153 -0
  74. package/dist/printer/formatter.d.mts +5 -0
  75. package/dist/printer/formatter.mjs +134 -0
  76. package/dist/printer/mssql.d.mts +10 -0
  77. package/dist/printer/mssql.mjs +161 -0
  78. package/dist/printer/mysql.d.mts +8 -0
  79. package/dist/printer/mysql.mjs +41 -0
  80. package/dist/printer/pg.d.mts +6 -0
  81. package/dist/printer/pg.mjs +9 -0
  82. package/dist/printer/sqlite.d.mts +8 -0
  83. package/dist/printer/sqlite.mjs +29 -0
  84. package/dist/printer/types.d.mts +11 -0
  85. package/dist/printer/types.mjs +1 -0
  86. package/dist/schema/column.d.mts +52 -0
  87. package/dist/schema/column.mjs +120 -0
  88. package/dist/schema/index.d.mts +6 -0
  89. package/dist/schema/index.mjs +4 -0
  90. package/dist/schema/table.d.mts +37 -0
  91. package/dist/schema/table.mjs +7 -0
  92. package/dist/schema/type-utils.d.mts +46 -0
  93. package/dist/schema/type-utils.mjs +1 -0
  94. package/dist/schema/types.d.mts +64 -0
  95. package/dist/schema/types.mjs +1 -0
  96. package/dist/schema.d.mts +2 -2
  97. package/dist/schema.mjs +1 -1
  98. package/dist/sqlite.d.mts +2 -2
  99. package/dist/sqlite.mjs +2 -1
  100. package/dist/sumak.d.mts +110 -0
  101. package/dist/sumak.mjs +141 -0
  102. package/dist/types.d.mts +14 -0
  103. package/dist/types.mjs +1 -0
  104. package/dist/utils/identifier.d.mts +3 -0
  105. package/dist/utils/identifier.mjs +14 -0
  106. package/dist/utils/param.d.mts +2 -0
  107. package/dist/utils/param.mjs +8 -0
  108. package/package.json +1 -1
  109. package/dist/_chunks/base.mjs +0 -1
  110. package/dist/_chunks/errors.mjs +0 -1
  111. package/dist/_chunks/index.d.mts +0 -136
  112. package/dist/_chunks/mssql.d.mts +0 -11
  113. package/dist/_chunks/mssql.mjs +0 -1
  114. package/dist/_chunks/mysql.d.mts +0 -9
  115. package/dist/_chunks/mysql.mjs +0 -1
  116. package/dist/_chunks/pg.d.mts +0 -7
  117. package/dist/_chunks/pg.mjs +0 -1
  118. package/dist/_chunks/schema.mjs +0 -1
  119. package/dist/_chunks/sqlite.d.mts +0 -9
  120. package/dist/_chunks/sqlite.mjs +0 -1
  121. package/dist/_chunks/types.d.mts +0 -338
@@ -0,0 +1,641 @@
1
+ import { col as rawCol, lit as rawLit, param as rawParam, and as rawAnd, or as rawOr, fn as rawFn, star as rawStar, exists as rawExists, cast as rawCast, not as rawNot } from "../ast/expression.mjs";
2
+
3
+ export class Col {
4
+
5
+ _node;
6
+ constructor(column, table) {
7
+ this._node = rawCol(column, table);
8
+ }
9
+
10
+ eq(value) {
11
+ return wrap(binOp("=", this._node, autoParam(value)));
12
+ }
13
+
14
+ neq(value) {
15
+ return wrap(binOp("!=", this._node, autoParam(value)));
16
+ }
17
+
18
+ gt(value) {
19
+ return wrap(binOp(">", this._node, autoParam(value)));
20
+ }
21
+
22
+ gte(value) {
23
+ return wrap(binOp(">=", this._node, autoParam(value)));
24
+ }
25
+
26
+ lt(value) {
27
+ return wrap(binOp("<", this._node, autoParam(value)));
28
+ }
29
+
30
+ lte(value) {
31
+ return wrap(binOp("<=", this._node, autoParam(value)));
32
+ }
33
+
34
+ like(pattern) {
35
+ return wrap(binOp("LIKE", this._node, rawLit(pattern)));
36
+ }
37
+
38
+ notLike(pattern) {
39
+ return wrap(binOp("NOT LIKE", this._node, rawLit(pattern)));
40
+ }
41
+
42
+ ilike(pattern) {
43
+ return wrap(binOp("ILIKE", this._node, rawLit(pattern)));
44
+ }
45
+
46
+ notIlike(pattern) {
47
+ return wrap(binOp("NOT ILIKE", this._node, rawLit(pattern)));
48
+ }
49
+
50
+ in(values) {
51
+ return wrap({
52
+ type: "in",
53
+ expr: this._node,
54
+ values: values.map((v) => autoParam(v)),
55
+ negated: false
56
+ });
57
+ }
58
+
59
+ notIn(values) {
60
+ return wrap({
61
+ type: "in",
62
+ expr: this._node,
63
+ values: values.map((v) => autoParam(v)),
64
+ negated: true
65
+ });
66
+ }
67
+
68
+ isNull() {
69
+ return wrap({
70
+ type: "is_null",
71
+ expr: this._node,
72
+ negated: false
73
+ });
74
+ }
75
+
76
+ isNotNull() {
77
+ return wrap({
78
+ type: "is_null",
79
+ expr: this._node,
80
+ negated: true
81
+ });
82
+ }
83
+
84
+ between(low, high) {
85
+ return wrap({
86
+ type: "between",
87
+ expr: this._node,
88
+ low: autoParam(low),
89
+ high: autoParam(high),
90
+ negated: false
91
+ });
92
+ }
93
+
94
+ notBetween(low, high) {
95
+ return wrap({
96
+ type: "between",
97
+ expr: this._node,
98
+ low: autoParam(low),
99
+ high: autoParam(high),
100
+ negated: true
101
+ });
102
+ }
103
+
104
+ betweenSymmetric(low, high) {
105
+ return wrap({
106
+ type: "between",
107
+ expr: this._node,
108
+ low: autoParam(low),
109
+ high: autoParam(high),
110
+ negated: false,
111
+ symmetric: true
112
+ });
113
+ }
114
+
115
+ inSubquery(query) {
116
+ return wrap({
117
+ type: "in",
118
+ expr: this._node,
119
+ values: query,
120
+ negated: false
121
+ });
122
+ }
123
+
124
+ notInSubquery(query) {
125
+ return wrap({
126
+ type: "in",
127
+ expr: this._node,
128
+ values: query,
129
+ negated: true
130
+ });
131
+ }
132
+
133
+ eqExpr(value) {
134
+ return wrap(binOp("=", this._node, value.node));
135
+ }
136
+
137
+ neqExpr(value) {
138
+ return wrap(binOp("!=", this._node, value.node));
139
+ }
140
+
141
+ gtExpr(value) {
142
+ return wrap(binOp(">", this._node, value.node));
143
+ }
144
+
145
+ gteExpr(value) {
146
+ return wrap(binOp(">=", this._node, value.node));
147
+ }
148
+
149
+ ltExpr(value) {
150
+ return wrap(binOp("<", this._node, value.node));
151
+ }
152
+
153
+ lteExpr(value) {
154
+ return wrap(binOp("<=", this._node, value.node));
155
+ }
156
+
157
+ isDistinctFrom(value) {
158
+ return wrap(binOp("IS DISTINCT FROM", this._node, autoParam(value)));
159
+ }
160
+
161
+ isNotDistinctFrom(value) {
162
+ return wrap(binOp("IS NOT DISTINCT FROM", this._node, autoParam(value)));
163
+ }
164
+
165
+ eqCol(other) {
166
+ return wrap(binOp("=", this._node, other._node));
167
+ }
168
+
169
+ neqCol(other) {
170
+ return wrap(binOp("!=", this._node, other._node));
171
+ }
172
+
173
+ gtCol(other) {
174
+ return wrap(binOp(">", this._node, other._node));
175
+ }
176
+
177
+ ltCol(other) {
178
+ return wrap(binOp("<", this._node, other._node));
179
+ }
180
+
181
+ gteCol(other) {
182
+ return wrap(binOp(">=", this._node, other._node));
183
+ }
184
+
185
+ lteCol(other) {
186
+ return wrap(binOp("<=", this._node, other._node));
187
+ }
188
+
189
+ toExpr() {
190
+ return wrap(this._node);
191
+ }
192
+ }
193
+
194
+ let _paramIdx = 0;
195
+ export function resetParams() {
196
+ _paramIdx = 0;
197
+ }
198
+ function autoParam(value) {
199
+ return rawParam(_paramIdx++, value);
200
+ }
201
+ function binOp(op, left, right) {
202
+ return {
203
+ type: "binary_op",
204
+ op,
205
+ left,
206
+ right
207
+ };
208
+ }
209
+ function wrap(node) {
210
+ return { node };
211
+ }
212
+
213
+ export function createColumnProxies(_table) {
214
+ return new Proxy({}, { get(_target, prop) {
215
+ return new Col(prop, undefined);
216
+ } });
217
+ }
218
+
219
+
220
+ export function and(...exprs) {
221
+ if (exprs.length === 0) return wrap(rawLit(true));
222
+ if (exprs.length === 1) return exprs[0];
223
+ return exprs.reduce((acc, expr) => wrap(rawAnd(acc.node, expr.node)));
224
+ }
225
+
226
+ export function or(...exprs) {
227
+ if (exprs.length === 0) return wrap(rawLit(false));
228
+ if (exprs.length === 1) return exprs[0];
229
+ return exprs.reduce((acc, expr) => wrap(rawOr(acc.node, expr.node)));
230
+ }
231
+
232
+ export function val(value) {
233
+ return wrap(rawLit(value));
234
+ }
235
+
236
+ export function rawExpr(sql, params = []) {
237
+ return wrap({
238
+ type: "raw",
239
+ sql,
240
+ params
241
+ });
242
+ }
243
+
244
+ export function sqlFn(name, ...args) {
245
+ return wrap(rawFn(name, args.map((a) => a.node)));
246
+ }
247
+
248
+ export function count() {
249
+ return wrap(rawFn("COUNT", [rawStar()]));
250
+ }
251
+
252
+ export function countDistinct(expr) {
253
+ const node = {
254
+ type: "function_call",
255
+ name: "COUNT",
256
+ args: [expr.node],
257
+ distinct: true
258
+ };
259
+ return wrap(node);
260
+ }
261
+
262
+ export function sum(expr) {
263
+ return wrap(rawFn("SUM", [expr.node]));
264
+ }
265
+
266
+ export function sumDistinct(expr) {
267
+ const node = {
268
+ type: "function_call",
269
+ name: "SUM",
270
+ args: [expr.node],
271
+ distinct: true
272
+ };
273
+ return wrap(node);
274
+ }
275
+
276
+ export function avg(expr) {
277
+ return wrap(rawFn("AVG", [expr.node]));
278
+ }
279
+
280
+ export function avgDistinct(expr) {
281
+ const node = {
282
+ type: "function_call",
283
+ name: "AVG",
284
+ args: [expr.node],
285
+ distinct: true
286
+ };
287
+ return wrap(node);
288
+ }
289
+
290
+ export function min(expr) {
291
+ return wrap(rawFn("MIN", [expr.node]));
292
+ }
293
+
294
+ export function max(expr) {
295
+ return wrap(rawFn("MAX", [expr.node]));
296
+ }
297
+
298
+ export function coalesce(...args) {
299
+ return wrap(rawFn("COALESCE", args.map((a) => a.node)));
300
+ }
301
+
302
+ export function not(expr) {
303
+ return wrap(rawNot(expr.node));
304
+ }
305
+
306
+ export function add(a, b) {
307
+ return wrap(binOp("+", a.node, b.node));
308
+ }
309
+
310
+ export function sub(a, b) {
311
+ return wrap(binOp("-", a.node, b.node));
312
+ }
313
+
314
+ export function mul(a, b) {
315
+ return wrap(binOp("*", a.node, b.node));
316
+ }
317
+
318
+ export function div(a, b) {
319
+ return wrap(binOp("/", a.node, b.node));
320
+ }
321
+
322
+ export function mod(a, b) {
323
+ return wrap(binOp("%", a.node, b.node));
324
+ }
325
+
326
+ export function neg(expr) {
327
+ return wrap({
328
+ type: "unary_op",
329
+ op: "-",
330
+ operand: expr.node,
331
+ position: "prefix"
332
+ });
333
+ }
334
+
335
+ export function exists(query) {
336
+ return wrap(rawExists(query));
337
+ }
338
+
339
+ export function notExists(query) {
340
+ return wrap(rawExists(query, true));
341
+ }
342
+
343
+ export function cast(expr, dataType) {
344
+ return wrap(rawCast(expr.node, dataType));
345
+ }
346
+
347
+ export function jsonRef(expr, path, operator = "->") {
348
+ const node = {
349
+ type: "json_access",
350
+ expr: expr.node,
351
+ path,
352
+ operator
353
+ };
354
+ return wrap(node);
355
+ }
356
+
357
+ export function textSearch(columns, query, options) {
358
+ const node = {
359
+ type: "full_text_search",
360
+ columns: columns.map((c) => c.node),
361
+ query: query.node,
362
+ mode: options?.mode,
363
+ language: options?.language
364
+ };
365
+ return wrap(node);
366
+ }
367
+
368
+ export function case_(operand) {
369
+ return new CaseBuilder(operand ? operand.node : undefined, []);
370
+ }
371
+ export class CaseBuilder {
372
+
373
+ _operand;
374
+
375
+ _whens;
376
+
377
+ _else;
378
+
379
+ constructor(operand, whens, else_) {
380
+ this._operand = operand;
381
+ this._whens = whens;
382
+ this._else = else_;
383
+ }
384
+ when(condition, result) {
385
+ return new CaseBuilder(this._operand, [...this._whens, {
386
+ condition: condition.node,
387
+ result: result.node
388
+ }]);
389
+ }
390
+ else_(result) {
391
+ return new CaseBuilder(this._operand, this._whens, result.node);
392
+ }
393
+ end() {
394
+ const node = {
395
+ type: "case",
396
+ operand: this._operand,
397
+ whens: this._whens,
398
+ else_: this._else
399
+ };
400
+ return wrap(node);
401
+ }
402
+ }
403
+
404
+
405
+ export function over(fn, build) {
406
+ const builder = build(new WindowBuilder());
407
+ const fnNode = fn.node;
408
+ const node = {
409
+ type: "window_function",
410
+ fn: fnNode,
411
+ partitionBy: builder._partitionBy,
412
+ orderBy: builder._orderBy,
413
+ frame: builder._frame
414
+ };
415
+ return wrap(node);
416
+ }
417
+ export class WindowBuilder {
418
+
419
+ _partitionBy = [];
420
+
421
+ _orderBy = [];
422
+
423
+ _frame;
424
+ partitionBy(...columns) {
425
+ const b = new WindowBuilder();
426
+ b._partitionBy = columns.map((c) => rawCol(c));
427
+ b._orderBy = this._orderBy;
428
+ b._frame = this._frame;
429
+ return b;
430
+ }
431
+ orderBy(column, direction = "ASC") {
432
+ const b = new WindowBuilder();
433
+ b._partitionBy = this._partitionBy;
434
+ b._orderBy = [...this._orderBy, {
435
+ expr: rawCol(column),
436
+ direction
437
+ }];
438
+ b._frame = this._frame;
439
+ return b;
440
+ }
441
+ rows(start, end) {
442
+ return this._withFrame("ROWS", start, end);
443
+ }
444
+ range(start, end) {
445
+ return this._withFrame("RANGE", start, end);
446
+ }
447
+ groups(start, end) {
448
+ return this._withFrame("GROUPS", start, end);
449
+ }
450
+
451
+ _withFrame(kind, start, end) {
452
+ const b = new WindowBuilder();
453
+ b._partitionBy = this._partitionBy;
454
+ b._orderBy = this._orderBy;
455
+ b._frame = {
456
+ kind,
457
+ start,
458
+ end
459
+ };
460
+ return b;
461
+ }
462
+ }
463
+
464
+
465
+ export function rowNumber() {
466
+ return wrap(rawFn("ROW_NUMBER", []));
467
+ }
468
+
469
+ export function rank() {
470
+ return wrap(rawFn("RANK", []));
471
+ }
472
+
473
+ export function denseRank() {
474
+ return wrap(rawFn("DENSE_RANK", []));
475
+ }
476
+
477
+ export function lag(expr, offset, defaultValue) {
478
+ const args = [expr.node];
479
+ if (offset !== undefined) args.push(rawLit(offset));
480
+ if (defaultValue !== undefined) args.push(defaultValue.node);
481
+ return wrap(rawFn("LAG", args));
482
+ }
483
+
484
+ export function lead(expr, offset, defaultValue) {
485
+ const args = [expr.node];
486
+ if (offset !== undefined) args.push(rawLit(offset));
487
+ if (defaultValue !== undefined) args.push(defaultValue.node);
488
+ return wrap(rawFn("LEAD", args));
489
+ }
490
+
491
+ export function ntile(n) {
492
+ return wrap(rawFn("NTILE", [rawLit(n)]));
493
+ }
494
+
495
+
496
+ export function upper(expr) {
497
+ return wrap(rawFn("UPPER", [expr.node]));
498
+ }
499
+
500
+ export function lower(expr) {
501
+ return wrap(rawFn("LOWER", [expr.node]));
502
+ }
503
+
504
+ export function concat(...args) {
505
+ return wrap(rawFn("CONCAT", args.map((a) => a.node)));
506
+ }
507
+
508
+ export function substring(expr, start, length) {
509
+ const args = [expr.node, rawLit(start)];
510
+ if (length !== undefined) args.push(rawLit(length));
511
+ return wrap(rawFn("SUBSTRING", args));
512
+ }
513
+
514
+ export function trim(expr) {
515
+ return wrap(rawFn("TRIM", [expr.node]));
516
+ }
517
+
518
+ export function length(expr) {
519
+ return wrap(rawFn("LENGTH", [expr.node]));
520
+ }
521
+
522
+ export function now() {
523
+ return wrap(rawFn("NOW", []));
524
+ }
525
+
526
+ export function currentTimestamp() {
527
+ return wrap(rawFn("CURRENT_TIMESTAMP", []));
528
+ }
529
+
530
+ export function nullif(a, b) {
531
+ return wrap(rawFn("NULLIF", [a.node, b.node]));
532
+ }
533
+
534
+ export function greatest(...args) {
535
+ return wrap(rawFn("GREATEST", args.map((a) => a.node)));
536
+ }
537
+
538
+ export function least(...args) {
539
+ return wrap(rawFn("LEAST", args.map((a) => a.node)));
540
+ }
541
+
542
+ export function abs(expr) {
543
+ return wrap(rawFn("ABS", [expr.node]));
544
+ }
545
+
546
+ export function round(expr, precision) {
547
+ const args = [expr.node];
548
+ if (precision !== undefined) args.push(rawLit(precision));
549
+ return wrap(rawFn("ROUND", args));
550
+ }
551
+
552
+ export function ceil(expr) {
553
+ return wrap(rawFn("CEIL", [expr.node]));
554
+ }
555
+
556
+ export function jsonAgg(expr) {
557
+ return wrap(rawFn("JSON_AGG", [expr.node]));
558
+ }
559
+
560
+ export function toJson(expr) {
561
+ return wrap(rawFn("TO_JSON", [expr.node]));
562
+ }
563
+
564
+ export function jsonBuildObject(...pairs) {
565
+ const args = [];
566
+ for (const [key, val] of pairs) {
567
+ args.push(rawLit(key));
568
+ args.push(val.node);
569
+ }
570
+ return wrap(rawFn("JSON_BUILD_OBJECT", args));
571
+ }
572
+
573
+
574
+ export function arrayContains(arr, values) {
575
+ return wrap(binOp("@>", arr.node, values.node));
576
+ }
577
+
578
+ export function arrayContainedBy(arr, values) {
579
+ return wrap(binOp("<@", arr.node, values.node));
580
+ }
581
+
582
+ export function arrayOverlaps(arr, values) {
583
+ return wrap(binOp("&&", arr.node, values.node));
584
+ }
585
+
586
+ export function floor(expr) {
587
+ return wrap(rawFn("FLOOR", [expr.node]));
588
+ }
589
+
590
+ export function stringAgg(expr, delimiter, orderBy) {
591
+ const node = {
592
+ type: "function_call",
593
+ name: "STRING_AGG",
594
+ args: [expr.node, rawLit(delimiter)],
595
+ orderBy: orderBy?.map((o) => ({
596
+ expr: o.expr.node,
597
+ direction: o.direction ?? "ASC"
598
+ }))
599
+ };
600
+ return wrap(node);
601
+ }
602
+
603
+ export function arrayAgg(expr, orderBy) {
604
+ const node = {
605
+ type: "function_call",
606
+ name: "ARRAY_AGG",
607
+ args: [expr.node],
608
+ orderBy: orderBy?.map((o) => ({
609
+ expr: o.expr.node,
610
+ direction: o.direction ?? "ASC"
611
+ }))
612
+ };
613
+ return wrap(node);
614
+ }
615
+
616
+ export function aggOrderBy(agg, orderBy) {
617
+ const fnNode = agg.node;
618
+ return wrap({
619
+ ...fnNode,
620
+ orderBy: orderBy.map((o) => ({
621
+ expr: o.expr.node,
622
+ direction: o.direction ?? "ASC"
623
+ }))
624
+ });
625
+ }
626
+
627
+ export function tuple(...exprs) {
628
+ const node = {
629
+ type: "tuple",
630
+ elements: exprs.map((e) => e.node)
631
+ };
632
+ return wrap(node);
633
+ }
634
+
635
+ export function filter(agg, condition) {
636
+ const fnNode = agg.node;
637
+ return wrap({
638
+ ...fnNode,
639
+ filter: condition.node
640
+ });
641
+ }
@@ -0,0 +1,5 @@
1
+ import { and, between, binOp, col, eq, exists, gt, gte, inList, isNull, like, lit, lt, lte, neq, not, or } from "../ast/expression.mjs";
2
+ import type { ExpressionNode } from "../ast/nodes.mjs";
3
+ export declare function resetParamCounter(): void;
4
+ export declare function val(value: unknown): ExpressionNode;
5
+ export { and, between, binOp, col, eq, exists, gt, gte, inList, isNull, like, lit, lt, lte, neq, not, or };
@@ -0,0 +1,10 @@
1
+ import { and, between, binOp, col, eq, exists, gt, gte, inList, isNull, like, lit, lt, lte, neq, not, or, param } from "../ast/expression.mjs";
2
+ let paramCounter = 0;
3
+ export function resetParamCounter() {
4
+ paramCounter = 0;
5
+ }
6
+ export function val(value) {
7
+ const index = paramCounter++;
8
+ return param(index, value);
9
+ }
10
+ export { and, between, binOp, col, eq, exists, gt, gte, inList, isNull, like, lit, lt, lte, neq, not, or };
@@ -0,0 +1,40 @@
1
+ import type { ExpressionNode, InsertMode, InsertNode, SelectNode, TableRefNode } from "../ast/nodes.mjs";
2
+ export declare class InsertBuilder {
3
+ private node;
4
+ private paramIndex;
5
+ constructor(node?: InsertNode, paramIndex?: number);
6
+ into(table: string | TableRefNode): InsertBuilder;
7
+ columns(...cols: string[]): InsertBuilder;
8
+ values(...vals: unknown[]): InsertBuilder;
9
+ returning(...exprs: ExpressionNode[]): InsertBuilder;
10
+ onConflictDoNothing(...columns: string[]): InsertBuilder;
11
+ onConflictDoUpdate(columns: string[], set: {
12
+ column: string;
13
+ value: ExpressionNode;
14
+ }[], where?: ExpressionNode): InsertBuilder;
15
+ /** ON CONFLICT ON CONSTRAINT name DO NOTHING */
16
+ onConflictConstraintDoNothing(constraint: string): InsertBuilder;
17
+ /** ON CONFLICT ON CONSTRAINT name DO UPDATE SET ... */
18
+ onConflictConstraintDoUpdate(constraint: string, set: {
19
+ column: string;
20
+ value: ExpressionNode;
21
+ }[], where?: ExpressionNode): InsertBuilder;
22
+ /** Set insert mode (SQLite: INSERT OR IGNORE, INSERT OR REPLACE, etc.) */
23
+ mode(mode: InsertMode): InsertBuilder;
24
+ /** Shorthand: INSERT OR IGNORE (SQLite) */
25
+ orIgnore(): InsertBuilder;
26
+ /** Shorthand: INSERT OR REPLACE (SQLite) */
27
+ orReplace(): InsertBuilder;
28
+ /** MySQL: ON DUPLICATE KEY UPDATE */
29
+ onDuplicateKeyUpdate(set: {
30
+ column: string;
31
+ value: ExpressionNode;
32
+ }[]): InsertBuilder;
33
+ /** INSERT INTO ... SELECT ... */
34
+ fromSelect(query: SelectNode): InsertBuilder;
35
+ /** INSERT INTO ... DEFAULT VALUES */
36
+ defaultValues(): InsertBuilder;
37
+ with(name: string, query: SelectNode, recursive?: boolean): InsertBuilder;
38
+ build(): InsertNode;
39
+ }
40
+ export declare function insert(table: string | TableRefNode): InsertBuilder;