rado 0.1.60 → 0.1.61
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/define/Expr.d.ts +69 -51
- package/dist/define/Expr.js +31 -31
- package/dist/lib/Formatter.d.ts +2 -1
- package/dist/lib/Formatter.js +61 -52
- package/package.json +1 -1
package/dist/define/Expr.d.ts
CHANGED
|
@@ -5,11 +5,11 @@ import { ParamData } from './Param';
|
|
|
5
5
|
import { Query } from './Query';
|
|
6
6
|
import { Selection } from './Selection';
|
|
7
7
|
import { Target } from './Target';
|
|
8
|
-
export declare enum
|
|
8
|
+
export declare enum UnOpType {
|
|
9
9
|
Not = "Not",
|
|
10
10
|
IsNull = "IsNull"
|
|
11
11
|
}
|
|
12
|
-
export declare enum
|
|
12
|
+
export declare enum BinOpType {
|
|
13
13
|
Add = "Add",
|
|
14
14
|
Subt = "Subt",
|
|
15
15
|
Mult = "Mult",
|
|
@@ -44,56 +44,74 @@ export declare enum ExprType {
|
|
|
44
44
|
Merge = "Merge",
|
|
45
45
|
Case = "Case"
|
|
46
46
|
}
|
|
47
|
-
export type ExprData =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
type
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
type
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
type
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
47
|
+
export type ExprData = ExprData.UnOp | ExprData.BinOp | ExprData.Field | ExprData.Param | ExprData.Call | ExprData.Query | ExprData.Record | ExprData.Merge | ExprData.Row | ExprData.Map | ExprData.Filter | ExprData.Case;
|
|
48
|
+
export declare namespace ExprData {
|
|
49
|
+
type UnOp = {
|
|
50
|
+
type: ExprType.UnOp;
|
|
51
|
+
op: UnOpType;
|
|
52
|
+
expr: ExprData;
|
|
53
|
+
};
|
|
54
|
+
type BinOp = {
|
|
55
|
+
type: ExprType.BinOp;
|
|
56
|
+
op: BinOpType;
|
|
57
|
+
a: ExprData;
|
|
58
|
+
b: ExprData;
|
|
59
|
+
};
|
|
60
|
+
type Field = {
|
|
61
|
+
type: ExprType.Field;
|
|
62
|
+
expr: ExprData;
|
|
63
|
+
field: string;
|
|
64
|
+
};
|
|
65
|
+
type Param = {
|
|
66
|
+
type: ExprType.Param;
|
|
67
|
+
param: ParamData;
|
|
68
|
+
};
|
|
69
|
+
type Call = {
|
|
70
|
+
type: ExprType.Call;
|
|
71
|
+
method: string;
|
|
72
|
+
params: Array<ExprData>;
|
|
73
|
+
};
|
|
74
|
+
type Query = {
|
|
75
|
+
type: ExprType.Query;
|
|
76
|
+
query: Query.Select;
|
|
77
|
+
};
|
|
78
|
+
type Record = {
|
|
79
|
+
type: ExprType.Record;
|
|
80
|
+
fields: {
|
|
81
|
+
[key: string]: ExprData;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
type Merge = {
|
|
85
|
+
type: ExprType.Merge;
|
|
86
|
+
a: ExprData;
|
|
87
|
+
b: ExprData;
|
|
88
|
+
};
|
|
89
|
+
type Row = {
|
|
90
|
+
type: ExprType.Row;
|
|
91
|
+
target: Target;
|
|
92
|
+
};
|
|
93
|
+
type Map = {
|
|
94
|
+
type: ExprType.Map;
|
|
95
|
+
target: Target;
|
|
96
|
+
result: ExprData;
|
|
97
|
+
};
|
|
98
|
+
type Filter = {
|
|
99
|
+
type: ExprType.Filter;
|
|
100
|
+
target: Target;
|
|
101
|
+
condition: ExprData;
|
|
102
|
+
};
|
|
103
|
+
type Case = {
|
|
104
|
+
type: ExprType.Case;
|
|
105
|
+
expr: ExprData;
|
|
106
|
+
cases: {
|
|
107
|
+
[key: string]: ExprData;
|
|
108
|
+
};
|
|
109
|
+
defaultCase?: ExprData;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
94
112
|
export declare const ExprData: {
|
|
95
|
-
UnOp(op:
|
|
96
|
-
BinOp(op:
|
|
113
|
+
UnOp(op: UnOpType, expr: ExprData): ExprData;
|
|
114
|
+
BinOp(op: BinOpType, a: ExprData, b: ExprData): ExprData;
|
|
97
115
|
Field(expr: ExprData, field: string): ExprData;
|
|
98
116
|
Param(param: ParamData): ExprData;
|
|
99
117
|
Call(method: string, params: Array<ExprData>): ExprData;
|
package/dist/define/Expr.js
CHANGED
|
@@ -9,33 +9,33 @@ var __publicField = (obj, key, value) => {
|
|
|
9
9
|
import { OrderDirection } from "./OrderBy.js";
|
|
10
10
|
import { ParamData, ParamType } from "./Param.js";
|
|
11
11
|
import { Target } from "./Target.js";
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
})(
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return
|
|
38
|
-
})(
|
|
12
|
+
var UnOpType = /* @__PURE__ */ ((UnOpType2) => {
|
|
13
|
+
UnOpType2["Not"] = "Not";
|
|
14
|
+
UnOpType2["IsNull"] = "IsNull";
|
|
15
|
+
return UnOpType2;
|
|
16
|
+
})(UnOpType || {});
|
|
17
|
+
var BinOpType = /* @__PURE__ */ ((BinOpType2) => {
|
|
18
|
+
BinOpType2["Add"] = "Add";
|
|
19
|
+
BinOpType2["Subt"] = "Subt";
|
|
20
|
+
BinOpType2["Mult"] = "Mult";
|
|
21
|
+
BinOpType2["Mod"] = "Mod";
|
|
22
|
+
BinOpType2["Div"] = "Div";
|
|
23
|
+
BinOpType2["Greater"] = "Greater";
|
|
24
|
+
BinOpType2["GreaterOrEqual"] = "GreaterOrEqual";
|
|
25
|
+
BinOpType2["Less"] = "Less";
|
|
26
|
+
BinOpType2["LessOrEqual"] = "LessOrEqual";
|
|
27
|
+
BinOpType2["Equals"] = "Equals";
|
|
28
|
+
BinOpType2["NotEquals"] = "NotEquals";
|
|
29
|
+
BinOpType2["And"] = "And";
|
|
30
|
+
BinOpType2["Or"] = "Or";
|
|
31
|
+
BinOpType2["Like"] = "Like";
|
|
32
|
+
BinOpType2["Glob"] = "Glob";
|
|
33
|
+
BinOpType2["Match"] = "Match";
|
|
34
|
+
BinOpType2["In"] = "In";
|
|
35
|
+
BinOpType2["NotIn"] = "NotIn";
|
|
36
|
+
BinOpType2["Concat"] = "Concat";
|
|
37
|
+
return BinOpType2;
|
|
38
|
+
})(BinOpType || {});
|
|
39
39
|
var ExprType = /* @__PURE__ */ ((ExprType2) => {
|
|
40
40
|
ExprType2["UnOp"] = "UnOp";
|
|
41
41
|
ExprType2["BinOp"] = "BinOp";
|
|
@@ -113,7 +113,7 @@ function isConstant(e, value) {
|
|
|
113
113
|
case "Param" /* Param */:
|
|
114
114
|
switch (e.param.type) {
|
|
115
115
|
case ParamType.Value:
|
|
116
|
-
return e.param.value
|
|
116
|
+
return e.param.value === value;
|
|
117
117
|
default:
|
|
118
118
|
return false;
|
|
119
119
|
}
|
|
@@ -178,7 +178,7 @@ var _Expr = class {
|
|
|
178
178
|
return this.isNull().not();
|
|
179
179
|
}
|
|
180
180
|
isNot(that) {
|
|
181
|
-
if (that
|
|
181
|
+
if (that === null || that instanceof _Expr && isConstant(that.expr, null))
|
|
182
182
|
return this.isNotNull();
|
|
183
183
|
return binop(this, "NotEquals" /* NotEquals */, that);
|
|
184
184
|
}
|
|
@@ -276,9 +276,9 @@ function binop(self, type, that) {
|
|
|
276
276
|
return new Expr(ExprData.BinOp(type, self.expr, toExpr(that)));
|
|
277
277
|
}
|
|
278
278
|
export {
|
|
279
|
-
|
|
279
|
+
BinOpType,
|
|
280
280
|
Expr,
|
|
281
281
|
ExprData,
|
|
282
282
|
ExprType,
|
|
283
|
-
|
|
283
|
+
UnOpType
|
|
284
284
|
};
|
package/dist/lib/Formatter.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export interface FormatContext {
|
|
|
20
20
|
forceInline?: boolean;
|
|
21
21
|
formatAsJson?: boolean;
|
|
22
22
|
formatAsInsert?: boolean;
|
|
23
|
+
formatAsIn?: boolean;
|
|
23
24
|
topLevel?: boolean;
|
|
24
25
|
}
|
|
25
26
|
type FormatSubject = (stmt: Statement, mkSubject: () => void) => void;
|
|
@@ -40,6 +41,7 @@ export declare abstract class Formatter implements Sanitizer {
|
|
|
40
41
|
forceInline?: boolean | undefined;
|
|
41
42
|
formatAsJson?: boolean | undefined;
|
|
42
43
|
formatAsInsert?: boolean | undefined;
|
|
44
|
+
formatAsIn?: boolean | undefined;
|
|
43
45
|
topLevel?: boolean | undefined;
|
|
44
46
|
skipNewlines?: boolean | undefined;
|
|
45
47
|
};
|
|
@@ -69,7 +71,6 @@ export declare abstract class Formatter implements Sanitizer {
|
|
|
69
71
|
formatSelection(ctx: FormatContext, selection: ExprData, formatSubject?: FormatSubject): Statement;
|
|
70
72
|
formatExprJson(ctx: FormatContext, expr: ExprData): Statement;
|
|
71
73
|
formatExprValue(ctx: FormatContext, expr: ExprData): Statement;
|
|
72
|
-
formatIn(ctx: FormatContext, expr: ExprData): Statement;
|
|
73
74
|
retrieveField(expr: ExprData, field: string): ExprData | undefined;
|
|
74
75
|
formatField(ctx: FormatContext, expr: ExprData, field: string): Statement;
|
|
75
76
|
formatString(ctx: FormatContext, input: string): Statement;
|
package/dist/lib/Formatter.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
// src/lib/Formatter.ts
|
|
2
2
|
import { ColumnType } from "../define/Column.js";
|
|
3
|
-
import {
|
|
3
|
+
import { BinOpType, Expr, ExprData, ExprType, UnOpType } from "../define/Expr.js";
|
|
4
4
|
import { OrderDirection } from "../define/OrderBy.js";
|
|
5
5
|
import { ParamType } from "../define/Param.js";
|
|
6
6
|
import { Query, QueryType } from "../define/Query.js";
|
|
7
7
|
import { Target, TargetType } from "../define/Target.js";
|
|
8
8
|
import { Statement } from "./Statement.js";
|
|
9
9
|
var binOps = {
|
|
10
|
-
[
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
24
|
-
[
|
|
25
|
-
[
|
|
26
|
-
[
|
|
27
|
-
[
|
|
28
|
-
[
|
|
10
|
+
[BinOpType.Add]: "+",
|
|
11
|
+
[BinOpType.Subt]: "-",
|
|
12
|
+
[BinOpType.Mult]: "*",
|
|
13
|
+
[BinOpType.Mod]: "%",
|
|
14
|
+
[BinOpType.Div]: "/",
|
|
15
|
+
[BinOpType.Greater]: ">",
|
|
16
|
+
[BinOpType.GreaterOrEqual]: ">=",
|
|
17
|
+
[BinOpType.Less]: "<",
|
|
18
|
+
[BinOpType.LessOrEqual]: "<=",
|
|
19
|
+
[BinOpType.Equals]: "=",
|
|
20
|
+
[BinOpType.NotEquals]: "!=",
|
|
21
|
+
[BinOpType.And]: "and",
|
|
22
|
+
[BinOpType.Or]: "or",
|
|
23
|
+
[BinOpType.Like]: "like",
|
|
24
|
+
[BinOpType.Glob]: "glob",
|
|
25
|
+
[BinOpType.Match]: "match",
|
|
26
|
+
[BinOpType.In]: "in",
|
|
27
|
+
[BinOpType.NotIn]: "not in",
|
|
28
|
+
[BinOpType.Concat]: "||"
|
|
29
29
|
};
|
|
30
30
|
var joins = {
|
|
31
31
|
left: "left",
|
|
@@ -420,21 +420,6 @@ var Formatter = class {
|
|
|
420
420
|
formatExprValue(ctx, expr) {
|
|
421
421
|
return this.formatExpr({ ...ctx, formatAsJson: false }, expr);
|
|
422
422
|
}
|
|
423
|
-
formatIn(ctx, expr) {
|
|
424
|
-
const { stmt } = ctx;
|
|
425
|
-
switch (expr.type) {
|
|
426
|
-
case ExprType.Field:
|
|
427
|
-
stmt.openParenthesis();
|
|
428
|
-
stmt.raw("SELECT value FROM json_each");
|
|
429
|
-
stmt.openParenthesis();
|
|
430
|
-
this.formatExprJson(ctx, expr);
|
|
431
|
-
stmt.closeParenthesis();
|
|
432
|
-
stmt.closeParenthesis();
|
|
433
|
-
return stmt;
|
|
434
|
-
default:
|
|
435
|
-
return this.formatExprValue(ctx, expr);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
423
|
retrieveField(expr, field) {
|
|
439
424
|
switch (expr.type) {
|
|
440
425
|
case ExprType.Record:
|
|
@@ -458,7 +443,7 @@ var Formatter = class {
|
|
|
458
443
|
const asBoolean = column?.type === ColumnType.Boolean && ctx.formatAsJson;
|
|
459
444
|
const asJson = column?.type === ColumnType.Json && ctx.formatAsJson;
|
|
460
445
|
if (asJson) {
|
|
461
|
-
stmt.
|
|
446
|
+
stmt.raw("json");
|
|
462
447
|
stmt.openParenthesis();
|
|
463
448
|
}
|
|
464
449
|
if (asBoolean)
|
|
@@ -533,9 +518,9 @@ var Formatter = class {
|
|
|
533
518
|
switch (expr.type) {
|
|
534
519
|
case ExprType.UnOp:
|
|
535
520
|
switch (expr.op) {
|
|
536
|
-
case
|
|
521
|
+
case UnOpType.IsNull:
|
|
537
522
|
return this.formatExprValue(ctx, expr.expr).add("IS NULL");
|
|
538
|
-
case
|
|
523
|
+
case UnOpType.Not:
|
|
539
524
|
stmt.raw("NOT").openParenthesis();
|
|
540
525
|
this.formatExprValue(ctx, expr.expr);
|
|
541
526
|
return stmt.closeParenthesis();
|
|
@@ -543,10 +528,8 @@ var Formatter = class {
|
|
|
543
528
|
case ExprType.BinOp:
|
|
544
529
|
stmt.openParenthesis();
|
|
545
530
|
this.formatExprValue(ctx, expr.a).add(binOps[expr.op]).space();
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
else
|
|
549
|
-
this.formatExprValue(ctx, expr.b);
|
|
531
|
+
const asIn = expr.op === BinOpType.In || expr.op === BinOpType.NotIn;
|
|
532
|
+
this.formatExprValue({ ...ctx, formatAsIn: asIn }, expr.b);
|
|
550
533
|
return stmt.closeParenthesis();
|
|
551
534
|
case ExprType.Param:
|
|
552
535
|
switch (expr.param.type) {
|
|
@@ -555,8 +538,18 @@ var Formatter = class {
|
|
|
555
538
|
case ParamType.Named:
|
|
556
539
|
return stmt.param(expr.param);
|
|
557
540
|
}
|
|
558
|
-
case ExprType.Field:
|
|
559
|
-
|
|
541
|
+
case ExprType.Field: {
|
|
542
|
+
const { formatAsIn, ...rest } = ctx;
|
|
543
|
+
if (formatAsIn) {
|
|
544
|
+
stmt.openParenthesis();
|
|
545
|
+
stmt.raw("SELECT value FROM json_each");
|
|
546
|
+
stmt.openParenthesis();
|
|
547
|
+
this.formatExprJson(rest, expr);
|
|
548
|
+
stmt.closeParenthesis();
|
|
549
|
+
return stmt.closeParenthesis();
|
|
550
|
+
}
|
|
551
|
+
return this.formatField(rest, expr.expr, expr.field);
|
|
552
|
+
}
|
|
560
553
|
case ExprType.Call: {
|
|
561
554
|
if (expr.method === "cast") {
|
|
562
555
|
const [e, type] = expr.params;
|
|
@@ -625,32 +618,48 @@ var Formatter = class {
|
|
|
625
618
|
}
|
|
626
619
|
return stmt;
|
|
627
620
|
case ExprType.Filter: {
|
|
621
|
+
const { formatAsIn, ...rest } = ctx;
|
|
628
622
|
const { target, condition } = expr;
|
|
629
623
|
switch (target.type) {
|
|
630
624
|
case TargetType.Expr:
|
|
631
|
-
stmt.openParenthesis()
|
|
632
|
-
|
|
625
|
+
stmt.openParenthesis();
|
|
626
|
+
if (!formatAsIn) {
|
|
627
|
+
stmt.raw("SELECT json_group_array(json(result)) FROM ").openParenthesis();
|
|
628
|
+
}
|
|
629
|
+
stmt.raw("SELECT value AS result").add("FROM json_each").openParenthesis();
|
|
630
|
+
this.formatExprJson(rest, target.expr);
|
|
633
631
|
stmt.closeParenthesis();
|
|
634
632
|
if (target.alias)
|
|
635
633
|
stmt.add("AS").addIdentifier(target.alias);
|
|
636
634
|
stmt.add("WHERE").space();
|
|
637
|
-
this.formatExprValue(
|
|
638
|
-
|
|
635
|
+
this.formatExprValue(rest, condition);
|
|
636
|
+
if (!formatAsIn) {
|
|
637
|
+
stmt.closeParenthesis();
|
|
638
|
+
}
|
|
639
|
+
return stmt.closeParenthesis();
|
|
639
640
|
default:
|
|
640
641
|
throw new Error("todo");
|
|
641
642
|
}
|
|
642
643
|
}
|
|
643
644
|
case ExprType.Map: {
|
|
645
|
+
const { formatAsIn, ...rest } = ctx;
|
|
644
646
|
const { target, result } = expr;
|
|
645
647
|
switch (target.type) {
|
|
646
648
|
case TargetType.Expr:
|
|
647
|
-
stmt.openParenthesis()
|
|
648
|
-
|
|
649
|
-
|
|
649
|
+
stmt.openParenthesis();
|
|
650
|
+
if (!formatAsIn) {
|
|
651
|
+
stmt.raw("SELECT json_group_array(json(result)) FROM ").openParenthesis();
|
|
652
|
+
}
|
|
653
|
+
stmt.raw("SELECT").space();
|
|
654
|
+
this.formatExprJson(rest, result).add("AS result").add("FROM json_each").openParenthesis();
|
|
655
|
+
this.formatExprJson(rest, target.expr);
|
|
650
656
|
stmt.closeParenthesis();
|
|
651
657
|
if (target.alias)
|
|
652
658
|
stmt.add("AS").addIdentifier(target.alias);
|
|
653
|
-
|
|
659
|
+
if (!formatAsIn) {
|
|
660
|
+
stmt.closeParenthesis();
|
|
661
|
+
}
|
|
662
|
+
return stmt.closeParenthesis();
|
|
654
663
|
default:
|
|
655
664
|
throw new Error("todo");
|
|
656
665
|
}
|