@livestore/wa-sqlite 1.0.1-dev.14 → 1.0.1-dev.16
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 +1 -1
- package/src/sqlite-api.js +37 -14
- package/src/types/index.d.ts +7 -0
package/package.json
CHANGED
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
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
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
|
-
|
|
937
|
+
rc = await f();
|
|
915
938
|
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
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
|
}
|
package/src/types/index.d.ts
CHANGED
|
@@ -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
|
/**
|
|
@@ -1256,6 +1262,7 @@ declare module '@livestore/wa-sqlite/src/examples/OPFSCoopSyncVFS.js' {
|
|
|
1256
1262
|
import * as VFS from "@livestore/wa-sqlite/src/VFS.js";
|
|
1257
1263
|
export class OPFSCoopSyncVFS extends VFS.Base {
|
|
1258
1264
|
constructor(name: string, module: any)
|
|
1265
|
+
static create(name: string, module: any): Promise<OPFSCoopSyncVFS>;
|
|
1259
1266
|
}
|
|
1260
1267
|
}
|
|
1261
1268
|
|