rado 0.1.61 → 0.1.63
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/lib/Formatter.d.ts +4 -4
- package/dist/lib/Formatter.js +23 -27
- package/package.json +1 -1
package/dist/lib/Formatter.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ export declare abstract class Formatter implements Sanitizer {
|
|
|
46
46
|
skipNewlines?: boolean | undefined;
|
|
47
47
|
};
|
|
48
48
|
format<T>(ctx: FormatContext, query: Query<T>): Statement;
|
|
49
|
-
formatSelect(ctx: FormatContext, query: Query.Select): Statement;
|
|
49
|
+
formatSelect({ topLevel, ...ctx }: FormatContext, query: Query.Select): Statement;
|
|
50
50
|
formatInsert(ctx: FormatContext, query: Query.Insert): Statement;
|
|
51
51
|
formatUpdate(ctx: FormatContext, query: Query.Update): Statement;
|
|
52
52
|
formatDelete(ctx: FormatContext, query: Query.Delete): Statement;
|
|
@@ -63,8 +63,8 @@ export declare abstract class Formatter implements Sanitizer {
|
|
|
63
63
|
formatInsertRow(ctx: FormatContext, columns: Record<string, ColumnData>, row: Record<string, any>): Statement;
|
|
64
64
|
formatColumnValue(ctx: FormatContext, column: ColumnData, columnValue: any): Statement;
|
|
65
65
|
formatTarget(ctx: FormatContext, target: Target): Statement;
|
|
66
|
-
formatWhere(ctx: FormatContext, expr: ExprData | undefined): Statement;
|
|
67
|
-
formatHaving(ctx: FormatContext, expr: ExprData | undefined): Statement;
|
|
66
|
+
formatWhere({ topLevel, ...ctx }: FormatContext, expr: ExprData | undefined): Statement;
|
|
67
|
+
formatHaving({ topLevel, ...ctx }: FormatContext, expr: ExprData | undefined): Statement;
|
|
68
68
|
formatGroupBy(ctx: FormatContext, groupBy: Array<ExprData> | undefined): Statement;
|
|
69
69
|
formatOrderBy(ctx: FormatContext, orderBy: Array<OrderBy> | undefined): Statement;
|
|
70
70
|
formatLimit(ctx: FormatContext, { limit, offset, singleResult }: Query.QueryBase): Statement;
|
|
@@ -76,6 +76,6 @@ export declare abstract class Formatter implements Sanitizer {
|
|
|
76
76
|
formatString(ctx: FormatContext, input: string): Statement;
|
|
77
77
|
formatInlineValue(ctx: FormatContext, rawValue: any): Statement;
|
|
78
78
|
formatValue(ctx: FormatContext, rawValue: any): Statement;
|
|
79
|
-
formatExpr(ctx: FormatContext, expr: ExprData): Statement;
|
|
79
|
+
formatExpr({ formatAsIn, ...ctx }: FormatContext, expr: ExprData): Statement;
|
|
80
80
|
}
|
|
81
81
|
export {};
|
package/dist/lib/Formatter.js
CHANGED
|
@@ -18,18 +18,18 @@ var binOps = {
|
|
|
18
18
|
[BinOpType.LessOrEqual]: "<=",
|
|
19
19
|
[BinOpType.Equals]: "=",
|
|
20
20
|
[BinOpType.NotEquals]: "!=",
|
|
21
|
-
[BinOpType.And]: "
|
|
22
|
-
[BinOpType.Or]: "
|
|
23
|
-
[BinOpType.Like]: "
|
|
24
|
-
[BinOpType.Glob]: "
|
|
25
|
-
[BinOpType.Match]: "
|
|
26
|
-
[BinOpType.In]: "
|
|
27
|
-
[BinOpType.NotIn]: "
|
|
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
28
|
[BinOpType.Concat]: "||"
|
|
29
29
|
};
|
|
30
30
|
var joins = {
|
|
31
|
-
left: "
|
|
32
|
-
inner: "
|
|
31
|
+
left: "LEFT",
|
|
32
|
+
inner: "INNER"
|
|
33
33
|
};
|
|
34
34
|
function formatAsResultObject(stmt, mkSubject) {
|
|
35
35
|
stmt.raw("json_object('result', ");
|
|
@@ -75,11 +75,11 @@ var Formatter = class {
|
|
|
75
75
|
return this.formatRaw(ctx, query);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
formatSelect(ctx, query) {
|
|
79
|
-
const { stmt
|
|
78
|
+
formatSelect({ topLevel, ...ctx }, query) {
|
|
79
|
+
const { stmt } = ctx;
|
|
80
80
|
stmt.raw("SELECT").space();
|
|
81
81
|
this.formatSelection(
|
|
82
|
-
|
|
82
|
+
ctx,
|
|
83
83
|
query.selection,
|
|
84
84
|
topLevel ? formatAsResultObject : void 0
|
|
85
85
|
);
|
|
@@ -353,7 +353,7 @@ var Formatter = class {
|
|
|
353
353
|
throw new Error("Cannot format expression as target");
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
|
-
formatWhere(ctx, expr) {
|
|
356
|
+
formatWhere({ topLevel, ...ctx }, expr) {
|
|
357
357
|
const { stmt } = ctx;
|
|
358
358
|
if (!expr)
|
|
359
359
|
return stmt;
|
|
@@ -361,7 +361,7 @@ var Formatter = class {
|
|
|
361
361
|
this.formatExprValue(ctx, expr);
|
|
362
362
|
return stmt;
|
|
363
363
|
}
|
|
364
|
-
formatHaving(ctx, expr) {
|
|
364
|
+
formatHaving({ topLevel, ...ctx }, expr) {
|
|
365
365
|
const { stmt } = ctx;
|
|
366
366
|
if (!expr)
|
|
367
367
|
return stmt;
|
|
@@ -410,7 +410,7 @@ var Formatter = class {
|
|
|
410
410
|
if (formatSubject)
|
|
411
411
|
formatSubject(stmt, mkSubject);
|
|
412
412
|
else
|
|
413
|
-
|
|
413
|
+
this.formatExpr(ctx, selection);
|
|
414
414
|
stmt.add("AS").addIdentifier("result");
|
|
415
415
|
return stmt;
|
|
416
416
|
}
|
|
@@ -513,7 +513,7 @@ var Formatter = class {
|
|
|
513
513
|
return stmt;
|
|
514
514
|
}
|
|
515
515
|
}
|
|
516
|
-
formatExpr(ctx, expr) {
|
|
516
|
+
formatExpr({ formatAsIn, ...ctx }, expr) {
|
|
517
517
|
const { stmt } = ctx;
|
|
518
518
|
switch (expr.type) {
|
|
519
519
|
case ExprType.UnOp:
|
|
@@ -538,18 +538,16 @@ var Formatter = class {
|
|
|
538
538
|
case ParamType.Named:
|
|
539
539
|
return stmt.param(expr.param);
|
|
540
540
|
}
|
|
541
|
-
case ExprType.Field:
|
|
542
|
-
const { formatAsIn, ...rest } = ctx;
|
|
541
|
+
case ExprType.Field:
|
|
543
542
|
if (formatAsIn) {
|
|
544
543
|
stmt.openParenthesis();
|
|
545
544
|
stmt.raw("SELECT value FROM json_each");
|
|
546
545
|
stmt.openParenthesis();
|
|
547
|
-
this.formatExprJson(
|
|
546
|
+
this.formatExprJson(ctx, expr);
|
|
548
547
|
stmt.closeParenthesis();
|
|
549
548
|
return stmt.closeParenthesis();
|
|
550
549
|
}
|
|
551
|
-
return this.formatField(
|
|
552
|
-
}
|
|
550
|
+
return this.formatField(ctx, expr.expr, expr.field);
|
|
553
551
|
case ExprType.Call: {
|
|
554
552
|
if (expr.method === "cast") {
|
|
555
553
|
const [e, type] = expr.params;
|
|
@@ -618,7 +616,6 @@ var Formatter = class {
|
|
|
618
616
|
}
|
|
619
617
|
return stmt;
|
|
620
618
|
case ExprType.Filter: {
|
|
621
|
-
const { formatAsIn, ...rest } = ctx;
|
|
622
619
|
const { target, condition } = expr;
|
|
623
620
|
switch (target.type) {
|
|
624
621
|
case TargetType.Expr:
|
|
@@ -627,12 +624,12 @@ var Formatter = class {
|
|
|
627
624
|
stmt.raw("SELECT json_group_array(json(result)) FROM ").openParenthesis();
|
|
628
625
|
}
|
|
629
626
|
stmt.raw("SELECT value AS result").add("FROM json_each").openParenthesis();
|
|
630
|
-
this.
|
|
627
|
+
this.formatExpr(ctx, target.expr);
|
|
631
628
|
stmt.closeParenthesis();
|
|
632
629
|
if (target.alias)
|
|
633
630
|
stmt.add("AS").addIdentifier(target.alias);
|
|
634
631
|
stmt.add("WHERE").space();
|
|
635
|
-
this.formatExprValue(
|
|
632
|
+
this.formatExprValue(ctx, condition);
|
|
636
633
|
if (!formatAsIn) {
|
|
637
634
|
stmt.closeParenthesis();
|
|
638
635
|
}
|
|
@@ -642,7 +639,6 @@ var Formatter = class {
|
|
|
642
639
|
}
|
|
643
640
|
}
|
|
644
641
|
case ExprType.Map: {
|
|
645
|
-
const { formatAsIn, ...rest } = ctx;
|
|
646
642
|
const { target, result } = expr;
|
|
647
643
|
switch (target.type) {
|
|
648
644
|
case TargetType.Expr:
|
|
@@ -651,8 +647,8 @@ var Formatter = class {
|
|
|
651
647
|
stmt.raw("SELECT json_group_array(json(result)) FROM ").openParenthesis();
|
|
652
648
|
}
|
|
653
649
|
stmt.raw("SELECT").space();
|
|
654
|
-
this.
|
|
655
|
-
this.formatExprJson(
|
|
650
|
+
this.formatExpr(ctx, result).add("AS result").add("FROM json_each").openParenthesis();
|
|
651
|
+
this.formatExprJson(ctx, target.expr);
|
|
656
652
|
stmt.closeParenthesis();
|
|
657
653
|
if (target.alias)
|
|
658
654
|
stmt.add("AS").addIdentifier(target.alias);
|