expo-sqlite 16.0.1 → 16.0.3

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/android/build.gradle +2 -2
  3. package/build/SQLiteDatabase.d.ts +21 -0
  4. package/build/SQLiteDatabase.d.ts.map +1 -1
  5. package/build/SQLiteDatabase.js +21 -0
  6. package/build/SQLiteDatabase.js.map +1 -1
  7. package/build/Storage.d.ts +16 -0
  8. package/build/Storage.d.ts.map +1 -1
  9. package/build/Storage.js +43 -0
  10. package/build/Storage.js.map +1 -1
  11. package/build/WebStorage.d.ts +22 -0
  12. package/build/WebStorage.d.ts.map +1 -0
  13. package/build/WebStorage.js +84 -0
  14. package/build/WebStorage.js.map +1 -0
  15. package/build/paramUtils.d.ts +6 -0
  16. package/build/paramUtils.d.ts.map +1 -1
  17. package/build/paramUtils.js +20 -0
  18. package/build/paramUtils.js.map +1 -1
  19. package/expo-module.config.json +1 -1
  20. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{16.0.1/expo.modules.sqlite-16.0.1.module → 16.0.3/expo.modules.sqlite-16.0.3.module} +7 -7
  21. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/16.0.3/expo.modules.sqlite-16.0.3.module.md5 +1 -0
  22. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/16.0.3/expo.modules.sqlite-16.0.3.module.sha1 +1 -0
  23. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/16.0.3/expo.modules.sqlite-16.0.3.module.sha256 +1 -0
  24. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/16.0.3/expo.modules.sqlite-16.0.3.module.sha512 +1 -0
  25. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{16.0.1/expo.modules.sqlite-16.0.1.pom → 16.0.3/expo.modules.sqlite-16.0.3.pom} +1 -1
  26. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/16.0.3/expo.modules.sqlite-16.0.3.pom.md5 +1 -0
  27. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/16.0.3/expo.modules.sqlite-16.0.3.pom.sha1 +1 -0
  28. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/16.0.3/expo.modules.sqlite-16.0.3.pom.sha256 +1 -0
  29. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/16.0.3/expo.modules.sqlite-16.0.3.pom.sha512 +1 -0
  30. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/maven-metadata.xml +4 -4
  31. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/maven-metadata.xml.md5 +1 -1
  32. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/maven-metadata.xml.sha1 +1 -1
  33. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/maven-metadata.xml.sha256 +1 -1
  34. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/maven-metadata.xml.sha512 +1 -1
  35. package/localStorage/install.js +4 -0
  36. package/package.json +9 -4
  37. package/src/SQLiteDatabase.ts +21 -0
  38. package/src/Storage.ts +47 -1
  39. package/src/WebStorage.ts +94 -0
  40. package/src/paramUtils.ts +22 -0
  41. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/16.0.1/expo.modules.sqlite-16.0.1.module.md5 +0 -1
  42. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/16.0.1/expo.modules.sqlite-16.0.1.module.sha1 +0 -1
  43. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/16.0.1/expo.modules.sqlite-16.0.1.module.sha256 +0 -1
  44. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/16.0.1/expo.modules.sqlite-16.0.1.module.sha512 +0 -1
  45. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/16.0.1/expo.modules.sqlite-16.0.1.pom.md5 +0 -1
  46. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/16.0.1/expo.modules.sqlite-16.0.1.pom.sha1 +0 -1
  47. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/16.0.1/expo.modules.sqlite-16.0.1.pom.sha256 +0 -1
  48. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/16.0.1/expo.modules.sqlite-16.0.1.pom.sha512 +0 -1
  49. /package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{16.0.1/expo.modules.sqlite-16.0.1-sources.jar → 16.0.3/expo.modules.sqlite-16.0.3-sources.jar} +0 -0
  50. /package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{16.0.1/expo.modules.sqlite-16.0.1-sources.jar.md5 → 16.0.3/expo.modules.sqlite-16.0.3-sources.jar.md5} +0 -0
  51. /package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{16.0.1/expo.modules.sqlite-16.0.1-sources.jar.sha1 → 16.0.3/expo.modules.sqlite-16.0.3-sources.jar.sha1} +0 -0
  52. /package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{16.0.1/expo.modules.sqlite-16.0.1-sources.jar.sha256 → 16.0.3/expo.modules.sqlite-16.0.3-sources.jar.sha256} +0 -0
  53. /package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{16.0.1/expo.modules.sqlite-16.0.1-sources.jar.sha512 → 16.0.3/expo.modules.sqlite-16.0.3-sources.jar.sha512} +0 -0
  54. /package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{16.0.1/expo.modules.sqlite-16.0.1.aar → 16.0.3/expo.modules.sqlite-16.0.3.aar} +0 -0
  55. /package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{16.0.1/expo.modules.sqlite-16.0.1.aar.md5 → 16.0.3/expo.modules.sqlite-16.0.3.aar.md5} +0 -0
  56. /package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{16.0.1/expo.modules.sqlite-16.0.1.aar.sha1 → 16.0.3/expo.modules.sqlite-16.0.3.aar.sha1} +0 -0
  57. /package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{16.0.1/expo.modules.sqlite-16.0.1.aar.sha256 → 16.0.3/expo.modules.sqlite-16.0.3.aar.sha256} +0 -0
  58. /package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{16.0.1/expo.modules.sqlite-16.0.1.aar.sha512 → 16.0.3/expo.modules.sqlite-16.0.3.aar.sha512} +0 -0
package/CHANGELOG.md CHANGED
@@ -10,6 +10,16 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 16.0.3 — 2025-08-18
14
+
15
+ ### 💡 Others
16
+
17
+ - Updated API doc for `loadExtensionAsync()` and `loadExtensionSync()`. ([#38905](https://github.com/expo/expo/pull/38905) by [@kudo](https://github.com/kudo))
18
+
19
+ ## 16.0.2 — 2025-08-16
20
+
21
+ _This version does not introduce any user-facing changes._
22
+
13
23
  ## 16.0.1 — 2025-08-15
14
24
 
15
25
  _This version does not introduce any user-facing changes._
@@ -20,6 +30,7 @@ _This version does not introduce any user-facing changes._
20
30
 
21
31
  - [iOS] Support Apple TV. ([#38475](https://github.com/expo/expo/pull/38475) by [@douglowder](https://github.com/douglowder))
22
32
  - Added `loadExtensionAsync` / `loadExtensionSync` APIs and pre-bundled [sqlite-vec](https://github.com/asg017/sqlite-vec) extension. ([#38693](https://github.com/expo/expo/pull/38693) by [@kudo](https://github.com/kudo))
33
+ - Added `expo-sqlite/localStorage/install` for [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) drop-in replacement API. ([#38699](https://github.com/expo/expo/pull/38699) by [@kudo](https://github.com/kudo))
23
34
 
24
35
  ### 🐛 Bug fixes
25
36
 
@@ -46,13 +46,13 @@ def reactNativeArchitectures() {
46
46
  }
47
47
 
48
48
  group = 'host.exp.exponent'
49
- version = '16.0.1'
49
+ version = '16.0.3'
50
50
 
51
51
  android {
52
52
  namespace "expo.modules.sqlite"
53
53
  defaultConfig {
54
54
  versionCode 18
55
- versionName "16.0.1"
55
+ versionName "16.0.3"
56
56
  buildConfigField "boolean", "USE_LIBSQL", project.ext.USE_LIBSQL.toString()
57
57
  buildConfigField "boolean", "WITH_SQLITE_VEC", project.ext.WITH_SQLITE_VEC.toString()
58
58
 
@@ -53,6 +53,16 @@ export declare class SQLiteDatabase {
53
53
  * @platform ios
54
54
  * @platform macos
55
55
  * @platform tvos
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * // Load `sqlite-vec` from `bundledExtensions`. You need to enable `withSQLiteVecExtension` to include `sqlite-vec`.
60
+ * const extension = SQLite.bundledExtensions['sqlite-vec'];
61
+ * await db.loadExtensionAsync(extension.libPath, extension.entryPoint);
62
+ *
63
+ * // You can also load a custom extension.
64
+ * await db.loadExtensionAsync('/path/to/extension');
65
+ * ```
56
66
  */
57
67
  loadExtensionAsync(libPath: string, entryPoint?: string): Promise<void>;
58
68
  /**
@@ -157,6 +167,17 @@ export declare class SQLiteDatabase {
157
167
  * @platform ios
158
168
  * @platform macos
159
169
  * @platform tvos
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * // Load `sqlite-vec` from `bundledExtensions`. You need to enable `withSQLiteVecExtension` to include `sqlite-vec`.
174
+ * const extension = SQLite.bundledExtensions['sqlite-vec'];
175
+ * db.loadExtensionSync(extension.libPath, extension.entryPoint);
176
+ *
177
+ * // You can also load a custom extension.
178
+ * db.loadExtensionSync('/path/to/extension');
179
+ * ```
180
+
160
181
  */
161
182
  loadExtensionSync(libPath: string, entryPoint?: string): void;
162
183
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"SQLiteDatabase.d.ts","sourceRoot":"","sources":["../src/SQLiteDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAI3D,OAAO,EAAsB,cAAc,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,gBAAgB,EAGhB,eAAe,EACf,eAAe,EACf,wBAAwB,EACzB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,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C7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,IAAI,CAOP;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,+HAA+H;IAC/H,YAAY,EAAE,MAAM,CAAC;IAErB,8CAA8C;IAC9C,gBAAgB,EAAE,MAAM,CAAC;IAEzB,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC;IAElB,0BAA0B;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,GAC7C,iBAAiB,CAEnB;AAED;;;GAGG;AACH,cAAM,WAAY,SAAQ,cAAc;WAClB,WAAW,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC;CAS1E"}
@@ -74,6 +74,16 @@ export class SQLiteDatabase {
74
74
  * @platform ios
75
75
  * @platform macos
76
76
  * @platform tvos
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * // Load `sqlite-vec` from `bundledExtensions`. You need to enable `withSQLiteVecExtension` to include `sqlite-vec`.
81
+ * const extension = SQLite.bundledExtensions['sqlite-vec'];
82
+ * await db.loadExtensionAsync(extension.libPath, extension.entryPoint);
83
+ *
84
+ * // You can also load a custom extension.
85
+ * await db.loadExtensionAsync('/path/to/extension');
86
+ * ```
77
87
  */
78
88
  loadExtensionAsync(libPath, entryPoint) {
79
89
  return this.nativeDatabase.loadExtensionAsync(libPath, entryPoint);
@@ -227,6 +237,17 @@ export class SQLiteDatabase {
227
237
  * @platform ios
228
238
  * @platform macos
229
239
  * @platform tvos
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * // Load `sqlite-vec` from `bundledExtensions`. You need to enable `withSQLiteVecExtension` to include `sqlite-vec`.
244
+ * const extension = SQLite.bundledExtensions['sqlite-vec'];
245
+ * db.loadExtensionSync(extension.libPath, extension.entryPoint);
246
+ *
247
+ * // You can also load a custom extension.
248
+ * db.loadExtensionSync('/path/to/extension');
249
+ * ```
250
+
230
251
  */
231
252
  loadExtensionSync(libPath, entryPoint) {
232
253
  this.nativeDatabase.loadExtensionSync(libPath, entryPoint);
@@ -1 +1 @@
1
- {"version":3,"file":"SQLiteDatabase.js","sourceRoot":"","sources":["../src/SQLiteDatabase.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,UAAU,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAqC,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAKL,eAAe,GAEhB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAIjD;;GAEG;AACH,MAAM,OAAO,cAAc;IAEP;IACA;IACA;IAHlB,YACkB,YAAoB,EACpB,OAA0B,EAC1B,cAA8B;QAF9B,iBAAY,GAAZ,YAAY,CAAQ;QACpB,YAAO,GAAP,OAAO,CAAmB;QAC1B,mBAAc,GAAd,cAAc,CAAgB;IAC7C,CAAC;IAEJ;;OAEG;IACI,oBAAoB;QACzB,OAAO,IAAI,CAAC,cAAc,CAAC,oBAAoB,EAAE,CAAC;IACpD,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,MAAc;QAC7B,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;IAED;;;;OAIG;IACI,cAAc,CAAC,eAAuB,MAAM;QACjD,OAAO,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;IAC1D,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,YAAY,CAAC,MAAc;QACtC,MAAM,eAAe,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,CAAC,YAAY,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;IACnE,CAAC;CACF","sourcesContent":["import { type EventSubscription } from 'expo-modules-core';\nimport { Platform } from 'react-native';\n\nimport ExpoSQLite from './ExpoSQLite';\nimport { flattenOpenOptions, NativeDatabase, SQLiteOpenOptions } from './NativeDatabase';\nimport { SQLiteSession } from './SQLiteSession';\nimport {\n SQLiteBindParams,\n SQLiteExecuteAsyncResult,\n SQLiteExecuteSyncResult,\n SQLiteRunResult,\n SQLiteStatement,\n SQLiteVariadicBindParams,\n} from './SQLiteStatement';\nimport { createDatabasePath } from './pathUtils';\n\nexport { SQLiteOpenOptions };\n\n/**\n * A SQLite database.\n */\nexport class SQLiteDatabase {\n constructor(\n public readonly databasePath: string,\n public readonly options: SQLiteOpenOptions,\n public readonly nativeDatabase: NativeDatabase\n ) {}\n\n /**\n * Asynchronous call to return whether the database is currently in a transaction.\n */\n public isInTransactionAsync(): Promise<boolean> {\n return this.nativeDatabase.isInTransactionAsync();\n }\n\n /**\n * Close the database.\n */\n public closeAsync(): Promise<void> {\n return this.nativeDatabase.closeAsync();\n }\n\n /**\n * Execute all SQL queries in the supplied string.\n * > Note: The queries are not escaped for you! Be careful when constructing your queries.\n *\n * @param source A string containing all the SQL queries.\n */\n public execAsync(source: string): Promise<void> {\n return this.nativeDatabase.execAsync(source);\n }\n\n /**\n * [Serialize the database](https://sqlite.org/c3ref/serialize.html) as `Uint8Array`.\n *\n * @param databaseName The name of the current attached databases. The default value is `main` which is the default database name.\n */\n public serializeAsync(databaseName: string = 'main'): Promise<Uint8Array> {\n return this.nativeDatabase.serializeAsync(databaseName);\n }\n\n /**\n * Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).\n *\n * @param source A string containing the SQL query.\n */\n public async prepareAsync(source: string): Promise<SQLiteStatement> {\n const nativeStatement = new ExpoSQLite.NativeStatement();\n await this.nativeDatabase.prepareAsync(nativeStatement, source);\n return new SQLiteStatement(this.nativeDatabase, nativeStatement);\n }\n\n /**\n * Create a new session for the database.\n * @see [`sqlite3session_create`](https://www.sqlite.org/session/sqlite3session_create.html)\n * @param dbName The name of the database to create a session for. The default value is `main`.\n */\n public async createSessionAsync(dbName: string = 'main'): Promise<SQLiteSession> {\n const nativeSession = new ExpoSQLite.NativeSession();\n await this.nativeDatabase.createSessionAsync(nativeSession, dbName);\n return new SQLiteSession(this.nativeDatabase, nativeSession);\n }\n\n /**\n * Load a SQLite extension.\n * @param libPath The path to the extension library file.\n * @param entryPoint The entry point of the extension. If not provided, the default entry point is inferred by [`sqlite3_load_extension`](https://www.sqlite.org/c3ref/load_extension.html).\n *\n * @platform android\n * @platform ios\n * @platform macos\n * @platform tvos\n */\n public loadExtensionAsync(libPath: string, entryPoint?: string): Promise<void> {\n return this.nativeDatabase.loadExtensionAsync(libPath, entryPoint);\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * > **Note:** This transaction is not exclusive and can be interrupted by other async queries.\n *\n * @example\n * ```ts\n * db.withTransactionAsync(async () => {\n * await db.execAsync('UPDATE test SET name = \"aaa\"');\n *\n * //\n * // We cannot control the order of async/await order, so order of execution is not guaranteed.\n * // The following UPDATE query out of transaction may be executed here and break the expectation.\n * //\n *\n * const result = await db.getFirstAsync<{ name: string }>('SELECT name FROM Users');\n * expect(result?.name).toBe('aaa');\n * });\n * db.execAsync('UPDATE test SET name = \"bbb\"');\n * ```\n * If you worry about the order of execution, use `withExclusiveTransactionAsync` instead.\n *\n * @param task An async function to execute within a transaction.\n */\n public async withTransactionAsync(task: () => Promise<void>): Promise<void> {\n try {\n await this.execAsync('BEGIN');\n await task();\n await this.execAsync('COMMIT');\n } catch (e) {\n await this.execAsync('ROLLBACK');\n throw e;\n }\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * The transaction may be exclusive.\n * As long as the transaction is converted into a write transaction,\n * the other async write queries will abort with `database is locked` error.\n *\n * > **Note:** This function is not supported on web.\n *\n * @param task An async function to execute within a transaction. Any queries inside the transaction must be executed on the `txn` object.\n * The `txn` object has the same interfaces as the [`SQLiteDatabase`](#sqlitedatabase) object. You can use `txn` like a [`SQLiteDatabase`](#sqlitedatabase) object.\n *\n * @platform android\n * @platform ios\n * @platform macos\n * @platform tvos\n *\n * @example\n * ```ts\n * db.withExclusiveTransactionAsync(async (txn) => {\n * await txn.execAsync('UPDATE test SET name = \"aaa\"');\n * });\n * ```\n */\n public async withExclusiveTransactionAsync(\n task: (txn: Transaction) => Promise<void>\n ): Promise<void> {\n if (Platform.OS === 'web') {\n throw new Error('withExclusiveTransactionAsync is not supported on web');\n }\n const transaction = await Transaction.createAsync(this);\n let error;\n try {\n await transaction.execAsync('BEGIN');\n await task(transaction);\n await transaction.execAsync('COMMIT');\n } catch (e) {\n await transaction.execAsync('ROLLBACK');\n error = e;\n } finally {\n await transaction.closeAsync();\n }\n if (error) {\n throw error;\n }\n }\n\n /**\n * Synchronous call to return whether the database is currently in a transaction.\n */\n public isInTransactionSync(): boolean {\n return this.nativeDatabase.isInTransactionSync();\n }\n\n /**\n * Close the database.\n */\n public closeSync(): void {\n return this.nativeDatabase.closeSync();\n }\n\n /**\n * Execute all SQL queries in the supplied string.\n *\n * > **Note:** The queries are not escaped for you! Be careful when constructing your queries.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param source A string containing all the SQL queries.\n */\n public execSync(source: string): void {\n return this.nativeDatabase.execSync(source);\n }\n\n /**\n * [Serialize the database](https://sqlite.org/c3ref/serialize.html) as `Uint8Array`.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param databaseName The name of the current attached databases. The default value is `main` which is the default database name.\n */\n public serializeSync(databaseName: string = 'main'): Uint8Array {\n return this.nativeDatabase.serializeSync(databaseName);\n }\n\n /**\n * Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param source A string containing the SQL query.\n */\n public prepareSync(source: string): SQLiteStatement {\n const nativeStatement = new ExpoSQLite.NativeStatement();\n this.nativeDatabase.prepareSync(nativeStatement, source);\n return new SQLiteStatement(this.nativeDatabase, nativeStatement);\n }\n\n /**\n * Create a new session for the database.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @see [`sqlite3session_create`](https://www.sqlite.org/session/sqlite3session_create.html)\n * @param dbName The name of the database to create a session for. The default value is `main`.\n */\n public createSessionSync(dbName: string = 'main'): SQLiteSession {\n const nativeSession = new ExpoSQLite.NativeSession();\n this.nativeDatabase.createSessionSync(nativeSession, dbName);\n return new SQLiteSession(this.nativeDatabase, nativeSession);\n }\n\n /**\n * Load a SQLite extension.\n * @param libPath The path to the extension library file.\n * @param entryPoint The entry point of the extension. If not provided, the default entry point is inferred by [`sqlite3_load_extension`](https://www.sqlite.org/c3ref/load_extension.html).\n *\n * @platform android\n * @platform ios\n * @platform macos\n * @platform tvos\n */\n public loadExtensionSync(libPath: string, entryPoint?: string): void {\n this.nativeDatabase.loadExtensionSync(libPath, entryPoint);\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param task An async function to execute within a transaction.\n */\n public withTransactionSync(task: () => void): void {\n try {\n this.execSync('BEGIN');\n task();\n this.execSync('COMMIT');\n } catch (e) {\n this.execSync('ROLLBACK');\n throw e;\n }\n }\n\n //#region Statement API shorthands\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public runAsync(source: string, params: SQLiteBindParams): Promise<SQLiteRunResult>;\n\n /**\n * @hidden\n */\n public runAsync(source: string, ...params: SQLiteVariadicBindParams): Promise<SQLiteRunResult>;\n public async runAsync(source: string, ...params: any[]): Promise<SQLiteRunResult> {\n const statement = await this.prepareAsync(source);\n let result: SQLiteExecuteAsyncResult<unknown>;\n try {\n result = await statement.executeAsync(...params);\n } finally {\n await statement.finalizeAsync();\n }\n return result;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), [`SQLiteExecuteAsyncResult.getFirstAsync()`](#getfirstasync), and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public getFirstAsync<T>(source: string, params: SQLiteBindParams): Promise<T | null>;\n /**\n * @hidden\n */\n public getFirstAsync<T>(source: string, ...params: SQLiteVariadicBindParams): Promise<T | null>;\n public async getFirstAsync<T>(source: string, ...params: any[]): Promise<T | null> {\n const statement = await this.prepareAsync(source);\n let firstRow: T | null;\n try {\n const result = await statement.executeAsync<T>(...params);\n firstRow = await result.getFirstAsync();\n } finally {\n await statement.finalizeAsync();\n }\n return firstRow;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), [`SQLiteExecuteAsyncResult`](#sqliteexecuteasyncresult) `AsyncIterator`, and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n * @returns Rather than returning Promise, this function returns an [`AsyncIterableIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncIterator). You can use `for await...of` to iterate over the rows from the SQLite query result.\n */\n public getEachAsync<T>(source: string, params: SQLiteBindParams): AsyncIterableIterator<T>;\n /**\n * @hidden\n */\n public getEachAsync<T>(\n source: string,\n ...params: SQLiteVariadicBindParams\n ): AsyncIterableIterator<T>;\n public async *getEachAsync<T>(source: string, ...params: any[]): AsyncIterableIterator<T> {\n const statement = await this.prepareAsync(source);\n try {\n const result = await statement.executeAsync<T>(...params);\n for await (const row of result) {\n yield row;\n }\n } finally {\n await statement.finalizeAsync();\n }\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), [`SQLiteExecuteAsyncResult.getAllAsync()`](#getallasync), and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n * @example\n * ```ts\n * // For unnamed parameters, you pass values in an array.\n * db.getAllAsync('SELECT * FROM test WHERE intValue = ? AND name = ?', [1, 'Hello']);\n *\n * // For unnamed parameters, you pass values in variadic arguments.\n * db.getAllAsync('SELECT * FROM test WHERE intValue = ? AND name = ?', 1, 'Hello');\n *\n * // For named parameters, you should pass values in object.\n * db.getAllAsync('SELECT * FROM test WHERE intValue = $intValue AND name = $name', { $intValue: 1, $name: 'Hello' });\n * ```\n */\n public getAllAsync<T>(source: string, params: SQLiteBindParams): Promise<T[]>;\n /**\n * @hidden\n */\n public getAllAsync<T>(source: string, ...params: SQLiteVariadicBindParams): Promise<T[]>;\n public async getAllAsync<T>(source: string, ...params: any[]): Promise<T[]> {\n const statement = await this.prepareAsync(source);\n let allRows;\n try {\n const result = await statement.executeAsync<T>(...params);\n allRows = await result.getAllAsync();\n } finally {\n await statement.finalizeAsync();\n }\n return allRows;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), and [`SQLiteStatement.finalizeSync()`](#finalizesync).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public runSync(source: string, params: SQLiteBindParams): SQLiteRunResult;\n /**\n * @hidden\n */\n public runSync(source: string, ...params: SQLiteVariadicBindParams): SQLiteRunResult;\n public runSync(source: string, ...params: any[]): SQLiteRunResult {\n const statement = this.prepareSync(source);\n let result: SQLiteExecuteSyncResult<unknown>;\n try {\n result = statement.executeSync(...params);\n } finally {\n statement.finalizeSync();\n }\n return result;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), [`SQLiteExecuteSyncResult.getFirstSync()`](#getfirstsync), and [`SQLiteStatement.finalizeSync()`](#finalizesync).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public getFirstSync<T>(source: string, params: SQLiteBindParams): T | null;\n /**\n * @hidden\n */\n public getFirstSync<T>(source: string, ...params: SQLiteVariadicBindParams): T | null;\n public getFirstSync<T>(source: string, ...params: any[]): T | null {\n const statement = this.prepareSync(source);\n let firstRow: T | null;\n try {\n const result = statement.executeSync<T>(...params);\n firstRow = result.getFirstSync();\n } finally {\n statement.finalizeSync();\n }\n return firstRow;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), [`SQLiteExecuteSyncResult`](#sqliteexecutesyncresult) `Iterator`, and [`SQLiteStatement.finalizeSync()`](#finalizesync).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n * @returns This function returns an [`IterableIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator). You can use `for...of` to iterate over the rows from the SQLite query result.\n */\n public getEachSync<T>(source: string, params: SQLiteBindParams): IterableIterator<T>;\n /**\n * @hidden\n */\n public getEachSync<T>(source: string, ...params: SQLiteVariadicBindParams): IterableIterator<T>;\n public *getEachSync<T>(source: string, ...params: any[]): IterableIterator<T> {\n const statement = this.prepareSync(source);\n try {\n const result = statement.executeSync<T>(...params);\n for (const row of result) {\n yield row;\n }\n } finally {\n statement.finalizeSync();\n }\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), [`SQLiteExecuteSyncResult.getAllSync()`](#getallsync), and [`SQLiteStatement.finalizeSync()`](#finalizesync).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public getAllSync<T>(source: string, params: SQLiteBindParams): T[];\n /**\n * @hidden\n */\n public getAllSync<T>(source: string, ...params: SQLiteVariadicBindParams): T[];\n public getAllSync<T>(source: string, ...params: any[]): T[] {\n const statement = this.prepareSync(source);\n let allRows;\n try {\n const result = statement.executeSync<T>(...params);\n allRows = result.getAllSync();\n } finally {\n statement.finalizeSync();\n }\n return allRows;\n }\n\n /**\n * Synchronize the local database with the remote libSQL server.\n * This method is only available from libSQL integration.\n */\n public syncLibSQL(): Promise<void> {\n if (typeof this.nativeDatabase.syncLibSQL !== 'function') {\n throw new Error('syncLibSQL is not supported in the current environment');\n }\n return this.nativeDatabase.syncLibSQL();\n }\n\n //#endregion\n}\n\n/**\n * The default directory for SQLite databases.\n */\nexport const defaultDatabaseDirectory = ExpoSQLite.defaultDatabaseDirectory;\n\n/**\n * The pre-bundled SQLite extensions.\n */\nexport const bundledExtensions: Record<\n string,\n { libPath: string; entryPoint: string } | undefined\n> = ExpoSQLite.bundledExtensions;\n\n/**\n * Open a database.\n *\n * @param databaseName The name of the database file to open.\n * @param options Open options.\n * @param directory The directory where the database file is located. The default value is `defaultDatabaseDirectory`. This parameter is not supported on web.\n */\nexport async function openDatabaseAsync(\n databaseName: string,\n options?: SQLiteOpenOptions,\n directory?: string\n): Promise<SQLiteDatabase> {\n const openOptions = options ?? {};\n const databasePath = createDatabasePath(databaseName, directory);\n await ExpoSQLite.ensureDatabasePathExistsAsync(databasePath);\n const nativeDatabase = new ExpoSQLite.NativeDatabase(\n databasePath,\n flattenOpenOptions(openOptions)\n );\n await nativeDatabase.initAsync();\n return new SQLiteDatabase(databasePath, openOptions, nativeDatabase);\n}\n\n/**\n * Open a database.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param databaseName The name of the database file to open.\n * @param options Open options.\n * @param directory The directory where the database file is located. The default value is `defaultDatabaseDirectory`. This parameter is not supported on web.\n */\nexport function openDatabaseSync(\n databaseName: string,\n options?: SQLiteOpenOptions,\n directory?: string\n): SQLiteDatabase {\n const openOptions = options ?? {};\n const databasePath = createDatabasePath(databaseName, directory);\n ExpoSQLite.ensureDatabasePathExistsSync(databasePath);\n const nativeDatabase = new ExpoSQLite.NativeDatabase(\n databasePath,\n flattenOpenOptions(openOptions)\n );\n nativeDatabase.initSync();\n return new SQLiteDatabase(databasePath, openOptions, nativeDatabase);\n}\n\n/**\n * Given a `Uint8Array` data and [deserialize to memory database](https://sqlite.org/c3ref/deserialize.html).\n *\n * @param serializedData The binary array to deserialize from [`SQLiteDatabase.serializeAsync()`](#serializeasyncdatabasename).\n * @param options Open options.\n */\nexport async function deserializeDatabaseAsync(\n serializedData: Uint8Array,\n options?: SQLiteOpenOptions\n): Promise<SQLiteDatabase> {\n const openOptions = options ?? {};\n const nativeDatabase = new ExpoSQLite.NativeDatabase(\n ':memory:',\n flattenOpenOptions(openOptions),\n serializedData\n );\n await nativeDatabase.initAsync();\n return new SQLiteDatabase(':memory:', openOptions, nativeDatabase);\n}\n\n/**\n * Given a `Uint8Array` data and [deserialize to memory database](https://sqlite.org/c3ref/deserialize.html).\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param serializedData The binary array to deserialize from [`SQLiteDatabase.serializeSync()`](#serializesyncdatabasename)\n * @param options Open options.\n */\nexport function deserializeDatabaseSync(\n serializedData: Uint8Array,\n options?: SQLiteOpenOptions\n): SQLiteDatabase {\n const openOptions = options ?? {};\n const nativeDatabase = new ExpoSQLite.NativeDatabase(\n ':memory:',\n flattenOpenOptions(openOptions),\n serializedData\n );\n nativeDatabase.initSync();\n return new SQLiteDatabase(':memory:', openOptions, nativeDatabase);\n}\n\n/**\n * Delete a database file.\n *\n * @param databaseName The name of the database file to delete.\n * @param directory The directory where the database file is located. The default value is `defaultDatabaseDirectory`.\n */\nexport async function deleteDatabaseAsync(databaseName: string, directory?: string): Promise<void> {\n const databasePath = createDatabasePath(databaseName, directory);\n return await ExpoSQLite.deleteDatabaseAsync(databasePath);\n}\n\n/**\n * Delete a database file.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param databaseName The name of the database file to delete.\n * @param directory The directory where the database file is located. The default value is `defaultDatabaseDirectory`.\n */\nexport function deleteDatabaseSync(databaseName: string, directory?: string): void {\n const databasePath = createDatabasePath(databaseName, directory);\n return ExpoSQLite.deleteDatabaseSync(databasePath);\n}\n\n/**\n * Backup a database to another database.\n *\n * @see https://www.sqlite.org/c3ref/backup_finish.html\n *\n * @param options - The backup options\n * @param options.sourceDatabase - The source database to backup from\n * @param options.sourceDatabaseName - The name of the source database. The default value is `main`\n * @param options.destDatabase - The destination database to backup to\n * @param options.destDatabaseName - The name of the destination database. The default value is `m\n */\nexport function backupDatabaseAsync({\n sourceDatabase,\n sourceDatabaseName,\n destDatabase,\n destDatabaseName,\n}: {\n sourceDatabase: SQLiteDatabase;\n sourceDatabaseName?: string;\n destDatabase: SQLiteDatabase;\n destDatabaseName?: string;\n}): Promise<void> {\n return ExpoSQLite.backupDatabaseAsync(\n destDatabase.nativeDatabase,\n destDatabaseName ?? 'main',\n sourceDatabase.nativeDatabase,\n sourceDatabaseName ?? 'main'\n );\n}\n\n/**\n * Backup a database to another database.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @see https://www.sqlite.org/c3ref/backup_finish.html\n *\n * @param options - The backup options\n * @param options.sourceDatabase - The source database to backup from\n * @param options.sourceDatabaseName - The name of the source database. The default value is `main`\n * @param options.destDatabase - The destination database to backup to\n * @param options.destDatabaseName - The name of the destination database. The default value is `m\n */\nexport function backupDatabaseSync({\n sourceDatabase,\n sourceDatabaseName,\n destDatabase,\n destDatabaseName,\n}: {\n sourceDatabase: SQLiteDatabase;\n sourceDatabaseName?: string;\n destDatabase: SQLiteDatabase;\n destDatabaseName?: string;\n}): void {\n return ExpoSQLite.backupDatabaseSync(\n destDatabase.nativeDatabase,\n destDatabaseName ?? 'main',\n sourceDatabase.nativeDatabase,\n sourceDatabaseName ?? 'main'\n );\n}\n\n/**\n * The event payload for the listener of [`addDatabaseChangeListener`](#sqliteadddatabasechangelistenerlistener)\n */\nexport type DatabaseChangeEvent = {\n /** The database name. The value would be `main` by default and other database names if you use `ATTACH DATABASE` statement. */\n databaseName: string;\n\n /** The absolute file path to the database. */\n databaseFilePath: string;\n\n /** The table name. */\n tableName: string;\n\n /** The changed row ID. */\n rowId: number;\n};\n\n/**\n * Add a listener for database changes.\n * > Note: to enable this feature, you must set [`enableChangeListener` to `true`](#sqliteopenoptions) when opening the database.\n *\n * @param listener A function that receives the `databaseName`, `databaseFilePath`, `tableName` and `rowId` of the modified data.\n * @returns A `Subscription` object that you can call `remove()` on when you would like to unsubscribe the listener.\n */\nexport function addDatabaseChangeListener(\n listener: (event: DatabaseChangeEvent) => void\n): EventSubscription {\n return ExpoSQLite.addListener('onDatabaseChange', listener);\n}\n\n/**\n * A new connection specific used for [`withExclusiveTransactionAsync`](#withexclusivetransactionasynctask).\n * @hidden not going to pull all the database methods to the document.\n */\nclass Transaction extends SQLiteDatabase {\n public static async createAsync(db: SQLiteDatabase): Promise<Transaction> {\n const options = { ...db.options, useNewConnection: true };\n const nativeDatabase = new ExpoSQLite.NativeDatabase(\n db.databasePath,\n flattenOpenOptions(options)\n );\n await nativeDatabase.initAsync();\n return new Transaction(db.databasePath, options, nativeDatabase);\n }\n}\n"]}
1
+ {"version":3,"file":"SQLiteDatabase.js","sourceRoot":"","sources":["../src/SQLiteDatabase.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,UAAU,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAqC,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAKL,eAAe,GAEhB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAIjD;;GAEG;AACH,MAAM,OAAO,cAAc;IAEP;IACA;IACA;IAHlB,YACkB,YAAoB,EACpB,OAA0B,EAC1B,cAA8B;QAF9B,iBAAY,GAAZ,YAAY,CAAQ;QACpB,YAAO,GAAP,OAAO,CAAmB;QAC1B,mBAAc,GAAd,cAAc,CAAgB;IAC7C,CAAC;IAEJ;;OAEG;IACI,oBAAoB;QACzB,OAAO,IAAI,CAAC,cAAc,CAAC,oBAAoB,EAAE,CAAC;IACpD,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,MAAc;QAC7B,OAAO,IAAI,CAAC,cAAc,CAAC,SAA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AAE,GAAG,EAAE,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC;QAC1D,MAAM,cAAc,GAAG,IAAI,UAAU,CAAC,cAAc,CAClD,EAAE,CAAC,YAAY,EACf,kBAAkB,CAAC,OAAO,CAAC,CAC5B,CAAC;QACF,MAAM,cAAc,CAAC,SAAS,EAAE,CAAC;QACjC,OAAO,IAAI,WAAW,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;IACnE,CAAC;CACF","sourcesContent":["import { type EventSubscription } from 'expo-modules-core';\nimport { Platform } from 'react-native';\n\nimport ExpoSQLite from './ExpoSQLite';\nimport { flattenOpenOptions, NativeDatabase, SQLiteOpenOptions } from './NativeDatabase';\nimport { SQLiteSession } from './SQLiteSession';\nimport {\n SQLiteBindParams,\n SQLiteExecuteAsyncResult,\n SQLiteExecuteSyncResult,\n SQLiteRunResult,\n SQLiteStatement,\n SQLiteVariadicBindParams,\n} from './SQLiteStatement';\nimport { createDatabasePath } from './pathUtils';\n\nexport { SQLiteOpenOptions };\n\n/**\n * A SQLite database.\n */\nexport class SQLiteDatabase {\n constructor(\n public readonly databasePath: string,\n public readonly options: SQLiteOpenOptions,\n public readonly nativeDatabase: NativeDatabase\n ) {}\n\n /**\n * Asynchronous call to return whether the database is currently in a transaction.\n */\n public isInTransactionAsync(): Promise<boolean> {\n return this.nativeDatabase.isInTransactionAsync();\n }\n\n /**\n * Close the database.\n */\n public closeAsync(): Promise<void> {\n return this.nativeDatabase.closeAsync();\n }\n\n /**\n * Execute all SQL queries in the supplied string.\n * > Note: The queries are not escaped for you! Be careful when constructing your queries.\n *\n * @param source A string containing all the SQL queries.\n */\n public execAsync(source: string): Promise<void> {\n return this.nativeDatabase.execAsync(source);\n }\n\n /**\n * [Serialize the database](https://sqlite.org/c3ref/serialize.html) as `Uint8Array`.\n *\n * @param databaseName The name of the current attached databases. The default value is `main` which is the default database name.\n */\n public serializeAsync(databaseName: string = 'main'): Promise<Uint8Array> {\n return this.nativeDatabase.serializeAsync(databaseName);\n }\n\n /**\n * Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).\n *\n * @param source A string containing the SQL query.\n */\n public async prepareAsync(source: string): Promise<SQLiteStatement> {\n const nativeStatement = new ExpoSQLite.NativeStatement();\n await this.nativeDatabase.prepareAsync(nativeStatement, source);\n return new SQLiteStatement(this.nativeDatabase, nativeStatement);\n }\n\n /**\n * Create a new session for the database.\n * @see [`sqlite3session_create`](https://www.sqlite.org/session/sqlite3session_create.html)\n * @param dbName The name of the database to create a session for. The default value is `main`.\n */\n public async createSessionAsync(dbName: string = 'main'): Promise<SQLiteSession> {\n const nativeSession = new ExpoSQLite.NativeSession();\n await this.nativeDatabase.createSessionAsync(nativeSession, dbName);\n return new SQLiteSession(this.nativeDatabase, nativeSession);\n }\n\n /**\n * Load a SQLite extension.\n * @param libPath The path to the extension library file.\n * @param entryPoint The entry point of the extension. If not provided, the default entry point is inferred by [`sqlite3_load_extension`](https://www.sqlite.org/c3ref/load_extension.html).\n *\n * @platform android\n * @platform ios\n * @platform macos\n * @platform tvos\n *\n * @example\n * ```ts\n * // Load `sqlite-vec` from `bundledExtensions`. You need to enable `withSQLiteVecExtension` to include `sqlite-vec`.\n * const extension = SQLite.bundledExtensions['sqlite-vec'];\n * await db.loadExtensionAsync(extension.libPath, extension.entryPoint);\n *\n * // You can also load a custom extension.\n * await db.loadExtensionAsync('/path/to/extension');\n * ```\n */\n public loadExtensionAsync(libPath: string, entryPoint?: string): Promise<void> {\n return this.nativeDatabase.loadExtensionAsync(libPath, entryPoint);\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * > **Note:** This transaction is not exclusive and can be interrupted by other async queries.\n *\n * @example\n * ```ts\n * db.withTransactionAsync(async () => {\n * await db.execAsync('UPDATE test SET name = \"aaa\"');\n *\n * //\n * // We cannot control the order of async/await order, so order of execution is not guaranteed.\n * // The following UPDATE query out of transaction may be executed here and break the expectation.\n * //\n *\n * const result = await db.getFirstAsync<{ name: string }>('SELECT name FROM Users');\n * expect(result?.name).toBe('aaa');\n * });\n * db.execAsync('UPDATE test SET name = \"bbb\"');\n * ```\n * If you worry about the order of execution, use `withExclusiveTransactionAsync` instead.\n *\n * @param task An async function to execute within a transaction.\n */\n public async withTransactionAsync(task: () => Promise<void>): Promise<void> {\n try {\n await this.execAsync('BEGIN');\n await task();\n await this.execAsync('COMMIT');\n } catch (e) {\n await this.execAsync('ROLLBACK');\n throw e;\n }\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * The transaction may be exclusive.\n * As long as the transaction is converted into a write transaction,\n * the other async write queries will abort with `database is locked` error.\n *\n * > **Note:** This function is not supported on web.\n *\n * @param task An async function to execute within a transaction. Any queries inside the transaction must be executed on the `txn` object.\n * The `txn` object has the same interfaces as the [`SQLiteDatabase`](#sqlitedatabase) object. You can use `txn` like a [`SQLiteDatabase`](#sqlitedatabase) object.\n *\n * @platform android\n * @platform ios\n * @platform macos\n * @platform tvos\n *\n * @example\n * ```ts\n * db.withExclusiveTransactionAsync(async (txn) => {\n * await txn.execAsync('UPDATE test SET name = \"aaa\"');\n * });\n * ```\n */\n public async withExclusiveTransactionAsync(\n task: (txn: Transaction) => Promise<void>\n ): Promise<void> {\n if (Platform.OS === 'web') {\n throw new Error('withExclusiveTransactionAsync is not supported on web');\n }\n const transaction = await Transaction.createAsync(this);\n let error;\n try {\n await transaction.execAsync('BEGIN');\n await task(transaction);\n await transaction.execAsync('COMMIT');\n } catch (e) {\n await transaction.execAsync('ROLLBACK');\n error = e;\n } finally {\n await transaction.closeAsync();\n }\n if (error) {\n throw error;\n }\n }\n\n /**\n * Synchronous call to return whether the database is currently in a transaction.\n */\n public isInTransactionSync(): boolean {\n return this.nativeDatabase.isInTransactionSync();\n }\n\n /**\n * Close the database.\n */\n public closeSync(): void {\n return this.nativeDatabase.closeSync();\n }\n\n /**\n * Execute all SQL queries in the supplied string.\n *\n * > **Note:** The queries are not escaped for you! Be careful when constructing your queries.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param source A string containing all the SQL queries.\n */\n public execSync(source: string): void {\n return this.nativeDatabase.execSync(source);\n }\n\n /**\n * [Serialize the database](https://sqlite.org/c3ref/serialize.html) as `Uint8Array`.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param databaseName The name of the current attached databases. The default value is `main` which is the default database name.\n */\n public serializeSync(databaseName: string = 'main'): Uint8Array {\n return this.nativeDatabase.serializeSync(databaseName);\n }\n\n /**\n * Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param source A string containing the SQL query.\n */\n public prepareSync(source: string): SQLiteStatement {\n const nativeStatement = new ExpoSQLite.NativeStatement();\n this.nativeDatabase.prepareSync(nativeStatement, source);\n return new SQLiteStatement(this.nativeDatabase, nativeStatement);\n }\n\n /**\n * Create a new session for the database.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @see [`sqlite3session_create`](https://www.sqlite.org/session/sqlite3session_create.html)\n * @param dbName The name of the database to create a session for. The default value is `main`.\n */\n public createSessionSync(dbName: string = 'main'): SQLiteSession {\n const nativeSession = new ExpoSQLite.NativeSession();\n this.nativeDatabase.createSessionSync(nativeSession, dbName);\n return new SQLiteSession(this.nativeDatabase, nativeSession);\n }\n\n /**\n * Load a SQLite extension.\n * @param libPath The path to the extension library file.\n * @param entryPoint The entry point of the extension. If not provided, the default entry point is inferred by [`sqlite3_load_extension`](https://www.sqlite.org/c3ref/load_extension.html).\n *\n * @platform android\n * @platform ios\n * @platform macos\n * @platform tvos\n *\n * @example\n * ```ts\n * // Load `sqlite-vec` from `bundledExtensions`. You need to enable `withSQLiteVecExtension` to include `sqlite-vec`.\n * const extension = SQLite.bundledExtensions['sqlite-vec'];\n * db.loadExtensionSync(extension.libPath, extension.entryPoint);\n *\n * // You can also load a custom extension.\n * db.loadExtensionSync('/path/to/extension');\n * ```\n\n */\n public loadExtensionSync(libPath: string, entryPoint?: string): void {\n this.nativeDatabase.loadExtensionSync(libPath, entryPoint);\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param task An async function to execute within a transaction.\n */\n public withTransactionSync(task: () => void): void {\n try {\n this.execSync('BEGIN');\n task();\n this.execSync('COMMIT');\n } catch (e) {\n this.execSync('ROLLBACK');\n throw e;\n }\n }\n\n //#region Statement API shorthands\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public runAsync(source: string, params: SQLiteBindParams): Promise<SQLiteRunResult>;\n\n /**\n * @hidden\n */\n public runAsync(source: string, ...params: SQLiteVariadicBindParams): Promise<SQLiteRunResult>;\n public async runAsync(source: string, ...params: any[]): Promise<SQLiteRunResult> {\n const statement = await this.prepareAsync(source);\n let result: SQLiteExecuteAsyncResult<unknown>;\n try {\n result = await statement.executeAsync(...params);\n } finally {\n await statement.finalizeAsync();\n }\n return result;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), [`SQLiteExecuteAsyncResult.getFirstAsync()`](#getfirstasync), and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public getFirstAsync<T>(source: string, params: SQLiteBindParams): Promise<T | null>;\n /**\n * @hidden\n */\n public getFirstAsync<T>(source: string, ...params: SQLiteVariadicBindParams): Promise<T | null>;\n public async getFirstAsync<T>(source: string, ...params: any[]): Promise<T | null> {\n const statement = await this.prepareAsync(source);\n let firstRow: T | null;\n try {\n const result = await statement.executeAsync<T>(...params);\n firstRow = await result.getFirstAsync();\n } finally {\n await statement.finalizeAsync();\n }\n return firstRow;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), [`SQLiteExecuteAsyncResult`](#sqliteexecuteasyncresult) `AsyncIterator`, and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n * @returns Rather than returning Promise, this function returns an [`AsyncIterableIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncIterator). You can use `for await...of` to iterate over the rows from the SQLite query result.\n */\n public getEachAsync<T>(source: string, params: SQLiteBindParams): AsyncIterableIterator<T>;\n /**\n * @hidden\n */\n public getEachAsync<T>(\n source: string,\n ...params: SQLiteVariadicBindParams\n ): AsyncIterableIterator<T>;\n public async *getEachAsync<T>(source: string, ...params: any[]): AsyncIterableIterator<T> {\n const statement = await this.prepareAsync(source);\n try {\n const result = await statement.executeAsync<T>(...params);\n for await (const row of result) {\n yield row;\n }\n } finally {\n await statement.finalizeAsync();\n }\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), [`SQLiteExecuteAsyncResult.getAllAsync()`](#getallasync), and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n * @example\n * ```ts\n * // For unnamed parameters, you pass values in an array.\n * db.getAllAsync('SELECT * FROM test WHERE intValue = ? AND name = ?', [1, 'Hello']);\n *\n * // For unnamed parameters, you pass values in variadic arguments.\n * db.getAllAsync('SELECT * FROM test WHERE intValue = ? AND name = ?', 1, 'Hello');\n *\n * // For named parameters, you should pass values in object.\n * db.getAllAsync('SELECT * FROM test WHERE intValue = $intValue AND name = $name', { $intValue: 1, $name: 'Hello' });\n * ```\n */\n public getAllAsync<T>(source: string, params: SQLiteBindParams): Promise<T[]>;\n /**\n * @hidden\n */\n public getAllAsync<T>(source: string, ...params: SQLiteVariadicBindParams): Promise<T[]>;\n public async getAllAsync<T>(source: string, ...params: any[]): Promise<T[]> {\n const statement = await this.prepareAsync(source);\n let allRows;\n try {\n const result = await statement.executeAsync<T>(...params);\n allRows = await result.getAllAsync();\n } finally {\n await statement.finalizeAsync();\n }\n return allRows;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), and [`SQLiteStatement.finalizeSync()`](#finalizesync).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public runSync(source: string, params: SQLiteBindParams): SQLiteRunResult;\n /**\n * @hidden\n */\n public runSync(source: string, ...params: SQLiteVariadicBindParams): SQLiteRunResult;\n public runSync(source: string, ...params: any[]): SQLiteRunResult {\n const statement = this.prepareSync(source);\n let result: SQLiteExecuteSyncResult<unknown>;\n try {\n result = statement.executeSync(...params);\n } finally {\n statement.finalizeSync();\n }\n return result;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), [`SQLiteExecuteSyncResult.getFirstSync()`](#getfirstsync), and [`SQLiteStatement.finalizeSync()`](#finalizesync).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public getFirstSync<T>(source: string, params: SQLiteBindParams): T | null;\n /**\n * @hidden\n */\n public getFirstSync<T>(source: string, ...params: SQLiteVariadicBindParams): T | null;\n public getFirstSync<T>(source: string, ...params: any[]): T | null {\n const statement = this.prepareSync(source);\n let firstRow: T | null;\n try {\n const result = statement.executeSync<T>(...params);\n firstRow = result.getFirstSync();\n } finally {\n statement.finalizeSync();\n }\n return firstRow;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), [`SQLiteExecuteSyncResult`](#sqliteexecutesyncresult) `Iterator`, and [`SQLiteStatement.finalizeSync()`](#finalizesync).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n * @returns This function returns an [`IterableIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator). You can use `for...of` to iterate over the rows from the SQLite query result.\n */\n public getEachSync<T>(source: string, params: SQLiteBindParams): IterableIterator<T>;\n /**\n * @hidden\n */\n public getEachSync<T>(source: string, ...params: SQLiteVariadicBindParams): IterableIterator<T>;\n public *getEachSync<T>(source: string, ...params: any[]): IterableIterator<T> {\n const statement = this.prepareSync(source);\n try {\n const result = statement.executeSync<T>(...params);\n for (const row of result) {\n yield row;\n }\n } finally {\n statement.finalizeSync();\n }\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), [`SQLiteExecuteSyncResult.getAllSync()`](#getallsync), and [`SQLiteStatement.finalizeSync()`](#finalizesync).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public getAllSync<T>(source: string, params: SQLiteBindParams): T[];\n /**\n * @hidden\n */\n public getAllSync<T>(source: string, ...params: SQLiteVariadicBindParams): T[];\n public getAllSync<T>(source: string, ...params: any[]): T[] {\n const statement = this.prepareSync(source);\n let allRows;\n try {\n const result = statement.executeSync<T>(...params);\n allRows = result.getAllSync();\n } finally {\n statement.finalizeSync();\n }\n return allRows;\n }\n\n /**\n * Synchronize the local database with the remote libSQL server.\n * This method is only available from libSQL integration.\n */\n public syncLibSQL(): Promise<void> {\n if (typeof this.nativeDatabase.syncLibSQL !== 'function') {\n throw new Error('syncLibSQL is not supported in the current environment');\n }\n return this.nativeDatabase.syncLibSQL();\n }\n\n //#endregion\n}\n\n/**\n * The default directory for SQLite databases.\n */\nexport const defaultDatabaseDirectory = ExpoSQLite.defaultDatabaseDirectory;\n\n/**\n * The pre-bundled SQLite extensions.\n */\nexport const bundledExtensions: Record<\n string,\n { libPath: string; entryPoint: string } | undefined\n> = ExpoSQLite.bundledExtensions;\n\n/**\n * Open a database.\n *\n * @param databaseName The name of the database file to open.\n * @param options Open options.\n * @param directory The directory where the database file is located. The default value is `defaultDatabaseDirectory`. This parameter is not supported on web.\n */\nexport async function openDatabaseAsync(\n databaseName: string,\n options?: SQLiteOpenOptions,\n directory?: string\n): Promise<SQLiteDatabase> {\n const openOptions = options ?? {};\n const databasePath = createDatabasePath(databaseName, directory);\n await ExpoSQLite.ensureDatabasePathExistsAsync(databasePath);\n const nativeDatabase = new ExpoSQLite.NativeDatabase(\n databasePath,\n flattenOpenOptions(openOptions)\n );\n await nativeDatabase.initAsync();\n return new SQLiteDatabase(databasePath, openOptions, nativeDatabase);\n}\n\n/**\n * Open a database.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param databaseName The name of the database file to open.\n * @param options Open options.\n * @param directory The directory where the database file is located. The default value is `defaultDatabaseDirectory`. This parameter is not supported on web.\n */\nexport function openDatabaseSync(\n databaseName: string,\n options?: SQLiteOpenOptions,\n directory?: string\n): SQLiteDatabase {\n const openOptions = options ?? {};\n const databasePath = createDatabasePath(databaseName, directory);\n ExpoSQLite.ensureDatabasePathExistsSync(databasePath);\n const nativeDatabase = new ExpoSQLite.NativeDatabase(\n databasePath,\n flattenOpenOptions(openOptions)\n );\n nativeDatabase.initSync();\n return new SQLiteDatabase(databasePath, openOptions, nativeDatabase);\n}\n\n/**\n * Given a `Uint8Array` data and [deserialize to memory database](https://sqlite.org/c3ref/deserialize.html).\n *\n * @param serializedData The binary array to deserialize from [`SQLiteDatabase.serializeAsync()`](#serializeasyncdatabasename).\n * @param options Open options.\n */\nexport async function deserializeDatabaseAsync(\n serializedData: Uint8Array,\n options?: SQLiteOpenOptions\n): Promise<SQLiteDatabase> {\n const openOptions = options ?? {};\n const nativeDatabase = new ExpoSQLite.NativeDatabase(\n ':memory:',\n flattenOpenOptions(openOptions),\n serializedData\n );\n await nativeDatabase.initAsync();\n return new SQLiteDatabase(':memory:', openOptions, nativeDatabase);\n}\n\n/**\n * Given a `Uint8Array` data and [deserialize to memory database](https://sqlite.org/c3ref/deserialize.html).\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param serializedData The binary array to deserialize from [`SQLiteDatabase.serializeSync()`](#serializesyncdatabasename)\n * @param options Open options.\n */\nexport function deserializeDatabaseSync(\n serializedData: Uint8Array,\n options?: SQLiteOpenOptions\n): SQLiteDatabase {\n const openOptions = options ?? {};\n const nativeDatabase = new ExpoSQLite.NativeDatabase(\n ':memory:',\n flattenOpenOptions(openOptions),\n serializedData\n );\n nativeDatabase.initSync();\n return new SQLiteDatabase(':memory:', openOptions, nativeDatabase);\n}\n\n/**\n * Delete a database file.\n *\n * @param databaseName The name of the database file to delete.\n * @param directory The directory where the database file is located. The default value is `defaultDatabaseDirectory`.\n */\nexport async function deleteDatabaseAsync(databaseName: string, directory?: string): Promise<void> {\n const databasePath = createDatabasePath(databaseName, directory);\n return await ExpoSQLite.deleteDatabaseAsync(databasePath);\n}\n\n/**\n * Delete a database file.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param databaseName The name of the database file to delete.\n * @param directory The directory where the database file is located. The default value is `defaultDatabaseDirectory`.\n */\nexport function deleteDatabaseSync(databaseName: string, directory?: string): void {\n const databasePath = createDatabasePath(databaseName, directory);\n return ExpoSQLite.deleteDatabaseSync(databasePath);\n}\n\n/**\n * Backup a database to another database.\n *\n * @see https://www.sqlite.org/c3ref/backup_finish.html\n *\n * @param options - The backup options\n * @param options.sourceDatabase - The source database to backup from\n * @param options.sourceDatabaseName - The name of the source database. The default value is `main`\n * @param options.destDatabase - The destination database to backup to\n * @param options.destDatabaseName - The name of the destination database. The default value is `m\n */\nexport function backupDatabaseAsync({\n sourceDatabase,\n sourceDatabaseName,\n destDatabase,\n destDatabaseName,\n}: {\n sourceDatabase: SQLiteDatabase;\n sourceDatabaseName?: string;\n destDatabase: SQLiteDatabase;\n destDatabaseName?: string;\n}): Promise<void> {\n return ExpoSQLite.backupDatabaseAsync(\n destDatabase.nativeDatabase,\n destDatabaseName ?? 'main',\n sourceDatabase.nativeDatabase,\n sourceDatabaseName ?? 'main'\n );\n}\n\n/**\n * Backup a database to another database.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @see https://www.sqlite.org/c3ref/backup_finish.html\n *\n * @param options - The backup options\n * @param options.sourceDatabase - The source database to backup from\n * @param options.sourceDatabaseName - The name of the source database. The default value is `main`\n * @param options.destDatabase - The destination database to backup to\n * @param options.destDatabaseName - The name of the destination database. The default value is `m\n */\nexport function backupDatabaseSync({\n sourceDatabase,\n sourceDatabaseName,\n destDatabase,\n destDatabaseName,\n}: {\n sourceDatabase: SQLiteDatabase;\n sourceDatabaseName?: string;\n destDatabase: SQLiteDatabase;\n destDatabaseName?: string;\n}): void {\n return ExpoSQLite.backupDatabaseSync(\n destDatabase.nativeDatabase,\n destDatabaseName ?? 'main',\n sourceDatabase.nativeDatabase,\n sourceDatabaseName ?? 'main'\n );\n}\n\n/**\n * The event payload for the listener of [`addDatabaseChangeListener`](#sqliteadddatabasechangelistenerlistener)\n */\nexport type DatabaseChangeEvent = {\n /** The database name. The value would be `main` by default and other database names if you use `ATTACH DATABASE` statement. */\n databaseName: string;\n\n /** The absolute file path to the database. */\n databaseFilePath: string;\n\n /** The table name. */\n tableName: string;\n\n /** The changed row ID. */\n rowId: number;\n};\n\n/**\n * Add a listener for database changes.\n * > Note: to enable this feature, you must set [`enableChangeListener` to `true`](#sqliteopenoptions) when opening the database.\n *\n * @param listener A function that receives the `databaseName`, `databaseFilePath`, `tableName` and `rowId` of the modified data.\n * @returns A `Subscription` object that you can call `remove()` on when you would like to unsubscribe the listener.\n */\nexport function addDatabaseChangeListener(\n listener: (event: DatabaseChangeEvent) => void\n): EventSubscription {\n return ExpoSQLite.addListener('onDatabaseChange', listener);\n}\n\n/**\n * A new connection specific used for [`withExclusiveTransactionAsync`](#withexclusivetransactionasynctask).\n * @hidden not going to pull all the database methods to the document.\n */\nclass Transaction extends SQLiteDatabase {\n public static async createAsync(db: SQLiteDatabase): Promise<Transaction> {\n const options = { ...db.options, useNewConnection: true };\n const nativeDatabase = new ExpoSQLite.NativeDatabase(\n db.databasePath,\n flattenOpenOptions(options)\n );\n await nativeDatabase.initAsync();\n return new Transaction(db.databasePath, options, nativeDatabase);\n }\n}\n"]}
@@ -37,6 +37,14 @@ export declare class SQLiteStorage {
37
37
  * Closes the database connection asynchronously.
38
38
  */
39
39
  closeAsync(): Promise<void>;
40
+ /**
41
+ * Retrieves the number of key-value pairs stored in the storage asynchronously.
42
+ */
43
+ getLengthAsync(): Promise<number>;
44
+ /**
45
+ * Retrieves the key at the given index asynchronously.
46
+ */
47
+ getKeyByIndexAsync(index: number): Promise<string | null>;
40
48
  /**
41
49
  * Retrieves the value associated with the given key synchronously.
42
50
  */
@@ -62,6 +70,14 @@ export declare class SQLiteStorage {
62
70
  * Closes the database connection synchronously.
63
71
  */
64
72
  closeSync(): void;
73
+ /**
74
+ * Retrieves the number of key-value pairs stored in the storage synchronously.
75
+ */
76
+ getLengthSync(): number;
77
+ /**
78
+ * Retrieves the key at the given index synchronously.
79
+ */
80
+ getKeyByIndexSync(index: number): string | null;
65
81
  /**
66
82
  * Alias for [`getItemAsync()`](#getitemasynckey) method.
67
83
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Storage.d.ts","sourceRoot":"","sources":["../src/Storage.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,MAAM,kCAAkC,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,KAAK,MAAM,CAAC;AAatF;;GAEG;AACH,qBAAa,aAAa;IAIZ,OAAO,CAAC,QAAQ,CAAC,YAAY;IAHzC,OAAO,CAAC,EAAE,CAA+B;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmB;gBAEhB,YAAY,EAAE,MAAM;IAIjD;;OAEG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAOvD;;;OAGG;IACG,YAAY,CAChB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GAAG,kCAAkC,GACjD,OAAO,CAAC,IAAI,CAAC;IAkBhB;;OAEG;IACG,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOpD;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAM1C;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAMpC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,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GAAG,IAAI,CAAC,EAAE,CAAC;IASlE;;OAEG;IACG,QAAQ,CAAC,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAUhE;;OAEG;IACG,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAUhD;;;OAGG;IACG,UAAU,CAAC,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBlE;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAQd,UAAU;IAcxB,OAAO,CAAC,SAAS;IASjB,OAAO,CAAC,mBAAmB;IAe3B,OAAO,CAAC,kBAAkB;IAe1B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,SAAS;IA2BxB,OAAO,CAAC,eAAe;CAgBxB;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,eAAyC,CAAC;AAEnE,eAAe,YAAY,CAAC;AAE5B;;GAEG;AACH,eAAO,MAAM,OAAO,eAAe,CAAC"}
package/build/Storage.js CHANGED
@@ -1,11 +1,14 @@
1
1
  import AwaitLock from 'await-lock';
2
2
  import { openDatabaseAsync, openDatabaseSync } from './index';
3
+ import { normalizeStorageIndex } from './paramUtils';
3
4
  const DATABASE_VERSION = 1;
4
5
  const STATEMENT_GET = 'SELECT value FROM storage WHERE key = ?;';
5
6
  const STATEMENT_SET = 'INSERT INTO storage (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value;';
6
7
  const STATEMENT_REMOVE = 'DELETE FROM storage WHERE key = ?;';
7
8
  const STATEMENT_GET_ALL_KEYS = 'SELECT key FROM storage;';
8
9
  const STATEMENT_CLEAR = 'DELETE FROM storage;';
10
+ const STATEMENT_LENGTH = 'SELECT COUNT(*) as count FROM storage;';
11
+ const STATEMENT_GET_KEY_BY_INDEX = 'SELECT key FROM storage LIMIT 1 OFFSET ?;';
9
12
  const MIGRATION_STATEMENT_0 = 'CREATE TABLE IF NOT EXISTS storage (key TEXT PRIMARY KEY NOT NULL, value TEXT);';
10
13
  /**
11
14
  * Key-value store backed by SQLite. This class accepts a `databaseName` parameter in its constructor, which is the name of the database file to use for the storage.
@@ -86,6 +89,26 @@ export class SQLiteStorage {
86
89
  this.awaitLock.release();
87
90
  }
88
91
  }
92
+ /**
93
+ * Retrieves the number of key-value pairs stored in the storage asynchronously.
94
+ */
95
+ async getLengthAsync() {
96
+ const db = await this.getDbAsync();
97
+ const result = await db.getFirstAsync(STATEMENT_LENGTH);
98
+ return result?.count ?? 0;
99
+ }
100
+ /**
101
+ * Retrieves the key at the given index asynchronously.
102
+ */
103
+ async getKeyByIndexAsync(index) {
104
+ const db = await this.getDbAsync();
105
+ const offset = normalizeStorageIndex(index);
106
+ if (offset == null) {
107
+ return null;
108
+ }
109
+ const result = await db.getFirstAsync(STATEMENT_GET_KEY_BY_INDEX, offset);
110
+ return result?.key ?? null;
111
+ }
89
112
  //#endregion
90
113
  //#region Synchronous API
91
114
  /**
@@ -150,6 +173,26 @@ export class SQLiteStorage {
150
173
  this.db = null;
151
174
  }
152
175
  }
176
+ /**
177
+ * Retrieves the number of key-value pairs stored in the storage synchronously.
178
+ */
179
+ getLengthSync() {
180
+ const db = this.getDbSync();
181
+ const result = db.getFirstSync(STATEMENT_LENGTH);
182
+ return result.count ?? 0;
183
+ }
184
+ /**
185
+ * Retrieves the key at the given index synchronously.
186
+ */
187
+ getKeyByIndexSync(index) {
188
+ const db = this.getDbSync();
189
+ const offset = normalizeStorageIndex(index);
190
+ if (offset == null) {
191
+ return null;
192
+ }
193
+ const result = db.getFirstSync(STATEMENT_GET_KEY_BY_INDEX, offset);
194
+ return result?.key ?? null;
195
+ }
153
196
  //#endregion
154
197
  //#region react-native-async-storage compatible API
155
198
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Storage.js","sourceRoot":"","sources":["../src/Storage.ts"],"names":[],"mappings":"A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,GAAG,KAAK,CAAC;QAE3B,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CACb,yBAAyB,OAAO,GAAG,mEAAmE,GAAG,EAAE,CAC5G,CAAC;QACJ,CAAC;QAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;YACjF,MAAM,IAAI,KAAK,CACb,yBAAyB,OAAO,KAAK,qEAAqE,GAAG,oBAAoB,KAAK,EAAE,CACzI,CAAC;QACJ,CAAC;IACH,CAAC;CAGF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,aAAa,CAAC,mBAAmB,CAAC,CAAC;AAEnE,eAAe,YAAY,CAAC;AAE5B;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,YAAY,CAAC","sourcesContent":["import AwaitLock from 'await-lock';\n\nimport { openDatabaseAsync, openDatabaseSync, type SQLiteDatabase } from './index';\n\n/**\n * Update function for the [`setItemAsync()`](#setitemasynckey-value) or [`setItemSync()`](#setitemsynckey-value) method. It computes the new value based on the previous value. The function returns the new value to set for the key.\n * @param prevValue The previous value associated with the key, or `null` if the key was not set.\n * @returns The new value to set for the key.\n */\nexport type SQLiteStorageSetItemUpdateFunction = (prevValue: string | null) => string;\n\nconst DATABASE_VERSION = 1;\nconst STATEMENT_GET = 'SELECT value FROM storage WHERE key = ?;';\nconst STATEMENT_SET =\n 'INSERT INTO storage (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value;';\nconst STATEMENT_REMOVE = 'DELETE FROM storage WHERE key = ?;';\nconst STATEMENT_GET_ALL_KEYS = 'SELECT key FROM storage;';\nconst STATEMENT_CLEAR = 'DELETE FROM storage;';\n\nconst MIGRATION_STATEMENT_0 =\n 'CREATE TABLE IF NOT EXISTS storage (key TEXT PRIMARY KEY NOT NULL, value TEXT);';\n\n/**\n * Key-value store backed by SQLite. This class accepts a `databaseName` parameter in its constructor, which is the name of the database file to use for the storage.\n */\nexport class SQLiteStorage {\n private db: SQLiteDatabase | null = null;\n private readonly awaitLock = new AwaitLock();\n\n constructor(private readonly databaseName: string) {}\n\n //#region Asynchronous API\n\n /**\n * Retrieves the value associated with the given key asynchronously.\n */\n async getItemAsync(key: string): Promise<string | null> {\n this.checkValidInput(key);\n const db = await this.getDbAsync();\n const result = await db.getFirstAsync<{ value: string }>(STATEMENT_GET, key);\n return result?.value ?? null;\n }\n\n /**\n * Sets the value for the given key asynchronously.\n * If a function is provided, it computes the new value based on the previous value.\n */\n async setItemAsync(\n key: string,\n value: string | SQLiteStorageSetItemUpdateFunction\n ): Promise<void> {\n this.checkValidInput(key, value);\n const db = await this.getDbAsync();\n\n if (typeof value === 'function') {\n await db.withExclusiveTransactionAsync(async (tx) => {\n const prevResult = await tx.getFirstAsync<{ value: string }>(STATEMENT_GET, key);\n const prevValue = prevResult?.value ?? null;\n const nextValue = value(prevValue);\n this.checkValidInput(key, nextValue);\n await tx.runAsync(STATEMENT_SET, key, nextValue);\n });\n return;\n }\n\n await db.runAsync(STATEMENT_SET, key, value);\n }\n\n /**\n * Removes the value associated with the given key asynchronously.\n */\n async removeItemAsync(key: string): Promise<boolean> {\n this.checkValidInput(key);\n const db = await this.getDbAsync();\n const result = await db.runAsync(STATEMENT_REMOVE, key);\n return result.changes > 0;\n }\n\n /**\n * Retrieves all keys stored in the storage asynchronously.\n */\n async getAllKeysAsync(): Promise<string[]> {\n const db = await this.getDbAsync();\n const result = await db.getAllAsync<{ key: string }>(STATEMENT_GET_ALL_KEYS);\n return result.map(({ key }) => key);\n }\n\n /**\n * Clears all key-value pairs from the storage asynchronously.\n */\n async clearAsync(): Promise<boolean> {\n const db = await this.getDbAsync();\n const result = await db.runAsync(STATEMENT_CLEAR);\n return result.changes > 0;\n }\n\n /**\n * Closes the database connection asynchronously.\n */\n async closeAsync(): Promise<void> {\n await this.awaitLock.acquireAsync();\n try {\n if (this.db) {\n await this.db.closeAsync();\n this.db = null;\n }\n } finally {\n this.awaitLock.release();\n }\n }\n\n //#endregion\n\n //#region Synchronous API\n\n /**\n * Retrieves the value associated with the given key synchronously.\n */\n getItemSync(key: string): string | null {\n this.checkValidInput(key);\n const db = this.getDbSync();\n const result = db.getFirstSync<{ value: string }>(STATEMENT_GET, key);\n return result?.value ?? null;\n }\n\n /**\n * Sets the value for the given key synchronously.\n * If a function is provided, it computes the new value based on the previous value.\n */\n setItemSync(key: string, value: string | SQLiteStorageSetItemUpdateFunction): void {\n this.checkValidInput(key, value);\n const db = this.getDbSync();\n\n if (typeof value === 'function') {\n db.withTransactionSync(() => {\n const prevResult = db.getFirstSync<{ value: string }>(STATEMENT_GET, key);\n const prevValue = prevResult?.value ?? null;\n const nextValue = value(prevValue);\n this.checkValidInput(key, nextValue);\n db.runSync(STATEMENT_SET, key, nextValue);\n });\n return;\n }\n\n db.runSync(STATEMENT_SET, key, value);\n }\n\n /**\n * Removes the value associated with the given key synchronously.\n */\n removeItemSync(key: string): boolean {\n this.checkValidInput(key);\n const db = this.getDbSync();\n const result = db.runSync(STATEMENT_REMOVE, key);\n return result.changes > 0;\n }\n\n /**\n * Retrieves all keys stored in the storage synchronously.\n */\n getAllKeysSync(): string[] {\n const db = this.getDbSync();\n const result = db.getAllSync<{ key: string }>(STATEMENT_GET_ALL_KEYS);\n return result.map(({ key }) => key);\n }\n\n /**\n * Clears all key-value pairs from the storage synchronously.\n */\n clearSync(): boolean {\n const db = this.getDbSync();\n const result = db.runSync(STATEMENT_CLEAR);\n return result.changes > 0;\n }\n\n /**\n * Closes the database connection synchronously.\n */\n closeSync(): void {\n if (this.db) {\n this.db.closeSync();\n this.db = null;\n }\n }\n\n //#endregion\n\n //#region react-native-async-storage compatible API\n\n /**\n * Alias for [`getItemAsync()`](#getitemasynckey) method.\n */\n async getItem(key: string): Promise<string | null> {\n return this.getItemAsync(key);\n }\n\n /**\n * Alias for [`setItemAsync()`](#setitemasynckey-value).\n */\n async setItem(key: string, value: string | SQLiteStorageSetItemUpdateFunction): Promise<void> {\n await this.setItemAsync(key, value);\n }\n\n /**\n * Alias for [`removeItemAsync()`](#removeitemasynckey) method.\n */\n async removeItem(key: string): Promise<void> {\n await this.removeItemAsync(key);\n }\n\n /**\n * Alias for [`getAllKeysAsync()`](#getallkeysasync) method.\n */\n async getAllKeys(): Promise<string[]> {\n return this.getAllKeysAsync();\n }\n\n /**\n * Alias for [`clearAsync()`](#clearasync) method.\n */\n async clear(): Promise<void> {\n await this.clearAsync();\n }\n\n /**\n * Merges the given value with the existing value for the given key asynchronously.\n * If the existing value is a JSON object, performs a deep merge.\n */\n async mergeItem(key: string, value: string): Promise<void> {\n this.checkValidInput(key, value);\n await this.setItemAsync(key, (prevValue) => {\n if (prevValue == null) {\n return value;\n }\n const prevJSON = JSON.parse(prevValue);\n const newJSON = JSON.parse(value);\n const mergedJSON = SQLiteStorage.mergeDeep(prevJSON, newJSON);\n return JSON.stringify(mergedJSON);\n });\n }\n\n /**\n * Retrieves the values associated with the given keys asynchronously.\n */\n async multiGet(keys: string[]): Promise<[string, string | null][]> {\n return Promise.all(\n keys.map(async (key): Promise<[string, string | null]> => {\n this.checkValidInput(key);\n return [key, await this.getItemAsync(key)];\n })\n );\n }\n\n /**\n * Sets multiple key-value pairs asynchronously.\n */\n async multiSet(keyValuePairs: [string, string][]): Promise<void> {\n const db = await this.getDbAsync();\n await db.withExclusiveTransactionAsync(async (tx) => {\n for (const [key, value] of keyValuePairs) {\n this.checkValidInput(key, value);\n await tx.runAsync(STATEMENT_SET, key, value);\n }\n });\n }\n\n /**\n * Removes the values associated with the given keys asynchronously.\n */\n async multiRemove(keys: string[]): Promise<void> {\n const db = await this.getDbAsync();\n await db.withExclusiveTransactionAsync(async (tx) => {\n for (const key of keys) {\n this.checkValidInput(key);\n await tx.runAsync(STATEMENT_REMOVE, key);\n }\n });\n }\n\n /**\n * Merges multiple key-value pairs asynchronously.\n * If existing values are JSON objects, performs a deep merge.\n */\n async multiMerge(keyValuePairs: [string, string][]): Promise<void> {\n const db = await this.getDbAsync();\n await db.withExclusiveTransactionAsync(async (tx) => {\n for (const [key, value] of keyValuePairs) {\n this.checkValidInput(key, value);\n const prevValue = await tx.getFirstAsync<{ value: string }>(STATEMENT_GET, key);\n if (prevValue == null) {\n await tx.runAsync(STATEMENT_SET, key, value);\n continue;\n }\n const prevJSON = JSON.parse(prevValue.value);\n const newJSON = JSON.parse(value);\n const mergedJSON = SQLiteStorage.mergeDeep(prevJSON, newJSON);\n await tx.runAsync(STATEMENT_SET, key, JSON.stringify(mergedJSON));\n }\n });\n }\n\n /**\n * Alias for [`closeAsync()`](#closeasync-1) method.\n */\n async close(): Promise<void> {\n await this.closeAsync();\n }\n\n //#endregion\n\n //#region Internals\n\n private async getDbAsync(): Promise<SQLiteDatabase> {\n await this.awaitLock.acquireAsync();\n try {\n if (!this.db) {\n const db = await openDatabaseAsync(this.databaseName);\n await this.maybeMigrateDbAsync(db);\n this.db = db;\n }\n } finally {\n this.awaitLock.release();\n }\n return this.db;\n }\n\n private getDbSync(): SQLiteDatabase {\n if (!this.db) {\n const db = openDatabaseSync(this.databaseName);\n this.maybeMigrateDbSync(db);\n this.db = db;\n }\n return this.db;\n }\n\n private maybeMigrateDbAsync(db: SQLiteDatabase) {\n return db.withTransactionAsync(async () => {\n const result = await db.getFirstAsync<{ user_version: number }>('PRAGMA user_version');\n let currentDbVersion = result?.user_version ?? 0;\n if (currentDbVersion >= DATABASE_VERSION) {\n return;\n }\n if (currentDbVersion === 0) {\n await db.execAsync(MIGRATION_STATEMENT_0);\n currentDbVersion = 1;\n }\n await db.execAsync(`PRAGMA user_version = ${DATABASE_VERSION}`);\n });\n }\n\n private maybeMigrateDbSync(db: SQLiteDatabase) {\n db.withTransactionSync(() => {\n const result = db.getFirstSync<{ user_version: number }>('PRAGMA user_version');\n let currentDbVersion = result?.user_version ?? 0;\n if (currentDbVersion >= DATABASE_VERSION) {\n return;\n }\n if (currentDbVersion === 0) {\n db.execSync(MIGRATION_STATEMENT_0);\n currentDbVersion = 1;\n }\n db.execSync(`PRAGMA user_version = ${DATABASE_VERSION}`);\n });\n }\n\n /**\n * Recursively merge two JSON objects.\n */\n private static mergeDeep(target: any, source: any): any {\n if (typeof target !== 'object' || target === null) {\n return source;\n }\n\n if (typeof source !== 'object' || source === null) {\n return target;\n }\n\n const output = { ...target };\n\n for (const key of Object.keys(source)) {\n if (source[key] instanceof Array) {\n if (!output[key]) {\n output[key] = [];\n }\n output[key] = output[key].concat(source[key]);\n } else if (typeof source[key] === 'object') {\n output[key] = this.mergeDeep(target[key], source[key]);\n } else {\n output[key] = source[key];\n }\n }\n\n return output;\n }\n\n private checkValidInput(...input: unknown[]) {\n const [key, value] = input;\n\n if (typeof key !== 'string') {\n throw new Error(\n `[SQLiteStorage] Using ${typeof key} type for key is not supported. Use string instead. Key passed: ${key}`\n );\n }\n\n if (input.length > 1 && typeof value !== 'string' && typeof value !== 'function') {\n throw new Error(\n `[SQLiteStorage] Using ${typeof value} type for value is not supported. Use string instead. Key passed: ${key}. Value passed : ${value}`\n );\n }\n }\n\n //#endregion\n}\n\n/**\n * This default instance of the [`SQLiteStorage`](#sqlitestorage-1) class is used as a drop-in replacement for the `AsyncStorage` module from [`@react-native-async-storage/async-storage`](https://github.com/react-native-async-storage/async-storage).\n */\nexport const AsyncStorage = new SQLiteStorage('ExpoSQLiteStorage');\n\nexport default AsyncStorage;\n\n/**\n * Alias for [`AsyncStorage`](#sqliteasyncstorage), given the storage not only offers asynchronous methods.\n */\nexport const Storage = AsyncStorage;\n"]}
1
+ {"version":3,"file":"Storage.js","sourceRoot":"","sources":["../src/Storage.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAuB,MAAM,SAAS,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AASr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,QAAQ,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CACb,yBAAyB,OAAO,GAAG,mEAAmE,GAAG,EAAE,CAC5G,CAAC;QACJ,CAAC;QAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;YACjF,MAAM,IAAI,KAAK,CACb,yBAAyB,OAAO,KAAK,qEAAqE,GAAG,oBAAoB,KAAK,EAAE,CACzI,CAAC;QACJ,CAAC;IACH,CAAC;CAEF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,aAAa,CAAC,mBAAmB,CAAC,CAAC;AAEnE,eAAe,YAAY,CAAC;AAE5B;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,YAAY,CAAC","sourcesContent":["import AwaitLock from 'await-lock';\n\nimport { openDatabaseAsync, openDatabaseSync, type SQLiteDatabase } from './index';\nimport { normalizeStorageIndex } from './paramUtils';\n\n/**\n * Update function for the [`setItemAsync()`](#setitemasynckey-value) or [`setItemSync()`](#setitemsynckey-value) method. It computes the new value based on the previous value. The function returns the new value to set for the key.\n * @param prevValue The previous value associated with the key, or `null` if the key was not set.\n * @returns The new value to set for the key.\n */\nexport type SQLiteStorageSetItemUpdateFunction = (prevValue: string | null) => string;\n\nconst DATABASE_VERSION = 1;\nconst STATEMENT_GET = 'SELECT value FROM storage WHERE key = ?;';\nconst STATEMENT_SET =\n 'INSERT INTO storage (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value;';\nconst STATEMENT_REMOVE = 'DELETE FROM storage WHERE key = ?;';\nconst STATEMENT_GET_ALL_KEYS = 'SELECT key FROM storage;';\nconst STATEMENT_CLEAR = 'DELETE FROM storage;';\nconst STATEMENT_LENGTH = 'SELECT COUNT(*) as count FROM storage;';\nconst STATEMENT_GET_KEY_BY_INDEX = 'SELECT key FROM storage LIMIT 1 OFFSET ?;';\n\nconst MIGRATION_STATEMENT_0 =\n 'CREATE TABLE IF NOT EXISTS storage (key TEXT PRIMARY KEY NOT NULL, value TEXT);';\n\n/**\n * Key-value store backed by SQLite. This class accepts a `databaseName` parameter in its constructor, which is the name of the database file to use for the storage.\n */\nexport class SQLiteStorage {\n private db: SQLiteDatabase | null = null;\n private readonly awaitLock = new AwaitLock();\n\n constructor(private readonly databaseName: string) {}\n\n //#region Asynchronous API\n\n /**\n * Retrieves the value associated with the given key asynchronously.\n */\n async getItemAsync(key: string): Promise<string | null> {\n this.checkValidInput(key);\n const db = await this.getDbAsync();\n const result = await db.getFirstAsync<{ value: string }>(STATEMENT_GET, key);\n return result?.value ?? null;\n }\n\n /**\n * Sets the value for the given key asynchronously.\n * If a function is provided, it computes the new value based on the previous value.\n */\n async setItemAsync(\n key: string,\n value: string | SQLiteStorageSetItemUpdateFunction\n ): Promise<void> {\n this.checkValidInput(key, value);\n const db = await this.getDbAsync();\n\n if (typeof value === 'function') {\n await db.withExclusiveTransactionAsync(async (tx) => {\n const prevResult = await tx.getFirstAsync<{ value: string }>(STATEMENT_GET, key);\n const prevValue = prevResult?.value ?? null;\n const nextValue = value(prevValue);\n this.checkValidInput(key, nextValue);\n await tx.runAsync(STATEMENT_SET, key, nextValue);\n });\n return;\n }\n\n await db.runAsync(STATEMENT_SET, key, value);\n }\n\n /**\n * Removes the value associated with the given key asynchronously.\n */\n async removeItemAsync(key: string): Promise<boolean> {\n this.checkValidInput(key);\n const db = await this.getDbAsync();\n const result = await db.runAsync(STATEMENT_REMOVE, key);\n return result.changes > 0;\n }\n\n /**\n * Retrieves all keys stored in the storage asynchronously.\n */\n async getAllKeysAsync(): Promise<string[]> {\n const db = await this.getDbAsync();\n const result = await db.getAllAsync<{ key: string }>(STATEMENT_GET_ALL_KEYS);\n return result.map(({ key }) => key);\n }\n\n /**\n * Clears all key-value pairs from the storage asynchronously.\n */\n async clearAsync(): Promise<boolean> {\n const db = await this.getDbAsync();\n const result = await db.runAsync(STATEMENT_CLEAR);\n return result.changes > 0;\n }\n\n /**\n * Closes the database connection asynchronously.\n */\n async closeAsync(): Promise<void> {\n await this.awaitLock.acquireAsync();\n try {\n if (this.db) {\n await this.db.closeAsync();\n this.db = null;\n }\n } finally {\n this.awaitLock.release();\n }\n }\n\n /**\n * Retrieves the number of key-value pairs stored in the storage asynchronously.\n */\n async getLengthAsync(): Promise<number> {\n const db = await this.getDbAsync();\n const result = await db.getFirstAsync<{ count: number }>(STATEMENT_LENGTH);\n return result?.count ?? 0;\n }\n\n /**\n * Retrieves the key at the given index asynchronously.\n */\n async getKeyByIndexAsync(index: number): Promise<string | null> {\n const db = await this.getDbAsync();\n const offset = normalizeStorageIndex(index);\n if (offset == null) {\n return null;\n }\n const result = await db.getFirstAsync<{ key: string }>(STATEMENT_GET_KEY_BY_INDEX, offset);\n return result?.key ?? null;\n }\n\n //#endregion\n\n //#region Synchronous API\n\n /**\n * Retrieves the value associated with the given key synchronously.\n */\n getItemSync(key: string): string | null {\n this.checkValidInput(key);\n const db = this.getDbSync();\n const result = db.getFirstSync<{ value: string }>(STATEMENT_GET, key);\n return result?.value ?? null;\n }\n\n /**\n * Sets the value for the given key synchronously.\n * If a function is provided, it computes the new value based on the previous value.\n */\n setItemSync(key: string, value: string | SQLiteStorageSetItemUpdateFunction): void {\n this.checkValidInput(key, value);\n const db = this.getDbSync();\n\n if (typeof value === 'function') {\n db.withTransactionSync(() => {\n const prevResult = db.getFirstSync<{ value: string }>(STATEMENT_GET, key);\n const prevValue = prevResult?.value ?? null;\n const nextValue = value(prevValue);\n this.checkValidInput(key, nextValue);\n db.runSync(STATEMENT_SET, key, nextValue);\n });\n return;\n }\n\n db.runSync(STATEMENT_SET, key, value);\n }\n\n /**\n * Removes the value associated with the given key synchronously.\n */\n removeItemSync(key: string): boolean {\n this.checkValidInput(key);\n const db = this.getDbSync();\n const result = db.runSync(STATEMENT_REMOVE, key);\n return result.changes > 0;\n }\n\n /**\n * Retrieves all keys stored in the storage synchronously.\n */\n getAllKeysSync(): string[] {\n const db = this.getDbSync();\n const result = db.getAllSync<{ key: string }>(STATEMENT_GET_ALL_KEYS);\n return result.map(({ key }) => key);\n }\n\n /**\n * Clears all key-value pairs from the storage synchronously.\n */\n clearSync(): boolean {\n const db = this.getDbSync();\n const result = db.runSync(STATEMENT_CLEAR);\n return result.changes > 0;\n }\n\n /**\n * Closes the database connection synchronously.\n */\n closeSync(): void {\n if (this.db) {\n this.db.closeSync();\n this.db = null;\n }\n }\n\n /**\n * Retrieves the number of key-value pairs stored in the storage synchronously.\n */\n getLengthSync(): number {\n const db = this.getDbSync();\n const result = db.getFirstSync<{ count: number }>(STATEMENT_LENGTH);\n return result!.count ?? 0;\n }\n\n /**\n * Retrieves the key at the given index synchronously.\n */\n getKeyByIndexSync(index: number): string | null {\n const db = this.getDbSync();\n const offset = normalizeStorageIndex(index);\n if (offset == null) {\n return null;\n }\n const result = db.getFirstSync<{ key: string }>(STATEMENT_GET_KEY_BY_INDEX, offset);\n return result?.key ?? null;\n }\n\n //#endregion\n\n //#region react-native-async-storage compatible API\n\n /**\n * Alias for [`getItemAsync()`](#getitemasynckey) method.\n */\n async getItem(key: string): Promise<string | null> {\n return this.getItemAsync(key);\n }\n\n /**\n * Alias for [`setItemAsync()`](#setitemasynckey-value).\n */\n async setItem(key: string, value: string | SQLiteStorageSetItemUpdateFunction): Promise<void> {\n await this.setItemAsync(key, value);\n }\n\n /**\n * Alias for [`removeItemAsync()`](#removeitemasynckey) method.\n */\n async removeItem(key: string): Promise<void> {\n await this.removeItemAsync(key);\n }\n\n /**\n * Alias for [`getAllKeysAsync()`](#getallkeysasync) method.\n */\n async getAllKeys(): Promise<string[]> {\n return this.getAllKeysAsync();\n }\n\n /**\n * Alias for [`clearAsync()`](#clearasync) method.\n */\n async clear(): Promise<void> {\n await this.clearAsync();\n }\n\n /**\n * Merges the given value with the existing value for the given key asynchronously.\n * If the existing value is a JSON object, performs a deep merge.\n */\n async mergeItem(key: string, value: string): Promise<void> {\n this.checkValidInput(key, value);\n await this.setItemAsync(key, (prevValue) => {\n if (prevValue == null) {\n return value;\n }\n const prevJSON = JSON.parse(prevValue);\n const newJSON = JSON.parse(value);\n const mergedJSON = SQLiteStorage.mergeDeep(prevJSON, newJSON);\n return JSON.stringify(mergedJSON);\n });\n }\n\n /**\n * Retrieves the values associated with the given keys asynchronously.\n */\n async multiGet(keys: string[]): Promise<[string, string | null][]> {\n return Promise.all(\n keys.map(async (key): Promise<[string, string | null]> => {\n this.checkValidInput(key);\n return [key, await this.getItemAsync(key)];\n })\n );\n }\n\n /**\n * Sets multiple key-value pairs asynchronously.\n */\n async multiSet(keyValuePairs: [string, string][]): Promise<void> {\n const db = await this.getDbAsync();\n await db.withExclusiveTransactionAsync(async (tx) => {\n for (const [key, value] of keyValuePairs) {\n this.checkValidInput(key, value);\n await tx.runAsync(STATEMENT_SET, key, value);\n }\n });\n }\n\n /**\n * Removes the values associated with the given keys asynchronously.\n */\n async multiRemove(keys: string[]): Promise<void> {\n const db = await this.getDbAsync();\n await db.withExclusiveTransactionAsync(async (tx) => {\n for (const key of keys) {\n this.checkValidInput(key);\n await tx.runAsync(STATEMENT_REMOVE, key);\n }\n });\n }\n\n /**\n * Merges multiple key-value pairs asynchronously.\n * If existing values are JSON objects, performs a deep merge.\n */\n async multiMerge(keyValuePairs: [string, string][]): Promise<void> {\n const db = await this.getDbAsync();\n await db.withExclusiveTransactionAsync(async (tx) => {\n for (const [key, value] of keyValuePairs) {\n this.checkValidInput(key, value);\n const prevValue = await tx.getFirstAsync<{ value: string }>(STATEMENT_GET, key);\n if (prevValue == null) {\n await tx.runAsync(STATEMENT_SET, key, value);\n continue;\n }\n const prevJSON = JSON.parse(prevValue.value);\n const newJSON = JSON.parse(value);\n const mergedJSON = SQLiteStorage.mergeDeep(prevJSON, newJSON);\n await tx.runAsync(STATEMENT_SET, key, JSON.stringify(mergedJSON));\n }\n });\n }\n\n /**\n * Alias for [`closeAsync()`](#closeasync-1) method.\n */\n async close(): Promise<void> {\n await this.closeAsync();\n }\n\n //#endregion\n\n //#region Internals\n\n private async getDbAsync(): Promise<SQLiteDatabase> {\n await this.awaitLock.acquireAsync();\n try {\n if (!this.db) {\n const db = await openDatabaseAsync(this.databaseName);\n await this.maybeMigrateDbAsync(db);\n this.db = db;\n }\n } finally {\n this.awaitLock.release();\n }\n return this.db;\n }\n\n private getDbSync(): SQLiteDatabase {\n if (!this.db) {\n const db = openDatabaseSync(this.databaseName);\n this.maybeMigrateDbSync(db);\n this.db = db;\n }\n return this.db;\n }\n\n private maybeMigrateDbAsync(db: SQLiteDatabase) {\n return db.withTransactionAsync(async () => {\n const result = await db.getFirstAsync<{ user_version: number }>('PRAGMA user_version');\n let currentDbVersion = result?.user_version ?? 0;\n if (currentDbVersion >= DATABASE_VERSION) {\n return;\n }\n if (currentDbVersion === 0) {\n await db.execAsync(MIGRATION_STATEMENT_0);\n currentDbVersion = 1;\n }\n await db.execAsync(`PRAGMA user_version = ${DATABASE_VERSION}`);\n });\n }\n\n private maybeMigrateDbSync(db: SQLiteDatabase) {\n db.withTransactionSync(() => {\n const result = db.getFirstSync<{ user_version: number }>('PRAGMA user_version');\n let currentDbVersion = result?.user_version ?? 0;\n if (currentDbVersion >= DATABASE_VERSION) {\n return;\n }\n if (currentDbVersion === 0) {\n db.execSync(MIGRATION_STATEMENT_0);\n currentDbVersion = 1;\n }\n db.execSync(`PRAGMA user_version = ${DATABASE_VERSION}`);\n });\n }\n\n /**\n * Recursively merge two JSON objects.\n */\n private static mergeDeep(target: any, source: any): any {\n if (typeof target !== 'object' || target === null) {\n return source;\n }\n\n if (typeof source !== 'object' || source === null) {\n return target;\n }\n\n const output = { ...target };\n\n for (const key of Object.keys(source)) {\n if (source[key] instanceof Array) {\n if (!output[key]) {\n output[key] = [];\n }\n output[key] = output[key].concat(source[key]);\n } else if (typeof source[key] === 'object') {\n output[key] = this.mergeDeep(target[key], source[key]);\n } else {\n output[key] = source[key];\n }\n }\n\n return output;\n }\n\n private checkValidInput(...input: unknown[]) {\n const [key, value] = input;\n\n if (typeof key !== 'string') {\n throw new Error(\n `[SQLiteStorage] Using ${typeof key} type for key is not supported. Use string instead. Key passed: ${key}`\n );\n }\n\n if (input.length > 1 && typeof value !== 'string' && typeof value !== 'function') {\n throw new Error(\n `[SQLiteStorage] Using ${typeof value} type for value is not supported. Use string instead. Key passed: ${key}. Value passed : ${value}`\n );\n }\n }\n //#endregion\n}\n\n/**\n * This default instance of the [`SQLiteStorage`](#sqlitestorage-1) class is used as a drop-in replacement for the `AsyncStorage` module from [`@react-native-async-storage/async-storage`](https://github.com/react-native-async-storage/async-storage).\n */\nexport const AsyncStorage = new SQLiteStorage('ExpoSQLiteStorage');\n\nexport default AsyncStorage;\n\n/**\n * Alias for [`AsyncStorage`](#sqliteasyncstorage), given the storage not only offers asynchronous methods.\n */\nexport const Storage = AsyncStorage;\n"]}
@@ -0,0 +1,22 @@
1
+ import { type SQLiteStorage } from './Storage';
2
+ declare class Storage {
3
+ private readonly storage;
4
+ constructor(storage: SQLiteStorage);
5
+ clear(): void;
6
+ getItem(key: string): string | null;
7
+ key(index: number): string | null;
8
+ removeItem(key: string): void;
9
+ setItem(key: string, value: string): void;
10
+ get length(): number;
11
+ toString(): string;
12
+ }
13
+ /**
14
+ * The default instance of the [`SQLiteStorage`](#sqlitestorage-1) class is used as a drop-in implementation for the [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) object from the Web.
15
+ */
16
+ export declare const localStorage: Storage & Record<string, string | undefined>;
17
+ /**
18
+ * Install the `localStorage` on the `globalThis` object.
19
+ */
20
+ export declare function installGlobal(): void;
21
+ export {};
22
+ //# sourceMappingURL=WebStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebStorage.d.ts","sourceRoot":"","sources":["../src/WebStorage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAErE,cAAM,OAAO;IACC,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,aAAa;IAEnD,KAAK,IAAI,IAAI;IAIb,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAInC,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIjC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAI7B,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIzC,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,QAAQ,IAAI,MAAM;CAGnB;AAiDD;;GAEG;AACH,eAAO,MAAM,YAAY,8CAAgD,CAAC;AAE1E;;GAEG;AACH,wBAAgB,aAAa,SAE5B"}