@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 +1 -1
- package/src/sqlite-api.js +14 -6
- package/src/types/index.d.ts +3 -3
package/package.json
CHANGED
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
787
|
+
return { stmts, finalize };
|
|
780
788
|
};
|
|
781
789
|
|
|
782
790
|
sqlite3.step = (function() {
|
package/src/types/index.d.ts
CHANGED
|
@@ -117,11 +117,11 @@ interface SQLiteVFS {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
|
-
* Options object argument for {@link SQLiteAPI
|
|
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
|
|
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
|