rado 0.1.7 → 0.1.8

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/Column.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Expr, ExprData } from './Expr';
2
- export declare const enum ColumnType {
2
+ export declare enum ColumnType {
3
3
  String = "String",
4
4
  Integer = "Integer",
5
5
  Number = "Number",
package/dist/Cursor.d.ts CHANGED
@@ -57,7 +57,7 @@ export declare namespace Cursor {
57
57
  innerJoin<C>(that: Table<C>, ...on: Array<EV<boolean>>): SelectMultiple<T>;
58
58
  select<X extends Selection>(selection: X): SelectMultiple<Selection.Infer<X>>;
59
59
  count(): SelectSingle<number>;
60
- orderBy(...orderBy: Array<OrderBy>): SelectMultiple<T>;
60
+ orderBy(...orderBy: Array<Expr<any> | OrderBy>): SelectMultiple<T>;
61
61
  groupBy(...groupBy: Array<Expr<any>>): SelectMultiple<T>;
62
62
  first(): SelectSingle<T | undefined>;
63
63
  where(...where: Array<EV<boolean>>): SelectMultiple<T>;
package/dist/Cursor.js CHANGED
@@ -136,7 +136,9 @@ var Cursor = class {
136
136
  orderBy(...orderBy) {
137
137
  return new SelectMultiple({
138
138
  ...this.query(),
139
- orderBy
139
+ orderBy: orderBy.map((e) => {
140
+ return e instanceof Expr ? e.asc() : e;
141
+ })
140
142
  });
141
143
  }
142
144
  groupBy(...groupBy) {
package/dist/Expr.d.ts CHANGED
@@ -5,11 +5,11 @@ import { ParamData } from './Param';
5
5
  import { Query } from './Query';
6
6
  import { Selection } from './Selection';
7
7
  import { Target } from './Target';
8
- export declare const enum UnOp {
8
+ export declare enum UnOp {
9
9
  Not = "Not",
10
10
  IsNull = "IsNull"
11
11
  }
12
- export declare const enum BinOp {
12
+ export declare enum BinOp {
13
13
  Add = "Add",
14
14
  Subt = "Subt",
15
15
  Mult = "Mult",
@@ -30,7 +30,7 @@ export declare const enum BinOp {
30
30
  NotIn = "NotIn",
31
31
  Concat = "Concat"
32
32
  }
33
- export declare const enum ExprType {
33
+ export declare enum ExprType {
34
34
  UnOp = "UnOp",
35
35
  BinOp = "BinOp",
36
36
  Field = "Field",
@@ -2,7 +2,6 @@ import { EV, Expr } from './Expr';
2
2
  export declare const Functions: Functions;
3
3
  /** These will have to be supported in every driver */
4
4
  export type Functions = {
5
- arrayLength(x: EV<Array<any>>): Expr<number>;
6
5
  count(x?: Expr<any>): Expr<number>;
7
6
  iif<T>(x: EV<boolean>, y: EV<T>, z: EV<T>): Expr<T>;
8
7
  };
package/dist/OrderBy.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ExprData } from './Expr';
2
- export declare const enum OrderDirection {
2
+ export declare enum OrderDirection {
3
3
  Asc = "Asc",
4
4
  Desc = "Desc"
5
5
  }
package/dist/Param.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const enum ParamType {
1
+ export declare enum ParamType {
2
2
  Value = "Value",
3
3
  Named = "Named"
4
4
  }
package/dist/Query.d.ts CHANGED
@@ -3,7 +3,7 @@ import { ExprData } from './Expr';
3
3
  import { OrderBy } from './OrderBy';
4
4
  import { Index, Schema } from './Schema';
5
5
  import { Target } from './Target';
6
- export declare const enum QueryType {
6
+ export declare enum QueryType {
7
7
  Insert = "Insert",
8
8
  Select = "Select",
9
9
  Update = "Update",
@@ -1,5 +1,5 @@
1
1
  import { Sanitizer } from './Sanitizer';
2
- declare const enum TokenType {
2
+ declare enum TokenType {
3
3
  Raw = "Raw",
4
4
  Identifier = "Identifier",
5
5
  Value = "Value",
package/dist/Target.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ExprData } from './Expr';
2
2
  import { Schema } from './Schema';
3
- export declare const enum TargetType {
3
+ export declare enum TargetType {
4
4
  Each = "Each",
5
5
  Table = "Table",
6
6
  Join = "Join"
@@ -1,4 +1,5 @@
1
- import { Formatter } from '../Formatter';
1
+ import { ExprData } from '../Expr';
2
+ import { FormatContext, Formatter } from '../Formatter';
2
3
  import { Statement } from '../Statement';
3
4
  export declare class SqliteFormatter extends Formatter {
4
5
  escapeValue(value: any): string;
@@ -6,4 +7,5 @@ export declare class SqliteFormatter extends Formatter {
6
7
  escapeString(input: string): string;
7
8
  formatSqlAccess(on: Statement, field: string): Statement;
8
9
  formatJsonAccess(on: Statement, field: string): Statement;
10
+ formatExpr(expr: ExprData, ctx: FormatContext): Statement;
9
11
  }
@@ -1,5 +1,8 @@
1
1
  // src/sqlite/SqliteFormatter.ts
2
+ import { ExprType } from "../Expr.js";
2
3
  import { Formatter } from "../Formatter.js";
4
+ import { identifier } from "../Statement.js";
5
+ import { TargetType } from "../Target.js";
3
6
  function escapeWithin(input, outer) {
4
7
  let buf = outer;
5
8
  for (const char of input) {
@@ -37,6 +40,21 @@ var SqliteFormatter = class extends Formatter {
37
40
  const target = this.formatString(`$.${field}`);
38
41
  return on.raw("->").concat(target);
39
42
  }
43
+ formatExpr(expr, ctx) {
44
+ switch (expr.type) {
45
+ case ExprType.Call:
46
+ if (expr.method === "match") {
47
+ const [from, query] = expr.params;
48
+ if (from.type !== ExprType.Row)
49
+ throw new Error("not implemented");
50
+ if (from.target.type !== TargetType.Table)
51
+ throw new Error("not implemented");
52
+ return identifier(from.target.table.alias || from.target.table.name).raw(" match ").concat(this.formatExprValue(query, ctx));
53
+ }
54
+ default:
55
+ return super.formatExpr(expr, ctx);
56
+ }
57
+ }
40
58
  };
41
59
  export {
42
60
  SqliteFormatter
@@ -1,7 +1,9 @@
1
1
  import { EV, Expr } from '../Expr';
2
+ import { Table } from '../Table';
2
3
  export declare const SqliteFunctions: SqliteFunctions;
3
4
  export type SqliteFunctions = {
4
- arrayLength(x: EV<Array<any>>): Expr<number>;
5
+ /** Use the match operator for the FTS5 module */
6
+ match(table: Table<any>, searchTerm: EV<string>): Expr<boolean>;
5
7
  cast(x: EV<any>, type: 'text'): Expr<string>;
6
8
  cast(x: EV<any>, type: 'real'): Expr<number>;
7
9
  cast(x: EV<any>, type: 'integer'): Expr<number>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {