rado 0.4.5 → 0.4.7

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.
@@ -13,7 +13,10 @@ export declare class D1Driver extends Driver.Async {
13
13
  executeQuery(query: QueryData, stmt?: Driver.Async.PreparedStatement, params?: any[] | undefined): Promise<unknown>;
14
14
  prepareStatement(stmt: Statement): Driver.Async.PreparedStatement;
15
15
  schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
16
- isolate(): [connection: Driver.Async, release: () => Promise<void>];
16
+ isolate(): Promise<[
17
+ connection: Driver.Async,
18
+ release: () => Promise<void>
19
+ ]>;
17
20
  close(): Promise<void>;
18
21
  }
19
22
  export declare function connect(db: D1Database, options?: DriverOptions): D1Driver;
package/dist/driver/d1.js CHANGED
@@ -48,12 +48,14 @@ class D1Driver extends Driver.Async {
48
48
  const indexData = await this.indexData(tableName);
49
49
  return SqliteSchema.createInstructions(columnData, indexData);
50
50
  }
51
- isolate() {
51
+ async isolate() {
52
+ const currentLock = this.lock;
52
53
  const connection = new D1Driver(this.db);
53
54
  let release, trigger = new Promise((resolve) => {
54
55
  release = async () => resolve();
55
56
  });
56
- this.lock = Promise.resolve(this.lock).then(() => trigger);
57
+ this.lock = Promise.resolve(currentLock).then(() => trigger);
58
+ await currentLock;
57
59
  return [connection, release];
58
60
  }
59
61
  async close() {
@@ -13,7 +13,10 @@ export declare class Sqlite3Driver extends Driver.Async {
13
13
  executeQuery(query: QueryData, stmt?: Driver.Async.PreparedStatement, params?: any[] | undefined): Promise<unknown>;
14
14
  prepareStatement(stmt: Statement): Driver.Async.PreparedStatement;
15
15
  schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
16
- isolate(): [connection: Driver.Async, release: () => Promise<void>];
16
+ isolate(): Promise<[
17
+ connection: Driver.Async,
18
+ release: () => Promise<void>
19
+ ]>;
17
20
  close(): Promise<void>;
18
21
  }
19
22
  export declare function connect(db: Database, options?: DriverOptions): Sqlite3Driver;
@@ -101,12 +101,14 @@ class Sqlite3Driver extends Driver.Async {
101
101
  const indexData = await this.indexData(tableName);
102
102
  return SqliteSchema.createInstructions(columnData, indexData);
103
103
  }
104
- isolate() {
104
+ async isolate() {
105
+ const currentLock = this.lock;
105
106
  const connection = new Sqlite3Driver(this.db);
106
107
  let release, trigger = new Promise((resolve) => {
107
108
  release = async () => resolve();
108
109
  });
109
- this.lock = Promise.resolve(this.lock).then(() => trigger);
110
+ this.lock = Promise.resolve(currentLock).then(() => trigger);
111
+ await currentLock;
110
112
  return [connection, release];
111
113
  }
112
114
  async close() {
@@ -59,7 +59,10 @@ declare abstract class AsyncDriver extends DriverBase {
59
59
  transactionId: number;
60
60
  constructor(formatter: Formatter, options?: DriverOptions);
61
61
  abstract close(): Promise<void>;
62
- abstract isolate(): [connection: AsyncDriver, release: () => Promise<void>];
62
+ abstract isolate(): Promise<[
63
+ connection: AsyncDriver,
64
+ release: () => Promise<void>
65
+ ]>;
63
66
  abstract prepareStatement(stmt: Statement, discardAfter: boolean): AsyncPreparedStatement;
64
67
  abstract schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
65
68
  createStatement(stmt: Statement, discardAfter: boolean): AsyncPreparedStatement;
@@ -78,7 +81,10 @@ declare class SyncWrapper extends AsyncDriver {
78
81
  executeQuery(query: QueryData, stmt?: AsyncPreparedStatement, params?: Array<any>): Promise<unknown>;
79
82
  prepareStatement(stmt: Statement, discardAfter: boolean): AsyncPreparedStatement;
80
83
  schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
81
- isolate(): [connection: AsyncDriver, release: () => Promise<void>];
84
+ isolate(): Promise<[
85
+ connection: AsyncDriver,
86
+ release: () => Promise<void>
87
+ ]>;
82
88
  }
83
89
  interface AsyncPreparedStatement {
84
90
  run(params: Array<any>): Promise<{
@@ -307,8 +307,8 @@ class AsyncDriver extends DriverBase {
307
307
  }
308
308
  }
309
309
  async transaction(run) {
310
+ const [connection, release] = await this.isolate();
310
311
  const id = `t${this.transactionId++}`;
311
- const [connection, release] = this.isolate();
312
312
  await connection.executeQuery(
313
313
  new QueryData.Transaction({ op: QueryData.TransactionOperation.Begin, id })
314
314
  );
@@ -377,12 +377,14 @@ class SyncWrapper extends AsyncDriver {
377
377
  async schemaInstructions(tableName) {
378
378
  return this.sync.schemaInstructions(tableName);
379
379
  }
380
- isolate() {
380
+ async isolate() {
381
+ const currentLock = this.lock;
381
382
  const connection = new SyncWrapper(this.sync);
382
383
  let release, trigger = new Promise((resolve) => {
383
384
  release = async () => resolve();
384
385
  });
385
- this.lock = Promise.resolve(this.lock).then(() => trigger);
386
+ this.lock = Promise.resolve(currentLock).then(() => trigger);
387
+ await currentLock;
386
388
  return [connection, release];
387
389
  }
388
390
  }
@@ -49,6 +49,7 @@ class SqliteFormatter extends Formatter {
49
49
  stmt.raw(" MATCH ");
50
50
  this.formatExprValue(ctx, query);
51
51
  return stmt;
52
+ case "bm25":
52
53
  case "highlight":
53
54
  case "snippet":
54
55
  stmt.identifier(expr.method);
@@ -13,6 +13,8 @@ export type SqliteFunctions = {
13
13
  exists(cursor: Query<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
+ /** Returns a real value reflecting the accuracy of the current match */
17
+ bm25(table: Table<any>, ...weights: Array<EV<number>>): Expr<number>;
16
18
  /** 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
19
  highlight(table: Table<any>, index: EV<number>, insertBefore: EV<string>, insertAfter: EV<string>): Expr<string>;
18
20
  /** 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. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",