rado 0.1.56 → 0.1.57
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 +2 -2
- package/dist/lib/Formatter.js +12 -7
- package/package.json +1 -1
package/dist/lib/Formatter.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface FormatContext {
|
|
|
19
19
|
/** Inline all parameters */
|
|
20
20
|
forceInline?: boolean;
|
|
21
21
|
formatAsJson?: boolean;
|
|
22
|
-
|
|
22
|
+
formatAsInsert?: boolean;
|
|
23
23
|
topLevel?: boolean;
|
|
24
24
|
}
|
|
25
25
|
type FormatSubject = (stmt: Statement, mkSubject: () => void) => void;
|
|
@@ -37,7 +37,7 @@ export declare abstract class Formatter implements Sanitizer {
|
|
|
37
37
|
tableAsExpr?: boolean | undefined;
|
|
38
38
|
forceInline?: boolean | undefined;
|
|
39
39
|
formatAsJson?: boolean | undefined;
|
|
40
|
-
|
|
40
|
+
formatAsInsert?: boolean | undefined;
|
|
41
41
|
topLevel?: boolean | undefined;
|
|
42
42
|
skipNewlines?: boolean | undefined;
|
|
43
43
|
};
|
package/dist/lib/Formatter.js
CHANGED
|
@@ -122,7 +122,7 @@ var Formatter = class {
|
|
|
122
122
|
if (value instanceof Expr)
|
|
123
123
|
this.formatExprJson(ctx, ExprData.create(data[key]));
|
|
124
124
|
else
|
|
125
|
-
this.formatValue({ ...ctx,
|
|
125
|
+
this.formatValue({ ...ctx, formatAsInsert: true }, value);
|
|
126
126
|
}
|
|
127
127
|
this.formatWhere(ctx, query.where);
|
|
128
128
|
this.formatLimit(ctx, query);
|
|
@@ -241,7 +241,7 @@ var Formatter = class {
|
|
|
241
241
|
this.formatExpr(
|
|
242
242
|
{
|
|
243
243
|
...ctx,
|
|
244
|
-
|
|
244
|
+
formatAsInsert: true,
|
|
245
245
|
forceInline: true
|
|
246
246
|
},
|
|
247
247
|
column.defaultValue
|
|
@@ -293,11 +293,11 @@ var Formatter = class {
|
|
|
293
293
|
if (column.defaultValue !== void 0) {
|
|
294
294
|
if (typeof column.defaultValue === "function")
|
|
295
295
|
return this.formatExprJson(
|
|
296
|
-
{ ...ctx,
|
|
296
|
+
{ ...ctx, formatAsInsert: true },
|
|
297
297
|
column.defaultValue()
|
|
298
298
|
);
|
|
299
299
|
return this.formatExprJson(
|
|
300
|
-
{ ...ctx,
|
|
300
|
+
{ ...ctx, formatAsInsert: true },
|
|
301
301
|
column.defaultValue
|
|
302
302
|
);
|
|
303
303
|
}
|
|
@@ -454,15 +454,20 @@ var Formatter = class {
|
|
|
454
454
|
switch (expr.target.type) {
|
|
455
455
|
case TargetType.Table:
|
|
456
456
|
const column = expr.target.table.columns[field];
|
|
457
|
+
const asBoolean = column?.type === ColumnType.Boolean && ctx.formatAsJson;
|
|
457
458
|
const asJson = column?.type === ColumnType.Json && ctx.formatAsJson;
|
|
458
459
|
if (asJson) {
|
|
459
460
|
stmt.add("json");
|
|
460
461
|
stmt.openParenthesis();
|
|
461
462
|
}
|
|
463
|
+
if (asBoolean)
|
|
464
|
+
stmt.add(`json(iif(`);
|
|
462
465
|
if (!ctx.skipTableName) {
|
|
463
466
|
stmt.identifier(expr.target.table.alias || expr.target.table.name).raw(".");
|
|
464
467
|
}
|
|
465
468
|
stmt.identifier(field);
|
|
469
|
+
if (asBoolean)
|
|
470
|
+
stmt.add(`, 'true', 'false'))`);
|
|
466
471
|
if (asJson)
|
|
467
472
|
stmt.closeParenthesis();
|
|
468
473
|
return stmt;
|
|
@@ -489,14 +494,14 @@ var Formatter = class {
|
|
|
489
494
|
}
|
|
490
495
|
}
|
|
491
496
|
formatValue(ctx, rawValue) {
|
|
492
|
-
const { stmt, formatAsJson,
|
|
497
|
+
const { stmt, formatAsJson, formatAsInsert, forceInline } = ctx;
|
|
493
498
|
switch (true) {
|
|
494
499
|
case (rawValue === null || rawValue === void 0):
|
|
495
500
|
return stmt.raw("NULL");
|
|
496
|
-
case ((
|
|
501
|
+
case ((formatAsInsert || !formatAsJson) && typeof rawValue === "boolean"):
|
|
497
502
|
return rawValue ? stmt.raw("1") : stmt.raw("0");
|
|
498
503
|
case Array.isArray(rawValue):
|
|
499
|
-
const asJson = formatAsJson ||
|
|
504
|
+
const asJson = formatAsJson || formatAsInsert;
|
|
500
505
|
if (asJson)
|
|
501
506
|
stmt.raw("json_array");
|
|
502
507
|
stmt.openParenthesis();
|