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

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.17",
3
+ "version": "1.0.1-dev.19",
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
@@ -249,19 +249,53 @@ export function Factory(Module) {
249
249
  };
250
250
  })();
251
251
 
252
+ const SQLITE_SERIALIZE_NOCOPY = 0x0_01
253
+
252
254
  sqlite3.serialize = (function() {
253
255
  const fname = 'sqlite3_serialize';
254
256
  const f = Module.cwrap(fname, ...decl('nsnn:n'));
255
- return function(db, schema, flags) {
257
+ return function(db, schema) {
256
258
  verifyDatabase(db);
257
259
  const piSize = tmpPtr[0];
258
- const address = f(db, schema, piSize, flags);
260
+ let address = f(db, schema, piSize, 0);
261
+ if (address === 0) {
262
+ address = f(db, schema, piSize, SQLITE_SERIALIZE_NOCOPY);
263
+ }
259
264
  const size = Module.getValue(piSize, '*');
260
265
  const result = Module.HEAPU8.subarray(address, address + size);
261
266
  return result;
262
267
  };
263
268
  })();
264
269
 
270
+ // sqlite3.serialize = (function() {
271
+ // const fname = 'sqlite3_serialize';
272
+ // const f = Module.cwrap(fname, ...decl('nsnn:n'));
273
+ // return function(db, schema, flags) {
274
+ // verifyDatabase(db);
275
+ // const piSize = tmpPtr[0];
276
+ // const address = f(db, schema, piSize, flags);
277
+ // const size = Module.getValue(piSize, '*');
278
+ // const result = Module.HEAPU8.subarray(address, address + size);
279
+ // return result;
280
+ // };
281
+ // })();
282
+
283
+ sqlite3.backup = (function() {
284
+ const fInit = Module.cwrap('sqlite3_backup_init', ...decl('nsns:n'));
285
+ const fStep = Module.cwrap('sqlite3_backup_step', ...decl('nn:n'));
286
+ const fFinish = Module.cwrap('sqlite3_backup_finish', ...decl('n:n'));
287
+ return function(dest, destName, source, sourceName) {
288
+ verifyDatabase(dest);
289
+ verifyDatabase(source);
290
+ const backup = fInit(dest, destName, source, sourceName);
291
+ if (backup === 0) {
292
+ throw new SQLiteError('backup failed', SQLite.SQLITE_ERROR);
293
+ }
294
+ fStep(backup, -1);
295
+ return fFinish(backup);
296
+ };
297
+ })();
298
+
265
299
  sqlite3.clear_bindings = (function() {
266
300
  const fname = 'sqlite3_clear_bindings';
267
301
  const f = Module.cwrap(fname, ...decl('n:n'));
@@ -361,9 +361,38 @@ interface SQLiteAPI {
361
361
  serialize(
362
362
  db: number,
363
363
  zSchema: string,
364
- mFlags: number
364
+ // mFlags: number
365
365
  ): Uint8Array;
366
366
 
367
+ // sqlite3_backup *sqlite3_backup_init(
368
+ // sqlite3 *pDest, /* Destination database handle */
369
+ // const char *zDestName, /* Destination database name */
370
+ // sqlite3 *pSource, /* Source database handle */
371
+ // const char *zSourceName /* Source database name */
372
+ // );
373
+ // int sqlite3_backup_step(sqlite3_backup *p, int nPage);
374
+ // int sqlite3_backup_finish(sqlite3_backup *p);
375
+ // int sqlite3_backup_remaining(sqlite3_backup *p);
376
+ // int sqlite3_backup_pagecount(sqlite3_backup *p);
377
+
378
+ backup_init(
379
+ pDest: number,
380
+ zDestName: string,
381
+ pSource: number,
382
+ zSourceName: string
383
+ ): number;
384
+
385
+ backup_step(p: number, nPage: number): number;
386
+ backup_finish(p: number): number;
387
+ backup_remaining(p: number): number;
388
+ backup_pagecount(p: number): number;
389
+
390
+ /**
391
+ * Combines the `backup_init`, `backup_step`, and `backup_finish` functions.
392
+ * @returns `SQLITE_OK` (throws exception on error)
393
+ */
394
+ backup(pDest: number, zDestName: string, pSource: number, zSourceName: string): number;
395
+
367
396
  /**
368
397
  * Reset all bindings on a prepared statement.
369
398
  * @see https://www.sqlite.org/c3ref/clear_bindings.html
@@ -1251,6 +1280,12 @@ declare module '@livestore/wa-sqlite/src/VFS.js' {
1251
1280
  }
1252
1281
  }
1253
1282
 
1283
+ /** @ignore */
1284
+ declare module '@livestore/wa-sqlite/src/FacadeVFS.js' {
1285
+ export type FacadeVFS = any
1286
+ }
1287
+
1288
+
1254
1289
  declare module '@livestore/wa-sqlite/src/examples/AccessHandlePoolVFS.js' {
1255
1290
  import * as VFS from "@livestore/wa-sqlite/src/VFS.js";
1256
1291
  export class AccessHandlePoolVFS extends VFS.Base {