rado 0.1.36 → 0.1.38

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.
@@ -8,7 +8,15 @@ import { Target } from './Target';
8
8
  export interface FormatContext {
9
9
  stmt: Statement;
10
10
  nameResult?: string;
11
+ /** Skip prefixing fields with their table name */
11
12
  skipTableName?: boolean;
13
+ /**
14
+ * In SQLite table names are used as expressions in the FTS5 plugin.
15
+ * To distinguish between formatting a row of the table and just the table name
16
+ * this flag can be used.
17
+ **/
18
+ tableAsExpr?: boolean;
19
+ /** Inline all parameters */
12
20
  forceInline?: boolean;
13
21
  formatAsJson?: boolean;
14
22
  formatSubject?: (mkSubject: () => void) => void;
@@ -30,7 +38,7 @@ export declare abstract class Formatter implements Sanitizer {
30
38
  formatDropIndex(ctx: FormatContext, query: Query.DropIndex): Statement;
31
39
  formatAlterTable(ctx: FormatContext, query: Query.AlterTable): Statement;
32
40
  formatTransaction(ctx: FormatContext, { op, id }: Query.Transaction): Statement;
33
- formatBatch(ctx: FormatContext, queries: Query[]): Statement;
41
+ formatBatch(ctx: FormatContext, { queries }: Query.Batch): Statement;
34
42
  formatRaw(ctx: FormatContext, { strings, params }: Query.Raw): Statement;
35
43
  formatColumn(ctx: FormatContext, column: ColumnData): Statement;
36
44
  formatContraintReference(ctx: FormatContext, reference: ExprData): Statement;
@@ -71,7 +71,7 @@ var Formatter = class {
71
71
  case QueryType.Transaction:
72
72
  return this.formatTransaction(ctx, query);
73
73
  case QueryType.Batch:
74
- return this.formatBatch(ctx, query.queries);
74
+ return this.formatBatch(ctx, query);
75
75
  case QueryType.Raw:
76
76
  return this.formatRaw(ctx, query);
77
77
  }
@@ -198,7 +198,7 @@ var Formatter = class {
198
198
  return stmt.raw("ROLLBACK TO").addIdentifier(id);
199
199
  }
200
200
  }
201
- formatBatch(ctx, queries) {
201
+ formatBatch(ctx, { queries }) {
202
202
  const { stmt } = ctx;
203
203
  for (const query of stmt.separate(queries, ";"))
204
204
  this.format(ctx, query);
@@ -574,6 +574,8 @@ var Formatter = class {
574
574
  const table = Target.source(expr.target);
575
575
  if (!table)
576
576
  throw new Error(`Cannot select empty target`);
577
+ if (ctx.tableAsExpr)
578
+ return stmt.identifier(table.alias || table.name);
577
579
  return this.formatExpr(
578
580
  ctx,
579
581
  ExprData.Record(
@@ -1,7 +1,6 @@
1
1
  // src/sqlite/SqliteFormatter.ts
2
2
  import { ExprType } from "../lib/Expr.js";
3
3
  import { Formatter } from "../lib/Formatter.js";
4
- import { TargetType } from "../lib/Target.js";
5
4
  function escapeWithin(input, outer) {
6
5
  let buf = outer;
7
6
  for (const char of input) {
@@ -52,15 +51,19 @@ var SqliteFormatter = class extends Formatter {
52
51
  const { stmt } = ctx;
53
52
  switch (expr.type) {
54
53
  case ExprType.Call:
55
- if (expr.method === "match") {
56
- const [from, query] = expr.params;
57
- if (from.type !== ExprType.Row)
58
- throw new Error("not implemented");
59
- if (from.target.type !== TargetType.Table)
60
- throw new Error("not implemented");
61
- stmt.identifier(from.target.table.alias || from.target.table.name).raw(" MATCH ");
62
- this.formatExprValue(ctx, query);
63
- return stmt;
54
+ switch (expr.method) {
55
+ case "match":
56
+ const [from, query] = expr.params;
57
+ this.formatExprValue({ ...ctx, tableAsExpr: true }, from);
58
+ stmt.raw(" MATCH ");
59
+ this.formatExprValue(ctx, query);
60
+ return stmt;
61
+ case "highlight":
62
+ case "snippet":
63
+ stmt.identifier(expr.method);
64
+ for (const param of stmt.call(expr.params))
65
+ this.formatExprValue({ ...ctx, tableAsExpr: true }, param);
66
+ return stmt;
64
67
  }
65
68
  default:
66
69
  return super.formatExpr(ctx, expr);
@@ -13,6 +13,10 @@ export type SqliteFunctions = {
13
13
  exists(cursor: Cursor<any>): Expr<boolean>;
14
14
  /** Use the match operator for the FTS5 module */
15
15
  match(table: Table<any>, searchTerm: EV<string>): Expr<boolean>;
16
+ /** The highlight() function returns a copy of the text from a specified column of the current row with extra markup text inserted to mark the start and end of phrase matches. */
17
+ highlight(table: Table<any>, index: EV<number>, insertBefore: EV<string>, insertAfter: EV<string>): Expr<string>;
18
+ /** The snippet() function is similar to highlight(), except that instead of returning entire column values, it automatically selects and extracts a short fragment of document text to process and return. */
19
+ snippet(table: Table<any>, index: EV<number>, insertBefore: EV<string>, insertAfter: EV<string>, snip: EV<string>, maxTokens: EV<number>): Expr<string>;
16
20
  cast(x: EV<any>, type: 'text'): Expr<string>;
17
21
  cast(x: EV<any>, type: 'real'): Expr<number>;
18
22
  cast(x: EV<any>, type: 'integer'): Expr<number>;
@@ -153,7 +157,7 @@ export type SqliteFunctions = {
153
157
  julianday(timeValue: EV<any>, ...rest: Array<EV<string>>): Expr<string>;
154
158
  strftime(format: EV<string>, timeValue: EV<any>, ...rest: Array<EV<string>>): Expr<string>;
155
159
  };
156
- export declare const count: (x?: Expr<any>) => Expr<number>, iif: <T>(x: EV<boolean>, y: EV<T>, z: EV<T>) => Expr<T>, exists: (cursor: Cursor<any>) => Expr<boolean>, match: (table: Table<any>, searchTerm: EV<string>) => Expr<boolean>, cast: {
160
+ export declare const count: (x?: Expr<any>) => Expr<number>, iif: <T>(x: EV<boolean>, y: EV<T>, z: EV<T>) => Expr<T>, exists: (cursor: Cursor<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: {
157
161
  (x: EV<any>, type: 'text'): Expr<string>;
158
162
  (x: EV<any>, type: 'real'): Expr<number>;
159
163
  (x: EV<any>, type: 'integer'): Expr<number>;
@@ -6,6 +6,8 @@ var {
6
6
  iif,
7
7
  exists,
8
8
  match,
9
+ highlight,
10
+ snippet,
9
11
  cast,
10
12
  abs,
11
13
  changes,
@@ -98,6 +100,7 @@ export {
98
100
  exp,
99
101
  floor,
100
102
  group_concat,
103
+ highlight,
101
104
  ifnull,
102
105
  iif,
103
106
  instr,
@@ -128,6 +131,7 @@ export {
128
131
  sign,
129
132
  sin,
130
133
  sinh,
134
+ snippet,
131
135
  soundex,
132
136
  sqlite_version,
133
137
  sqrt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "0.1.36",
3
+ "version": "0.1.38",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {