expo-sqlite 57.0.0 → 57.0.2

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 (46) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/android/build.gradle +2 -2
  3. package/build/Storage.d.ts.map +1 -1
  4. package/build/Storage.js +16 -10
  5. package/build/Storage.js.map +1 -1
  6. package/expo-module.config.json +1 -1
  7. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{57.0.0/expo.modules.sqlite-57.0.0.aar → 57.0.2/expo.modules.sqlite-57.0.2.aar} +0 -0
  8. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.2/expo.modules.sqlite-57.0.2.aar.md5 +1 -0
  9. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.2/expo.modules.sqlite-57.0.2.aar.sha1 +1 -0
  10. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.2/expo.modules.sqlite-57.0.2.aar.sha256 +1 -0
  11. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.2/expo.modules.sqlite-57.0.2.aar.sha512 +1 -0
  12. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{57.0.0/expo.modules.sqlite-57.0.0.module → 57.0.2/expo.modules.sqlite-57.0.2.module} +15 -15
  13. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.2/expo.modules.sqlite-57.0.2.module.md5 +1 -0
  14. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.2/expo.modules.sqlite-57.0.2.module.sha1 +1 -0
  15. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.2/expo.modules.sqlite-57.0.2.module.sha256 +1 -0
  16. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.2/expo.modules.sqlite-57.0.2.module.sha512 +1 -0
  17. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{57.0.0/expo.modules.sqlite-57.0.0.pom → 57.0.2/expo.modules.sqlite-57.0.2.pom} +1 -1
  18. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.2/expo.modules.sqlite-57.0.2.pom.md5 +1 -0
  19. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.2/expo.modules.sqlite-57.0.2.pom.sha1 +1 -0
  20. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.2/expo.modules.sqlite-57.0.2.pom.sha256 +1 -0
  21. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.2/expo.modules.sqlite-57.0.2.pom.sha512 +1 -0
  22. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/maven-metadata.xml +4 -4
  23. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/maven-metadata.xml.md5 +1 -1
  24. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/maven-metadata.xml.sha1 +1 -1
  25. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/maven-metadata.xml.sha256 +1 -1
  26. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/maven-metadata.xml.sha512 +1 -1
  27. package/package.json +4 -4
  28. package/plugin/tsconfig.tsbuildinfo +1 -1
  29. package/src/Storage.ts +20 -10
  30. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.0/expo.modules.sqlite-57.0.0.aar.md5 +0 -1
  31. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.0/expo.modules.sqlite-57.0.0.aar.sha1 +0 -1
  32. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.0/expo.modules.sqlite-57.0.0.aar.sha256 +0 -1
  33. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.0/expo.modules.sqlite-57.0.0.aar.sha512 +0 -1
  34. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.0/expo.modules.sqlite-57.0.0.module.md5 +0 -1
  35. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.0/expo.modules.sqlite-57.0.0.module.sha1 +0 -1
  36. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.0/expo.modules.sqlite-57.0.0.module.sha256 +0 -1
  37. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.0/expo.modules.sqlite-57.0.0.module.sha512 +0 -1
  38. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.0/expo.modules.sqlite-57.0.0.pom.md5 +0 -1
  39. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.0/expo.modules.sqlite-57.0.0.pom.sha1 +0 -1
  40. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.0/expo.modules.sqlite-57.0.0.pom.sha256 +0 -1
  41. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/57.0.0/expo.modules.sqlite-57.0.0.pom.sha512 +0 -1
  42. /package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{57.0.0/expo.modules.sqlite-57.0.0-sources.jar → 57.0.2/expo.modules.sqlite-57.0.2-sources.jar} +0 -0
  43. /package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{57.0.0/expo.modules.sqlite-57.0.0-sources.jar.md5 → 57.0.2/expo.modules.sqlite-57.0.2-sources.jar.md5} +0 -0
  44. /package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{57.0.0/expo.modules.sqlite-57.0.0-sources.jar.sha1 → 57.0.2/expo.modules.sqlite-57.0.2-sources.jar.sha1} +0 -0
  45. /package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{57.0.0/expo.modules.sqlite-57.0.0-sources.jar.sha256 → 57.0.2/expo.modules.sqlite-57.0.2-sources.jar.sha256} +0 -0
  46. /package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{57.0.0/expo.modules.sqlite-57.0.0-sources.jar.sha512 → 57.0.2/expo.modules.sqlite-57.0.2-sources.jar.sha512} +0 -0
package/CHANGELOG.md CHANGED
@@ -10,6 +10,16 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 57.0.2 — 2026-08-26
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - Fixed `SQLiteStorage` permanently throwing `no such table: storage` when the synchronous and asynchronous APIs raced the first-run migration. ([#48878](https://github.com/expo/expo/pull/48878) by [@giaBaoJS](https://github.com/giaBaoJS))
18
+
19
+ ## 57.0.1 — 2026-07-15
20
+
21
+ _This version does not introduce any user-facing changes._
22
+
13
23
  ## 57.0.0 — 2026-06-25
14
24
 
15
25
  _This version does not introduce any user-facing changes._
@@ -47,13 +47,13 @@ def reactNativeArchitectures() {
47
47
  }
48
48
 
49
49
  group = 'host.exp.exponent'
50
- version = '57.0.0'
50
+ version = '57.0.2'
51
51
 
52
52
  android {
53
53
  namespace "expo.modules.sqlite"
54
54
  defaultConfig {
55
55
  versionCode 18
56
- versionName "57.0.0"
56
+ versionName "57.0.2"
57
57
  buildConfigField "boolean", "USE_LIBSQL", project.ext.USE_LIBSQL.toString()
58
58
  buildConfigField "boolean", "WITH_SQLITE_VEC", project.ext.WITH_SQLITE_VEC.toString()
59
59
 
@@ -1 +1 @@
1
- {"version":3,"file":"Storage.d.ts","sourceRoot":"","sources":["../src/Storage.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,MAAM,MAAM,kCAAkC,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,KAAK,MAAM,CAAC;AAetF;;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,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db;
319
319
  }
320
320
  getDbSync() {
321
+ // NOTE: Unlike `getDbAsync()`, this cannot acquire `awaitLock` because the lock is
322
+ // promise-based and this method is synchronous. The migration is idempotent instead,
323
+ // so the next open repairs a database left without a `storage` table by a race.
321
324
  if (!this.db) {
322
325
  const db = openDatabaseSync(this.databaseName);
323
326
  this.maybeMigrateDbSync(db);
@@ -328,28 +331,31 @@ export class SQLiteStorage {
328
331
  maybeMigrateDbAsync(db) {
329
332
  return db.withTransactionAsync(async () => {
330
333
  const result = await db.getFirstAsync('PRAGMA user_version');
331
- let currentDbVersion = result?.user_version ?? 0;
334
+ const currentDbVersion = result?.user_version ?? 0;
335
+ // Baseline schema, deliberately outside the version ladder below. It is a
336
+ // `CREATE TABLE IF NOT EXISTS`, so it is a no-op on a healthy database and it also repairs
337
+ // one that a raced first-run migration left at `user_version >= 1` with no `storage` table.
338
+ // A new column has to be added here as well, so fresh and repaired databases also get it.
339
+ await db.execAsync(MIGRATION_STATEMENT_0);
340
+ // Version ladder: add each new migration below, gated on `currentDbVersion`. Since the
341
+ // baseline above already carries every column, a ladder entry that adds one has to
342
+ // tolerate it already being there. Gate it on `PRAGMA table_info(storage)`, or a fresh
343
+ // database fails the migration with `duplicate column name`.
332
344
  if (currentDbVersion >= DATABASE_VERSION) {
333
345
  return;
334
346
  }
335
- if (currentDbVersion === 0) {
336
- await db.execAsync(MIGRATION_STATEMENT_0);
337
- currentDbVersion = 1;
338
- }
339
347
  await db.execAsync(`PRAGMA user_version = ${DATABASE_VERSION}`);
340
348
  });
341
349
  }
342
350
  maybeMigrateDbSync(db) {
343
351
  db.withTransactionSync(() => {
344
352
  const result = db.getFirstSync('PRAGMA user_version');
345
- let currentDbVersion = result?.user_version ?? 0;
353
+ const currentDbVersion = result?.user_version ?? 0;
354
+ // Keep in sync with `maybeMigrateDbAsync()`, which documents the two steps below.
355
+ db.execSync(MIGRATION_STATEMENT_0);
346
356
  if (currentDbVersion >= DATABASE_VERSION) {
347
357
  return;
348
358
  }
349
- if (currentDbVersion === 0) {
350
- db.execSync(MIGRATION_STATEMENT_0);
351
- currentDbVersion = 1;
352
- }
353
359
  db.execSync(`PRAGMA user_version = ${DATABASE_VERSION}`);
354
360
  });
355
361
  }
@@ -1 +1 @@
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;AASrD,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,aAAa,GAAG,0CAA0C,CAAC;AACjE,MAAM,aAAa,GACjB,uGAAuG,CAAC;AAC1G,MAAM,gBAAgB,GAAG,oCAAoC,CAAC;AAC9D,MAAM,sBAAsB,GAAG,0BAA0B,CAAC;AAC1D,MAAM,eAAe,GAAG,sBAAsB,CAAC;AAC/C,MAAM,gBAAgB,GAAG,wCAAwC,CAAC;AAClE,MAAM,0BAA0B,GAAG,2CAA2C,CAAC;AAE/E,MAAM,qBAAqB,GACzB,iFAAiF,CAAC;AAEpF;;GAEG;AACH,MAAM,OAAO,aAAa;IAIK;IAHrB,EAAE,GAA0B,IAAI,CAAC;IACxB,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;IAE7C,YAA6B,YAAoB;QAApB,iBAAY,GAAZ,YAAY,CAAQ;IAAG,CAAC;IAErD,0BAA0B;IAE1B;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,GAAW;QAC5B,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QAC1B,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QACnC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,aAAa,CAAoB,aAAa,EAAE,GAAG,CAAC,CAAC;QAC7E,OAAO,MAAM,EAAE,KAAK,IAAI,IAAI,CA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AAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YACzD,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,eAAe,CAAC,GAAG,KAAgB;QACzC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,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;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"]}
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;AASrD,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,aAAa,GAAG,0CAA0C,CAAC;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AmE,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 // NOTE: Unlike `getDbAsync()`, this cannot acquire `awaitLock` because the lock is\n // promise-based and this method is synchronous. The migration is idempotent instead,\n // so the next open repairs a database left without a `storage` table by a race.\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 const currentDbVersion = result?.user_version ?? 0;\n\n // Baseline schema, deliberately outside the version ladder below. It is a\n // `CREATE TABLE IF NOT EXISTS`, so it is a no-op on a healthy database and it also repairs\n // one that a raced first-run migration left at `user_version >= 1` with no `storage` table.\n // A new column has to be added here as well, so fresh and repaired databases also get it.\n await db.execAsync(MIGRATION_STATEMENT_0);\n\n // Version ladder: add each new migration below, gated on `currentDbVersion`. Since the\n // baseline above already carries every column, a ladder entry that adds one has to\n // tolerate it already being there. Gate it on `PRAGMA table_info(storage)`, or a fresh\n // database fails the migration with `duplicate column name`.\n if (currentDbVersion >= DATABASE_VERSION) {\n return;\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 const currentDbVersion = result?.user_version ?? 0;\n\n // Keep in sync with `maybeMigrateDbAsync()`, which documents the two steps below.\n db.execSync(MIGRATION_STATEMENT_0);\n\n if (currentDbVersion >= DATABASE_VERSION) {\n return;\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"]}
@@ -9,7 +9,7 @@
9
9
  "publication": {
10
10
  "groupId": "host.exp.exponent",
11
11
  "artifactId": "expo.modules.sqlite",
12
- "version": "57.0.0",
12
+ "version": "57.0.2",
13
13
  "repository": "local-maven-repo"
14
14
  }
15
15
  },
@@ -0,0 +1 @@
1
+ df1da5f5381b01deb84c69e946436e98f69fb7a3c3f55c03b01e88061fd88e4d
@@ -0,0 +1 @@
1
+ 97b9f3c849ecda169a14bd40502d11b42a7db55e98a1ac3a33391a720bdac4748fd4e7fe190c1ab77c37aada7d932f7b587efa141949d4f4f281959e5e1a2475
@@ -3,7 +3,7 @@
3
3
  "component": {
4
4
  "group": "host.exp.exponent",
5
5
  "module": "expo.modules.sqlite",
6
- "version": "57.0.0",
6
+ "version": "57.0.2",
7
7
  "attributes": {
8
8
  "org.gradle.status": "release"
9
9
  }
@@ -24,13 +24,13 @@
24
24
  },
25
25
  "files": [
26
26
  {
27
- "name": "expo.modules.sqlite-57.0.0.aar",
28
- "url": "expo.modules.sqlite-57.0.0.aar",
27
+ "name": "expo.modules.sqlite-57.0.2.aar",
28
+ "url": "expo.modules.sqlite-57.0.2.aar",
29
29
  "size": 3823160,
30
- "sha512": "506ae5382744d7eef7435c54b037cdc7070a9b829180915260e50b5581571a5b090be8aa69a75a1e71a44af890234583ecd42be82fa277e62b9971abe3ad07bc",
31
- "sha256": "0e586f6e77c05913bf255634ab14739bab556215b86b3018c7846d2adb9fd81d",
32
- "sha1": "de857eb84f55165a2afe5e90cc6e66afe6990a4c",
33
- "md5": "635d7676b6e170c23e6ce7f5506aeadf"
30
+ "sha512": "97b9f3c849ecda169a14bd40502d11b42a7db55e98a1ac3a33391a720bdac4748fd4e7fe190c1ab77c37aada7d932f7b587efa141949d4f4f281959e5e1a2475",
31
+ "sha256": "df1da5f5381b01deb84c69e946436e98f69fb7a3c3f55c03b01e88061fd88e4d",
32
+ "sha1": "87f1f42b8d635fff98edf78cf7a123628dc369e0",
33
+ "md5": "89190f5fa83aadb89346c061f9cb6c34"
34
34
  }
35
35
  ]
36
36
  },
@@ -67,13 +67,13 @@
67
67
  ],
68
68
  "files": [
69
69
  {
70
- "name": "expo.modules.sqlite-57.0.0.aar",
71
- "url": "expo.modules.sqlite-57.0.0.aar",
70
+ "name": "expo.modules.sqlite-57.0.2.aar",
71
+ "url": "expo.modules.sqlite-57.0.2.aar",
72
72
  "size": 3823160,
73
- "sha512": "506ae5382744d7eef7435c54b037cdc7070a9b829180915260e50b5581571a5b090be8aa69a75a1e71a44af890234583ecd42be82fa277e62b9971abe3ad07bc",
74
- "sha256": "0e586f6e77c05913bf255634ab14739bab556215b86b3018c7846d2adb9fd81d",
75
- "sha1": "de857eb84f55165a2afe5e90cc6e66afe6990a4c",
76
- "md5": "635d7676b6e170c23e6ce7f5506aeadf"
73
+ "sha512": "97b9f3c849ecda169a14bd40502d11b42a7db55e98a1ac3a33391a720bdac4748fd4e7fe190c1ab77c37aada7d932f7b587efa141949d4f4f281959e5e1a2475",
74
+ "sha256": "df1da5f5381b01deb84c69e946436e98f69fb7a3c3f55c03b01e88061fd88e4d",
75
+ "sha1": "87f1f42b8d635fff98edf78cf7a123628dc369e0",
76
+ "md5": "89190f5fa83aadb89346c061f9cb6c34"
77
77
  }
78
78
  ]
79
79
  },
@@ -87,8 +87,8 @@
87
87
  },
88
88
  "files": [
89
89
  {
90
- "name": "expo.modules.sqlite-57.0.0-sources.jar",
91
- "url": "expo.modules.sqlite-57.0.0-sources.jar",
90
+ "name": "expo.modules.sqlite-57.0.2-sources.jar",
91
+ "url": "expo.modules.sqlite-57.0.2-sources.jar",
92
92
  "size": 11551,
93
93
  "sha512": "3b63d91aadb7a09514fc8fb158bb08caf92b6108cbc0876893b1a7a3fd33c1a4934c3b7912a858404f0a0eac7b854572fa90c90b8c93b9b52bde2204dcdab735",
94
94
  "sha256": "b8f668275e3ec93cff367011da2b3ae7bd83f43a690ce56473395ba6284c8b7c",
@@ -0,0 +1 @@
1
+ c93569dd661c1229cf4dd11f95777d1393298b14594803957f8fc6ca6ec31c4f
@@ -0,0 +1 @@
1
+ f2b4ce5c245f0db1c269e117fcd5331790142445f2671d4d44affa3d5ea867247094d3a24304f938e7956a1596779854a5345d323d558b03a423ac3d37e4cddb
@@ -9,7 +9,7 @@
9
9
  <modelVersion>4.0.0</modelVersion>
10
10
  <groupId>host.exp.exponent</groupId>
11
11
  <artifactId>expo.modules.sqlite</artifactId>
12
- <version>57.0.0</version>
12
+ <version>57.0.2</version>
13
13
  <packaging>aar</packaging>
14
14
  <name>expo.modules.sqlite</name>
15
15
  <url>https://github.com/expo/expo</url>
@@ -0,0 +1 @@
1
+ 94cafda0638ad1c46827badb1c67105c365a281ba54c504a42d6bc776502ef7a
@@ -0,0 +1 @@
1
+ bc7961c892e2d30f9cf5f01d24f004f3db07c1771e3c36601051297d3ea2eb3f201483444a1ff471b0e354a7d7e1d22b6beb2cf82b4d3ad3df5e293db52b479e
@@ -3,11 +3,11 @@
3
3
  <groupId>host.exp.exponent</groupId>
4
4
  <artifactId>expo.modules.sqlite</artifactId>
5
5
  <versioning>
6
- <latest>57.0.0</latest>
7
- <release>57.0.0</release>
6
+ <latest>57.0.2</latest>
7
+ <release>57.0.2</release>
8
8
  <versions>
9
- <version>57.0.0</version>
9
+ <version>57.0.2</version>
10
10
  </versions>
11
- <lastUpdated>20260625191818</lastUpdated>
11
+ <lastUpdated>20260826195101</lastUpdated>
12
12
  </versioning>
13
13
  </metadata>
@@ -1 +1 @@
1
- 35ea8b4ad2d6eb205f6f32d8e9902a7c
1
+ 943bd6c6ba9001f5ecb3af4fafd4ee84
@@ -1 +1 @@
1
- da1b16fbc81fdf599af898b3e77913ebfd5444b7
1
+ 38b42af796fdf4c637ca73590228fe51f3877fc6
@@ -1 +1 @@
1
- 08cd9a01b9c686b34e4e06ba4ee74cf6b30a5fb6d05e8c4fe61d23c40fb7e73e
1
+ b659d913f40205a82cd7946c8b61143cf236763b3d2d1bcb8a82e1462208f144
@@ -1 +1 @@
1
- a3bee262883fc0ee0db65d42bb7b1ff33260c084ac218d30a42980807a599542e342c4f03ddf00043d48e2a45745e8d1d3347ff1a53a43fa2aa3bb3a0c11ef6d
1
+ dcfecae5accd596d83855b3ec6db25dd71f085a18c50ec44b2afeb9916ee3fc7f5db84c9daef74075e58dc29b8c11c1591f5fe6b783324a7bb14d14ea8ea3568
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-sqlite",
3
- "version": "57.0.0",
3
+ "version": "57.0.2",
4
4
  "description": "Provides access to a database using SQLite (https://www.sqlite.org/). The database is persisted across restarts of your app.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -55,15 +55,15 @@
55
55
  "@types/react": "~19.2.0",
56
56
  "better-sqlite3": "^11.6.0",
57
57
  "react-error-boundary": "^4.0.11",
58
- "expo": "57.0.0-preview.0",
59
- "expo-module-scripts": "56.0.3"
58
+ "expo-module-scripts": "56.0.3",
59
+ "expo": "57.0.17"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "expo": "*",
63
63
  "react": "*",
64
64
  "react-native": "*"
65
65
  },
66
- "gitHead": "e3eb896c5fdcd89e0cded98ff4e35c9db12cc9c0",
66
+ "gitHead": "c300d2cc60c9e684e64f48d9bc90ea18a571d01d",
67
67
  "scripts": {
68
68
  "build": "expo-module build",
69
69
  "bundle:webui": "pushd dev-plugin-webui && bun run build && popd && rm -rf dev-plugin-dist && mv dev-plugin-webui/dist dev-plugin-dist",
@@ -1 +1 @@
1
- {"root":["./src/index.ts","./src/withsqlite.ts"],"version":"6.0.3"}
1
+ {"root":["./src/withsqlite.ts"],"version":"5.9.2"}
package/src/Storage.ts CHANGED
@@ -372,6 +372,9 @@ export class SQLiteStorage {
372
372
  }
373
373
 
374
374
  private getDbSync(): SQLiteDatabase {
375
+ // NOTE: Unlike `getDbAsync()`, this cannot acquire `awaitLock` because the lock is
376
+ // promise-based and this method is synchronous. The migration is idempotent instead,
377
+ // so the next open repairs a database left without a `storage` table by a race.
375
378
  if (!this.db) {
376
379
  const db = openDatabaseSync(this.databaseName);
377
380
  this.maybeMigrateDbSync(db);
@@ -383,14 +386,21 @@ export class SQLiteStorage {
383
386
  private maybeMigrateDbAsync(db: SQLiteDatabase) {
384
387
  return db.withTransactionAsync(async () => {
385
388
  const result = await db.getFirstAsync<{ user_version: number }>('PRAGMA user_version');
386
- let currentDbVersion = result?.user_version ?? 0;
389
+ const currentDbVersion = result?.user_version ?? 0;
390
+
391
+ // Baseline schema, deliberately outside the version ladder below. It is a
392
+ // `CREATE TABLE IF NOT EXISTS`, so it is a no-op on a healthy database and it also repairs
393
+ // one that a raced first-run migration left at `user_version >= 1` with no `storage` table.
394
+ // A new column has to be added here as well, so fresh and repaired databases also get it.
395
+ await db.execAsync(MIGRATION_STATEMENT_0);
396
+
397
+ // Version ladder: add each new migration below, gated on `currentDbVersion`. Since the
398
+ // baseline above already carries every column, a ladder entry that adds one has to
399
+ // tolerate it already being there. Gate it on `PRAGMA table_info(storage)`, or a fresh
400
+ // database fails the migration with `duplicate column name`.
387
401
  if (currentDbVersion >= DATABASE_VERSION) {
388
402
  return;
389
403
  }
390
- if (currentDbVersion === 0) {
391
- await db.execAsync(MIGRATION_STATEMENT_0);
392
- currentDbVersion = 1;
393
- }
394
404
  await db.execAsync(`PRAGMA user_version = ${DATABASE_VERSION}`);
395
405
  });
396
406
  }
@@ -398,14 +408,14 @@ export class SQLiteStorage {
398
408
  private maybeMigrateDbSync(db: SQLiteDatabase) {
399
409
  db.withTransactionSync(() => {
400
410
  const result = db.getFirstSync<{ user_version: number }>('PRAGMA user_version');
401
- let currentDbVersion = result?.user_version ?? 0;
411
+ const currentDbVersion = result?.user_version ?? 0;
412
+
413
+ // Keep in sync with `maybeMigrateDbAsync()`, which documents the two steps below.
414
+ db.execSync(MIGRATION_STATEMENT_0);
415
+
402
416
  if (currentDbVersion >= DATABASE_VERSION) {
403
417
  return;
404
418
  }
405
- if (currentDbVersion === 0) {
406
- db.execSync(MIGRATION_STATEMENT_0);
407
- currentDbVersion = 1;
408
- }
409
419
  db.execSync(`PRAGMA user_version = ${DATABASE_VERSION}`);
410
420
  });
411
421
  }
@@ -1 +0,0 @@
1
- de857eb84f55165a2afe5e90cc6e66afe6990a4c
@@ -1 +0,0 @@
1
- 0e586f6e77c05913bf255634ab14739bab556215b86b3018c7846d2adb9fd81d
@@ -1 +0,0 @@
1
- 506ae5382744d7eef7435c54b037cdc7070a9b829180915260e50b5581571a5b090be8aa69a75a1e71a44af890234583ecd42be82fa277e62b9971abe3ad07bc
@@ -1 +0,0 @@
1
- e637fb947fff61c91e61692c0f24ad4198c2084c6d6faef7a97bf04521d82c37
@@ -1 +0,0 @@
1
- 4e559a6dfda848b8b50ec909378cbaff0dca377b202b327865759894277659f99796fb8da8165f77073eb3539a26fce32cfa7a3b2817430aa123d5144b1af5b6
@@ -1 +0,0 @@
1
- 66420491ff856d7f32fb35db33eedb06e5809137
@@ -1 +0,0 @@
1
- c02a88d781032ae7c98bc4a25d57879694de604e718eda7a87b9395804ca1bb2
@@ -1 +0,0 @@
1
- ba4e63315c51b7222afb8702cee0d96e7cfb0bda3e0732e4f25fe82c60725b8c1fb375ee2579e048adc17e20eac05bed99fa5c5c432d2fba2f51423a046d01d1