@livestore/wa-sqlite 1.0.1-dev.1 → 1.0.1-dev.10

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.1",
3
+ "version": "1.0.1-dev.10",
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
@@ -237,6 +237,31 @@ export function Factory(Module) {
237
237
  };
238
238
  })();
239
239
 
240
+ sqlite3.deserialize = (function() {
241
+ const fname = 'sqlite3_deserialize';
242
+ const f = Module.cwrap(fname, ...decl('nnnnnn:n'));
243
+ return function(db, schema, data, szDb, szBuf, flags) {
244
+ verifyDatabase(db);
245
+ const ptr = Module._sqlite3_malloc(szDb);
246
+ Module.HEAPU8.subarray(ptr).set(data);
247
+ const result = f(db, schema, ptr, szDb, szBuf, flags);
248
+ return result;
249
+ };
250
+ })();
251
+
252
+ sqlite3.serialize = (function() {
253
+ const fname = 'sqlite3_serialize';
254
+ const f = Module.cwrap(fname, ...decl('nsnn:n'));
255
+ return function(db, schema, piSize, flags) {
256
+ verifyDatabase(db);
257
+ // TODO alloc + free memory for result?
258
+ const address = f(db, schema, piSize, flags);
259
+ const result = Module.HEAPU8.subarray(address, address + piSize);
260
+
261
+ return result;
262
+ };
263
+ })();
264
+
240
265
  sqlite3.clear_bindings = (function() {
241
266
  const fname = 'sqlite3_clear_bindings';
242
267
  const f = Module.cwrap(fname, ...decl('n:n'));
@@ -33,7 +33,7 @@ type SQLiteCompatibleType = number|string|Uint8Array|Array<number>|bigint|null;
33
33
  * @see https://sqlite.org/vfs.html
34
34
  * @see https://sqlite.org/c3ref/io_methods.html
35
35
  */
36
- declare interface SQLiteVFS {
36
+ interface SQLiteVFS {
37
37
  /** Maximum length of a file path in UTF-8 bytes (default 64) */
38
38
  mxPathName?: number;
39
39
 
@@ -178,7 +178,7 @@ declare interface SQLitePrepareOptions {
178
178
  *
179
179
  * @see https://sqlite.org/c3ref/funclist.html
180
180
  */
181
- declare interface SQLiteAPI {
181
+ interface SQLiteAPI {
182
182
  /**
183
183
  * Bind a collection of values to a statement
184
184
  *
@@ -330,6 +330,41 @@ declare interface SQLiteAPI {
330
330
  */
331
331
  changes(db): number;
332
332
 
333
+ /**
334
+ * https://www.sqlite.org/c3ref/deserialize.html
335
+ * int sqlite3_deserialize(
336
+ * sqlite3 *db, The database connection
337
+ * const char *zSchema, Which DB to reopen with the deserialization
338
+ * unsigned char *pData, The serialized database content
339
+ * sqlite3_int64 szDb, Number bytes in the deserialization
340
+ * sqlite3_int64 szBuf, Total size of buffer pData[]
341
+ * unsigned mFlags Zero or more SQLITE_DESERIALIZE_* flags
342
+ * );
343
+ */
344
+ deserialize(
345
+ db: number,
346
+ zSchema: string,
347
+ pData: Uint8Array,
348
+ szDb: number,
349
+ szBuf: number,
350
+ mFlags: number
351
+ ): number;
352
+
353
+ /**
354
+ * unsigned char *sqlite3_serialize(
355
+ * sqlite3 *db, The database connection
356
+ * const char *zSchema, Which DB to serialize. ex: "main", "temp", ...
357
+ * sqlite3_int64 *piSize, Write size of the DB here, if not NULL
358
+ * unsigned int mFlags Zero or more SQLITE_SERIALIZE_* flags
359
+ * );
360
+ */
361
+ serialize(
362
+ db: number,
363
+ zSchema: string,
364
+ piSize: number,
365
+ mFlags: number
366
+ ): Uint8Array;
367
+
333
368
  /**
334
369
  * Reset all bindings on a prepared statement.
335
370
  * @see https://www.sqlite.org/c3ref/clear_bindings.html
@@ -576,7 +611,7 @@ declare interface SQLiteAPI {
576
611
  zFilename: string,
577
612
  iFlags?: number,
578
613
  zVfs?: string
579
- ): Promise<number>;
614
+ ): number;
580
615
 
581
616
  /**
582
617
  * Specify callback to be invoked between long-running queries
@@ -596,9 +631,9 @@ declare interface SQLiteAPI {
596
631
  * Reset a prepared statement object
597
632
  * @see https://www.sqlite.org/c3ref/reset.html
598
633
  * @param stmt prepared statement pointer
599
- * @returns Promise-wrapped `SQLITE_OK` (rejects on error)
634
+ * @returns `SQLITE_OK` (rejects on error)
600
635
  */
601
- reset(stmt: number): Promise<number>;
636
+ reset(stmt: number): number;
602
637
 
603
638
  /**
604
639
  * Convenience function to call `result_*` based of the type of `value`
@@ -725,7 +760,7 @@ declare interface SQLiteAPI {
725
760
  * @param options
726
761
  */
727
762
  // statements(db: number, sql: string, options?: SQLitePrepareOptions): AsyncIterable<number>;
728
- statements(db: number, sql: string, options?: SQLitePrepareOptions): Iterable<number>;
763
+ statements(db: number, sql: string, options?: SQLitePrepareOptions): ReadonlyArray<number>;
729
764
 
730
765
  /**
731
766
  * Evaluate an SQL statement
@@ -822,6 +857,11 @@ declare interface SQLiteAPI {
822
857
  vfs_register(vfs: SQLiteVFS, makeDefault?: boolean): number;
823
858
  }
824
859
 
860
+ declare module '@livestore/wa-sqlite' {
861
+ export type SQLiteAPI_ = SQLiteAPI;
862
+ export type SQLiteVFS_ = SQLiteVFS;
863
+ }
864
+
825
865
  /** @ignore */
826
866
  declare module '@livestore/wa-sqlite/src/sqlite-constants.js' {
827
867
  export const SQLITE_OK: 0;
@@ -1094,6 +1134,7 @@ declare module '@livestore/wa-sqlite/src/VFS.js' {
1094
1134
  export * from '@livestore/wa-sqlite/src/sqlite-constants.js';
1095
1135
 
1096
1136
  export class Base {
1137
+ name: string;
1097
1138
  mxPathName: number;
1098
1139
  /**
1099
1140
  * @param {number} fileId
@@ -1205,9 +1246,16 @@ declare module '@livestore/wa-sqlite/src/VFS.js' {
1205
1246
  }
1206
1247
  }
1207
1248
 
1249
+ declare module '@livestore/wa-sqlite/src/examples/AccessHandlePoolVFS.js' {
1250
+ import * as VFS from "@livestore/wa-sqlite/src/VFS.js";
1251
+ export class AccessHandlePoolVFS extends VFS.Base {
1252
+ constructor(name: string, module: any)
1253
+ }
1254
+ }
1255
+
1208
1256
  /** @ignore */
1209
1257
  declare module '@livestore/wa-sqlite/src/examples/IndexedDbVFS.js' {
1210
- import * as VFS from "wa-sqlite/src/VFS.js";
1258
+ import * as VFS from "@livestore/wa-sqlite/src/VFS.js";
1211
1259
  export class IndexedDbVFS extends VFS.Base {
1212
1260
  /**
1213
1261
  * @param {string} idbName Name of IndexedDB database.
@@ -1261,7 +1309,7 @@ declare module '@livestore/wa-sqlite/src/examples/IndexedDbVFS.js' {
1261
1309
 
1262
1310
  /** @ignore */
1263
1311
  declare module '@livestore/wa-sqlite/src/examples/MemoryVFS.js' {
1264
- import * as VFS from "wa-sqlite/src/VFS.js";
1312
+ import * as VFS from "@livestore/wa-sqlite/src/VFS.js";
1265
1313
  /** @ignore */
1266
1314
  export class MemoryVFS extends VFS.Base {
1267
1315
  name: string;
@@ -1272,7 +1320,7 @@ declare module '@livestore/wa-sqlite/src/examples/MemoryVFS.js' {
1272
1320
 
1273
1321
  /** @ignore */
1274
1322
  declare module '@livestore/wa-sqlite/src/examples/MemoryAsyncVFS.js' {
1275
- import { MemoryVFS } from "wa-sqlite/src/examples/MemoryVFS.js";
1323
+ import { MemoryVFS } from "@livestore/wa-sqlite/src/examples/MemoryVFS.js";
1276
1324
  export class MemoryAsyncVFS extends MemoryVFS {
1277
1325
  }
1278
1326
  }