rado 0.1.46 → 0.1.48

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,6 +19,7 @@ export interface FormatContext {
19
19
  /** Inline all parameters */
20
20
  forceInline?: boolean;
21
21
  formatAsJson?: boolean;
22
+ formatAsDefault?: boolean;
22
23
  topLevel?: boolean;
23
24
  }
24
25
  type FormatSubject = (stmt: Statement, mkSubject: () => void) => void;
@@ -176,7 +176,7 @@ var Formatter = class {
176
176
  const { stmt } = ctx;
177
177
  stmt.add("ALTER TABLE").addIdentifier(query.table.name);
178
178
  if (query.addColumn) {
179
- stmt.add("ADD COLUMN");
179
+ stmt.add("ADD COLUMN").space();
180
180
  this.formatColumn(ctx, query.addColumn);
181
181
  } else if (query.dropColumn) {
182
182
  stmt.add("DROP COLUMN").addIdentifier(query.dropColumn);
@@ -235,7 +235,7 @@ var Formatter = class {
235
235
  this.formatExpr(
236
236
  {
237
237
  ...ctx,
238
- formatAsJson: true,
238
+ formatAsDefault: true,
239
239
  forceInline: true
240
240
  },
241
241
  column.defaultValue
@@ -286,8 +286,14 @@ var Formatter = class {
286
286
  if (isNull) {
287
287
  if (column.defaultValue !== void 0) {
288
288
  if (typeof column.defaultValue === "function")
289
- return this.formatExprJson(ctx, column.defaultValue());
290
- return this.formatExprJson(ctx, column.defaultValue);
289
+ return this.formatExprJson(
290
+ { ...ctx, formatAsDefault: true },
291
+ column.defaultValue()
292
+ );
293
+ return this.formatExprJson(
294
+ { ...ctx, formatAsDefault: true },
295
+ column.defaultValue
296
+ );
291
297
  }
292
298
  if (!isOptional)
293
299
  throw new TypeError(`Expected value for column ${column.name}`);
@@ -410,7 +416,9 @@ var Formatter = class {
410
416
  formatIn(ctx, expr) {
411
417
  const { stmt } = ctx;
412
418
  switch (expr.type) {
413
- case ExprType.Field:
419
+ case ExprType.Query:
420
+ return this.formatExprValue(ctx, expr);
421
+ default:
414
422
  stmt.openParenthesis();
415
423
  stmt.raw("SELECT value FROM json_each");
416
424
  stmt.openParenthesis();
@@ -418,8 +426,6 @@ var Formatter = class {
418
426
  stmt.closeParenthesis();
419
427
  stmt.closeParenthesis();
420
428
  return stmt;
421
- default:
422
- return this.formatExprValue(ctx, expr);
423
429
  }
424
430
  }
425
431
  retrieveField(expr, field) {
@@ -477,20 +483,20 @@ var Formatter = class {
477
483
  }
478
484
  }
479
485
  formatValue(ctx, rawValue) {
480
- const { stmt, formatAsJson, forceInline } = ctx;
486
+ const { stmt, formatAsJson, formatAsDefault, forceInline } = ctx;
481
487
  switch (true) {
482
488
  case (rawValue === null || rawValue === void 0):
483
489
  return stmt.raw("NULL");
484
- case (!formatAsJson && typeof rawValue === "boolean"):
490
+ case ((formatAsDefault || !formatAsJson) && typeof rawValue === "boolean"):
485
491
  return rawValue ? stmt.raw("1") : stmt.raw("0");
486
492
  case Array.isArray(rawValue):
487
- if (formatAsJson) {
493
+ if (formatAsDefault || formatAsJson) {
488
494
  stmt.raw("json_array");
489
495
  stmt.openParenthesis();
490
496
  }
491
497
  for (const v of stmt.separate(rawValue))
492
498
  this.formatValue({ ...ctx, formatAsJson: false }, v);
493
- if (formatAsJson)
499
+ if (formatAsDefault || formatAsJson)
494
500
  stmt.closeParenthesis();
495
501
  return stmt;
496
502
  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.46",
3
+ "version": "0.1.48",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {