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

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.11",
3
+ "version": "1.0.1-dev.13",
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
@@ -252,12 +252,12 @@ export function Factory(Module) {
252
252
  sqlite3.serialize = (function() {
253
253
  const fname = 'sqlite3_serialize';
254
254
  const f = Module.cwrap(fname, ...decl('nsnn:n'));
255
- return function(db, schema, piSize, flags) {
255
+ return function(db, schema, flags) {
256
256
  verifyDatabase(db);
257
- // TODO alloc + free memory for result?
257
+ const piSize = tmpPtr[0];
258
258
  const address = f(db, schema, piSize, flags);
259
- const result = Module.HEAPU8.subarray(address, address + piSize);
260
-
259
+ const size = Module.getValue(piSize, '*');
260
+ const result = Module.HEAPU8.subarray(address, address + size);
261
261
  return result;
262
262
  };
263
263
  })();
@@ -458,7 +458,7 @@ export function Factory(Module) {
458
458
  // return SQLite.SQLITE_OK;
459
459
  // };
460
460
  sqlite3.exec = function(db, sql, callback) {
461
- const { stmts, finalize } = sqlite3.statements(db, sql);
461
+ const stmts = sqlite3.statements(db, sql);
462
462
  for (const stmt of stmts) {
463
463
  let columns;
464
464
  while (sqlite3.step(stmt) === SQLite.SQLITE_ROW) {
@@ -469,7 +469,9 @@ export function Factory(Module) {
469
469
  }
470
470
  }
471
471
  }
472
- finalize();
472
+ for (const stmt of stmts) {
473
+ sqlite3.finalize(stmt);
474
+ }
473
475
  return SQLite.SQLITE_OK;
474
476
  };
475
477
 
@@ -778,13 +780,7 @@ export function Factory(Module) {
778
780
  // }
779
781
  // }
780
782
 
781
- const finalize = () => {
782
- while (onFinally.length) {
783
- onFinally.pop()();
784
- }
785
- }
786
-
787
- return { stmts, finalize };
783
+ return stmts;
788
784
  };
789
785
 
790
786
  sqlite3.step = (function() {
@@ -361,7 +361,6 @@ interface SQLiteAPI {
361
361
  serialize(
362
362
  db: number,
363
363
  zSchema: string,
364
- piSize: number,
365
364
  mFlags: number
366
365
  ): Uint8Array;
367
366
 
@@ -760,7 +759,7 @@ interface SQLiteAPI {
760
759
  * @param options
761
760
  */
762
761
  // statements(db: number, sql: string, options?: SQLitePrepareOptions): AsyncIterable<number>;
763
- statements(db: number, sql: string, options?: SQLitePrepareOptions): { stmts: ReadonlyArray<number>; finalize: () => void; };
762
+ statements(db: number, sql: string, options?: SQLitePrepareOptions): ReadonlyArray<number>;
764
763
 
765
764
  /**
766
765
  * Evaluate an SQL statement