@livestore/wa-sqlite 1.0.1-dev.10 → 1.0.1-dev.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livestore/wa-sqlite",
3
- "version": "1.0.1-dev.10",
3
+ "version": "1.0.1-dev.11",
4
4
  "type": "module",
5
5
  "main": "src/sqlite-api.js",
6
6
  "types": "src/types/index.d.ts",
package/src/sqlite-api.js CHANGED
@@ -458,7 +458,8 @@ export function Factory(Module) {
458
458
  // return SQLite.SQLITE_OK;
459
459
  // };
460
460
  sqlite3.exec = function(db, sql, callback) {
461
- for (const stmt of sqlite3.statements(db, sql)) {
461
+ const { stmts, finalize } = sqlite3.statements(db, sql);
462
+ for (const stmt of stmts) {
462
463
  let columns;
463
464
  while (sqlite3.step(stmt) === SQLite.SQLITE_ROW) {
464
465
  if (callback) {
@@ -468,6 +469,7 @@ export function Factory(Module) {
468
469
  }
469
470
  }
470
471
  }
472
+ finalize();
471
473
  return SQLite.SQLITE_OK;
472
474
  };
473
475
 
@@ -702,10 +704,10 @@ export function Factory(Module) {
702
704
  // { async: true });
703
705
  { async: false });
704
706
 
705
- const results = [];
707
+ const stmts = [];
706
708
 
707
709
  const onFinally = [];
708
- try {
710
+ // try {
709
711
  // Encode SQL string to UTF-8.
710
712
  const utf8 = new TextEncoder().encode(sql);
711
713
 
@@ -767,16 +769,22 @@ export function Factory(Module) {
767
769
  if (stmt) {
768
770
  mapStmtToDB.set(stmt, db);
769
771
  // yield stmt;
770
- results.push(stmt);
772
+ stmts.push(stmt);
771
773
  }
772
774
  } while (stmt);
773
- } finally {
775
+ // } finally {
776
+ // while (onFinally.length) {
777
+ // onFinally.pop()();
778
+ // }
779
+ // }
780
+
781
+ const finalize = () => {
774
782
  while (onFinally.length) {
775
783
  onFinally.pop()();
776
784
  }
777
785
  }
778
786
 
779
- return results;
787
+ return { stmts, finalize };
780
788
  };
781
789
 
782
790
  sqlite3.step = (function() {
@@ -117,11 +117,11 @@ interface SQLiteVFS {
117
117
  }
118
118
 
119
119
  /**
120
- * Options object argument for {@link SQLiteAPI.statements}
120
+ * Options object argument for {@link SQLiteAPI['statements']}
121
121
  */
122
122
  declare interface SQLitePrepareOptions {
123
123
  /**
124
- * Statement handles prepared and yielded by {@link SQLiteAPI.statements}
124
+ * Statement handles prepared and yielded by {@link SQLiteAPI['statements']}
125
125
  * are normally valid only within the scope of an iteration.
126
126
  * Set `unscoped` to `true` to give iterated statements an arbitrary
127
127
  * lifetime.
@@ -760,7 +760,7 @@ interface SQLiteAPI {
760
760
  * @param options
761
761
  */
762
762
  // statements(db: number, sql: string, options?: SQLitePrepareOptions): AsyncIterable<number>;
763
- statements(db: number, sql: string, options?: SQLitePrepareOptions): ReadonlyArray<number>;
763
+ statements(db: number, sql: string, options?: SQLitePrepareOptions): { stmts: ReadonlyArray<number>; finalize: () => void; };
764
764
 
765
765
  /**
766
766
  * Evaluate an SQL statement