@livestore/wa-sqlite 1.0.1-dev.15 → 1.0.1-dev.17

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.15",
3
+ "version": "1.0.1-dev.17",
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
@@ -527,6 +527,28 @@ export function Factory(Module) {
527
527
  })();
528
528
 
529
529
  sqlite3.open_v2 = (function() {
530
+ const fname = 'sqlite3_open_v2';
531
+ const f = Module.cwrap(fname, ...decl('snnn:n'), { async });
532
+ return async function(zFilename, flags, zVfs) {
533
+ flags = flags || SQLite.SQLITE_OPEN_CREATE | SQLite.SQLITE_OPEN_READWRITE;
534
+ zVfs = createUTF8(zVfs);
535
+ try {
536
+ // Allow retry operations.
537
+ const rc = await retry(() => f(zFilename, tmpPtr[0], flags, zVfs));
538
+
539
+ const db = Module.getValue(tmpPtr[0], '*');
540
+ databases.add(db);
541
+
542
+ Module.ccall('RegisterExtensionFunctions', 'void', ['number'], [db]);
543
+ check(fname, rc);
544
+ return db;
545
+ } finally {
546
+ Module._sqlite3_free(zVfs);
547
+ }
548
+ };
549
+ })();
550
+
551
+ sqlite3.open_v2Sync = (function() {
530
552
  const fname = 'sqlite3_open_v2';
531
553
  const f = Module.cwrap(fname, ...decl('snnn:n'), { async });
532
554
  return function(zFilename, flags, zVfs) {
@@ -549,6 +571,7 @@ export function Factory(Module) {
549
571
  };
550
572
  })();
551
573
 
574
+
552
575
  sqlite3.progress_handler = function(db, nProgressOps, handler, userData) {
553
576
  verifyDatabase(db);
554
577
  Module.progress_handler(db, nProgressOps, handler, userData);
@@ -901,22 +924,22 @@ export function Factory(Module) {
901
924
  // This function is used to automatically retry failed calls that
902
925
  // have pending retry operations that should allow the retry to
903
926
  // succeed.
904
- // async function retry(f) {
905
- // let rc;
906
- // do {
907
- // // Wait for all pending retry operations to complete. This is
908
- // // normally empty on the first loop iteration.
909
- // if (Module.retryOps.length) {
910
- // await Promise.all(Module.retryOps);
911
- // Module.retryOps = [];
912
- // }
927
+ async function retry(f) {
928
+ let rc;
929
+ do {
930
+ // Wait for all pending retry operations to complete. This is
931
+ // normally empty on the first loop iteration.
932
+ if (Module.retryOps.length) {
933
+ await Promise.all(Module.retryOps);
934
+ Module.retryOps = [];
935
+ }
913
936
 
914
- // rc = await f();
937
+ rc = await f();
915
938
 
916
- // // Retry on failure with new pending retry operations.
917
- // } while (rc && Module.retryOps.length);
918
- // return rc;
919
- // }
939
+ // Retry on failure with new pending retry operations.
940
+ } while (rc && Module.retryOps.length);
941
+ return rc;
942
+ }
920
943
 
921
944
  return sqlite3;
922
945
  }
@@ -610,6 +610,12 @@ interface SQLiteAPI {
610
610
  zFilename: string,
611
611
  iFlags?: number,
612
612
  zVfs?: string
613
+ ): Promise<number>;
614
+
615
+ open_v2Sync(
616
+ zFilename: string,
617
+ iFlags?: number,
618
+ zVfs?: string
613
619
  ): number;
614
620
 
615
621
  /**
@@ -1249,6 +1255,7 @@ declare module '@livestore/wa-sqlite/src/examples/AccessHandlePoolVFS.js' {
1249
1255
  import * as VFS from "@livestore/wa-sqlite/src/VFS.js";
1250
1256
  export class AccessHandlePoolVFS extends VFS.Base {
1251
1257
  constructor(name: string, module: any)
1258
+ static create(name: string, module: any): Promise<AccessHandlePoolVFS>;
1252
1259
  }
1253
1260
  }
1254
1261