rado 0.1.36 → 0.1.37

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;
@@ -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>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "0.1.36",
3
+ "version": "0.1.37",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {