rado 0.2.41 → 0.2.43

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.
@@ -170,7 +170,7 @@ export declare namespace Expr {
170
170
  const IsExpr: unique symbol;
171
171
  const ToExpr: unique symbol;
172
172
  const NULL: Expr<null>;
173
- function value<T>(value: T): Expr<T>;
173
+ function value<T>(value: T, inline?: boolean): Expr<T>;
174
174
  function get<T = any>(expr: ObjectExpr, field: string): Expr<T>;
175
175
  function create<T>(input: EV<T>): Expr<T>;
176
176
  function and(...conditions: Array<EV<boolean>>): Expr<boolean>;
@@ -392,8 +392,8 @@ class Expr {
392
392
  Expr2.IsExpr = Symbol("Expr.IsExpr");
393
393
  Expr2.ToExpr = Symbol("Expr.ToExpr");
394
394
  Expr2.NULL = create(null);
395
- function value(value2) {
396
- return new Expr2(new ExprData.Param(new ParamData.Value(value2)));
395
+ function value(value2, inline = false) {
396
+ return new Expr2(new ExprData.Param(new ParamData.Value(value2, inline)));
397
397
  }
398
398
  Expr2.value = value;
399
399
  function get(expr, field) {
@@ -5,8 +5,9 @@ export declare enum ParamType {
5
5
  export declare namespace ParamData {
6
6
  class Value {
7
7
  value: any;
8
+ inline: boolean;
8
9
  type: ParamType.Value;
9
- constructor(value: any);
10
+ constructor(value: any, inline?: boolean);
10
11
  }
11
12
  class Named {
12
13
  name: string;
@@ -6,8 +6,9 @@ var ParamType = /* @__PURE__ */ ((ParamType2) => {
6
6
  var ParamData;
7
7
  ((ParamData2) => {
8
8
  class Value {
9
- constructor(value) {
9
+ constructor(value, inline = false) {
10
10
  this.value = value;
11
+ this.inline = inline;
11
12
  }
12
13
  type = "ParamData.Value" /* Value */;
13
14
  }
@@ -1,6 +1,6 @@
1
1
  import { Query } from './Query.js';
2
2
  export declare function sql<T>(strings: TemplateStringsArray, ...params: Array<unknown>): Query<T>;
3
3
  export declare namespace sql {
4
- function all<T>(strings: TemplateStringsArray, ...params: Array<unknown>): Query<T>;
5
- function get<T>(strings: TemplateStringsArray, ...params: Array<unknown>): Query<T>;
4
+ function all<T = unknown>(strings: TemplateStringsArray, ...params: Array<unknown>): Query<Array<T>>;
5
+ function get<T = unknown>(strings: TemplateStringsArray, ...params: Array<unknown>): Query<T>;
6
6
  }
@@ -75,7 +75,7 @@ export declare abstract class Formatter implements Sanitizer {
75
75
  formatSelection(ctx: FormatContext, selection: ExprData, formatSubject?: FormatSubject): Statement;
76
76
  formatString(ctx: FormatContext, input: string): Statement;
77
77
  formatInlineValue(ctx: FormatContext, rawValue: any): Statement;
78
- formatValue(ctx: FormatContext, rawValue: any): Statement;
78
+ formatValue(ctx: FormatContext, rawValue: any, inline?: boolean): Statement;
79
79
  formatExprJson(ctx: FormatContext, expr: ExprData): Statement;
80
80
  formatExprValue(ctx: FormatContext, expr: ExprData): Statement;
81
81
  formatExpr(ctx: FormatContext, expr: ExprData): Statement;
@@ -438,7 +438,7 @@ class Formatter {
438
438
  }
439
439
  formatGroupBy(ctx, groupBy) {
440
440
  const { stmt } = ctx;
441
- if (!groupBy)
441
+ if (!groupBy || groupBy.length === 0)
442
442
  return stmt;
443
443
  stmt.addLine("GROUP BY").space();
444
444
  for (const expr of stmt.separate(groupBy))
@@ -447,7 +447,7 @@ class Formatter {
447
447
  }
448
448
  formatOrderBy(ctx, orderBy) {
449
449
  const { stmt } = ctx;
450
- if (!orderBy)
450
+ if (!orderBy || orderBy.length === 0)
451
451
  return stmt;
452
452
  stmt.addLine("ORDER BY").space();
453
453
  for (const { expr, order } of stmt.separate(orderBy)) {
@@ -502,8 +502,9 @@ class Formatter {
502
502
  return this.formatString(ctx, JSON.stringify(rawValue));
503
503
  }
504
504
  }
505
- formatValue(ctx, rawValue) {
505
+ formatValue(ctx, rawValue, inline = false) {
506
506
  const { stmt, formatAsJson, formatAsInsert, forceInline } = ctx;
507
+ const inlineValue = inline || forceInline;
507
508
  const asJson = formatAsJson || formatAsInsert;
508
509
  switch (true) {
509
510
  case (rawValue === null || rawValue === void 0):
@@ -519,7 +520,7 @@ class Formatter {
519
520
  stmt.closeParenthesis();
520
521
  return stmt;
521
522
  case (typeof rawValue === "string" || typeof rawValue === "number"):
522
- if (forceInline)
523
+ if (inlineValue)
523
524
  return stmt.raw(this.escapeValue(rawValue));
524
525
  return stmt.value(rawValue);
525
526
  default:
@@ -527,7 +528,7 @@ class Formatter {
527
528
  stmt.raw("json");
528
529
  stmt.openParenthesis();
529
530
  }
530
- if (forceInline)
531
+ if (inlineValue)
531
532
  this.formatString(ctx, JSON.stringify(rawValue));
532
533
  else
533
534
  stmt.value(JSON.stringify(rawValue));
@@ -594,7 +595,7 @@ class Formatter {
594
595
  const { stmt } = ctx;
595
596
  switch (expr.param.type) {
596
597
  case ParamType.Value:
597
- return this.formatValue(ctx, expr.param.value);
598
+ return this.formatValue(ctx, expr.param.value, expr.param.inline);
598
599
  case ParamType.Named:
599
600
  return stmt.param(expr.param);
600
601
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "0.2.41",
3
+ "version": "0.2.43",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",