rado 0.4.7 → 0.4.9

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.
@@ -27,7 +27,8 @@ export declare enum BinOpType {
27
27
  Match = "Match",
28
28
  In = "In",
29
29
  NotIn = "NotIn",
30
- Concat = "Concat"
30
+ Concat = "Concat",
31
+ Collate = "Collate"
31
32
  }
32
33
  export declare enum ExprType {
33
34
  UnOp = "ExprData.UnOp",
@@ -139,6 +140,7 @@ export declare class Expr<T> {
139
140
  isLess(that: EV<any>): Expr<boolean>;
140
141
  isLessOrEqual(that: EV<any>): Expr<boolean>;
141
142
  add(this: Expr<number>, that: EV<number>, ...rest: Array<EV<number>>): Expr<number>;
143
+ collate(collation: string): Expr<string>;
142
144
  subtract(this: Expr<number>, that: EV<number>, ...rest: Array<EV<number>>): Expr<number>;
143
145
  multiply(this: Expr<number>, that: EV<number>, ...rest: Array<EV<number>>): Expr<number>;
144
146
  remainder(this: Expr<number>, that: EV<number>): Expr<number>;
@@ -28,6 +28,7 @@ var BinOpType = /* @__PURE__ */ ((BinOpType2) => {
28
28
  BinOpType2["In"] = "In";
29
29
  BinOpType2["NotIn"] = "NotIn";
30
30
  BinOpType2["Concat"] = "Concat";
31
+ BinOpType2["Collate"] = "Collate";
31
32
  return BinOpType2;
32
33
  })(BinOpType || {});
33
34
  var ExprType = /* @__PURE__ */ ((ExprType2) => {
@@ -284,6 +285,15 @@ class Expr {
284
285
  )
285
286
  );
286
287
  }
288
+ collate(collation) {
289
+ return new Expr(
290
+ new ExprData.BinOp(
291
+ "Collate" /* Collate */,
292
+ this[Expr.Data],
293
+ ExprData.create(collation)
294
+ )
295
+ );
296
+ }
287
297
  subtract(that, ...rest) {
288
298
  return new Expr(
289
299
  ExprData.createAll(this, that, ...rest).reduce(
@@ -24,7 +24,8 @@ const binOps = {
24
24
  [BinOpType.Match]: "MATCH",
25
25
  [BinOpType.In]: "IN",
26
26
  [BinOpType.NotIn]: "NOT IN",
27
- [BinOpType.Concat]: "||"
27
+ [BinOpType.Concat]: "||",
28
+ [BinOpType.Collate]: "COLLATE"
28
29
  };
29
30
  const joins = {
30
31
  left: "LEFT",
@@ -616,12 +617,21 @@ class Formatter {
616
617
  const { stmt } = ctx;
617
618
  stmt.openParenthesis();
618
619
  this.formatExprValue(ctx, expr.a).add(binOps[expr.op]).space();
619
- const asIn = expr.op === BinOpType.In || expr.op === BinOpType.NotIn;
620
- if (asIn)
621
- this.formatIn(ctx, expr.b);
622
- else
623
- this.formatExprValue(ctx, expr.b);
624
- return stmt.closeParenthesis();
620
+ switch (expr.op) {
621
+ case BinOpType.Collate:
622
+ const value = expr.b.type === ExprType.Param && expr.b.param.type === ParamType.Value && expr.b.param.value;
623
+ if (typeof value !== "string")
624
+ throw new Error("Expected string");
625
+ stmt.add(this.escapeIdentifier(value));
626
+ return stmt.closeParenthesis();
627
+ case BinOpType.In:
628
+ case BinOpType.NotIn:
629
+ this.formatIn(ctx, expr.b);
630
+ return stmt.closeParenthesis();
631
+ default:
632
+ this.formatExprValue(ctx, expr.b);
633
+ return stmt.closeParenthesis();
634
+ }
625
635
  }
626
636
  formatParam(ctx, expr) {
627
637
  const { stmt } = ctx;
@@ -159,7 +159,7 @@ export type SqliteFunctions = {
159
159
  julianday(timeValue: EV<any>, ...rest: Array<EV<string>>): Expr<string>;
160
160
  strftime(format: EV<string>, timeValue: EV<any>, ...rest: Array<EV<string>>): Expr<string>;
161
161
  };
162
- export declare const count: (x?: Expr<any>) => Expr<number>, iif: <T>(x: EV<boolean>, y: EV<T>, z: EV<T>) => Expr<T>, exists: (cursor: Query<any>) => Expr<boolean>, match: (table: Table<any>, searchTerm: EV<string>) => Expr<boolean>, highlight: (table: Table<any>, index: EV<number>, insertBefore: EV<string>, insertAfter: EV<string>) => Expr<string>, snippet: (table: Table<any>, index: EV<number>, insertBefore: EV<string>, insertAfter: EV<string>, snip: EV<string>, maxTokens: EV<number>) => Expr<string>, cast: {
162
+ export declare const count: (x?: Expr<any>) => Expr<number>, iif: <T>(x: EV<boolean>, y: EV<T>, z: EV<T>) => Expr<T>, exists: (cursor: Query<any>) => Expr<boolean>, match: (table: Table<any>, searchTerm: EV<string>) => Expr<boolean>, bm25: (table: Table<any>, ...weights: Array<EV<number>>) => Expr<number>, highlight: (table: Table<any>, index: EV<number>, insertBefore: EV<string>, insertAfter: EV<string>) => Expr<string>, snippet: (table: Table<any>, index: EV<number>, insertBefore: EV<string>, insertAfter: EV<string>, snip: EV<string>, maxTokens: EV<number>) => Expr<string>, cast: {
163
163
  (x: EV<any>, type: 'text'): Expr<string>;
164
164
  (x: EV<any>, type: 'real'): Expr<number>;
165
165
  (x: EV<any>, type: 'integer'): Expr<number>;
@@ -5,6 +5,7 @@ const {
5
5
  iif,
6
6
  exists,
7
7
  match,
8
+ bm25,
8
9
  highlight,
9
10
  snippet,
10
11
  cast,
@@ -84,6 +85,7 @@ export {
84
85
  atan2,
85
86
  atanh,
86
87
  avg,
88
+ bm25,
87
89
  cast,
88
90
  ceil,
89
91
  changes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",