rado 0.1.55 → 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.
@@ -19,7 +19,7 @@ export interface FormatContext {
19
19
  /** Inline all parameters */
20
20
  forceInline?: boolean;
21
21
  formatAsJson?: boolean;
22
- formatAsDefault?: boolean;
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
- formatAsDefault?: boolean | undefined;
40
+ formatAsInsert?: boolean | undefined;
41
41
  topLevel?: boolean | undefined;
42
42
  skipNewlines?: boolean | undefined;
43
43
  };
@@ -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, formatAsJson: true }, value);
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
- formatAsDefault: true,
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, formatAsDefault: true },
296
+ { ...ctx, formatAsInsert: true },
297
297
  column.defaultValue()
298
298
  );
299
299
  return this.formatExprJson(
300
- { ...ctx, formatAsDefault: true },
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,19 +494,19 @@ var Formatter = class {
489
494
  }
490
495
  }
491
496
  formatValue(ctx, rawValue) {
492
- const { stmt, formatAsJson, formatAsDefault, forceInline } = ctx;
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 ((formatAsDefault || !formatAsJson) && typeof rawValue === "boolean"):
501
+ case ((formatAsInsert || !formatAsJson) && typeof rawValue === "boolean"):
497
502
  return rawValue ? stmt.raw("1") : stmt.raw("0");
498
503
  case Array.isArray(rawValue):
499
- if (formatAsDefault || formatAsJson) {
504
+ const asJson = formatAsJson || formatAsInsert;
505
+ if (asJson)
500
506
  stmt.raw("json_array");
501
- }
502
507
  stmt.openParenthesis();
503
508
  for (const v of stmt.separate(rawValue))
504
- this.formatValue({ ...ctx, formatAsJson: false }, v);
509
+ this.formatValue({ ...ctx, formatAsJson: asJson }, v);
505
510
  stmt.closeParenthesis();
506
511
  return stmt;
507
512
  case (typeof rawValue === "string" || typeof rawValue === "number"):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "0.1.55",
3
+ "version": "0.1.57",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",