expo-sqlite 13.0.0 → 13.1.0

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 (61) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/android/build.gradle +2 -2
  3. package/android/src/main/cpp/NativeDatabaseBinding.cpp +4 -4
  4. package/android/src/main/cpp/NativeDatabaseBinding.h +2 -2
  5. package/android/src/main/cpp/NativeStatementBinding.cpp +6 -0
  6. package/android/src/main/cpp/NativeStatementBinding.h +1 -0
  7. package/android/src/main/java/expo/modules/sqlite/NativeDatabase.kt +1 -1
  8. package/android/src/main/java/expo/modules/sqlite/NativeDatabaseBinding.kt +4 -4
  9. package/android/src/main/java/expo/modules/sqlite/NativeStatementBinding.kt +5 -4
  10. package/android/src/main/java/expo/modules/sqlite/SQLiteModule.kt +21 -21
  11. package/android/src/main/java/expo/modules/sqlite/SQLiteModuleNext.kt +55 -68
  12. package/build/next/ExpoSQLiteNext.d.ts +4 -4
  13. package/build/next/ExpoSQLiteNext.d.ts.map +1 -1
  14. package/build/next/ExpoSQLiteNext.js +3 -3
  15. package/build/next/ExpoSQLiteNext.js.map +1 -1
  16. package/build/next/NativeDatabase.d.ts +3 -3
  17. package/build/next/NativeDatabase.d.ts.map +1 -1
  18. package/build/next/NativeDatabase.js.map +1 -1
  19. package/build/next/NativeStatement.d.ts +37 -31
  20. package/build/next/NativeStatement.d.ts.map +1 -1
  21. package/build/next/NativeStatement.js.map +1 -1
  22. package/build/next/SQLiteDatabase.d.ts +266 -0
  23. package/build/next/SQLiteDatabase.d.ts.map +1 -0
  24. package/build/next/{Database.js → SQLiteDatabase.js} +69 -59
  25. package/build/next/SQLiteDatabase.js.map +1 -0
  26. package/build/next/SQLiteStatement.d.ts +190 -0
  27. package/build/next/SQLiteStatement.d.ts.map +1 -0
  28. package/build/next/SQLiteStatement.js +275 -0
  29. package/build/next/SQLiteStatement.js.map +1 -0
  30. package/build/next/hooks.d.ts +26 -14
  31. package/build/next/hooks.d.ts.map +1 -1
  32. package/build/next/hooks.js +121 -33
  33. package/build/next/hooks.js.map +1 -1
  34. package/build/next/index.d.ts +2 -2
  35. package/build/next/index.d.ts.map +1 -1
  36. package/build/next/index.js +2 -2
  37. package/build/next/index.js.map +1 -1
  38. package/build/next/paramUtils.d.ts +18 -0
  39. package/build/next/paramUtils.d.ts.map +1 -0
  40. package/build/next/paramUtils.js +72 -0
  41. package/build/next/paramUtils.js.map +1 -0
  42. package/ios/NativeDatabase.swift +3 -3
  43. package/ios/SQLiteModule.swift +17 -17
  44. package/ios/SQLiteModuleNext.swift +56 -77
  45. package/package.json +4 -3
  46. package/src/next/ExpoSQLiteNext.ts +4 -4
  47. package/src/next/NativeDatabase.ts +3 -3
  48. package/src/next/NativeStatement.ts +39 -58
  49. package/src/next/{Database.ts → SQLiteDatabase.ts} +134 -112
  50. package/src/next/SQLiteStatement.ts +528 -0
  51. package/src/next/hooks.tsx +202 -51
  52. package/src/next/index.ts +2 -2
  53. package/src/next/paramUtils.ts +94 -0
  54. package/build/next/Database.d.ts +0 -272
  55. package/build/next/Database.d.ts.map +0 -1
  56. package/build/next/Database.js.map +0 -1
  57. package/build/next/Statement.d.ts +0 -140
  58. package/build/next/Statement.d.ts.map +0 -1
  59. package/build/next/Statement.js +0 -173
  60. package/build/next/Statement.js.map +0 -1
  61. package/src/next/Statement.ts +0 -315
@@ -1,16 +1,16 @@
1
1
  import { EventEmitter } from 'expo-modules-core';
2
2
  import ExpoSQLite from './ExpoSQLiteNext';
3
- import { Statement } from './Statement';
3
+ import { SQLiteStatement, } from './SQLiteStatement';
4
4
  const emitter = new EventEmitter(ExpoSQLite);
5
5
  /**
6
6
  * A SQLite database.
7
7
  */
8
- export class Database {
9
- dbName;
8
+ export class SQLiteDatabase {
9
+ databaseName;
10
10
  options;
11
11
  nativeDatabase;
12
- constructor(dbName, options, nativeDatabase) {
13
- this.dbName = dbName;
12
+ constructor(databaseName, options, nativeDatabase) {
13
+ this.databaseName = databaseName;
14
14
  this.options = options;
15
15
  this.nativeDatabase = nativeDatabase;
16
16
  }
@@ -36,14 +36,14 @@ export class Database {
36
36
  return this.nativeDatabase.execAsync(source);
37
37
  }
38
38
  /**
39
- * Prepare a SQL statement.
39
+ * Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).
40
40
  *
41
41
  * @param source A string containing the SQL query.
42
42
  */
43
43
  async prepareAsync(source) {
44
44
  const nativeStatement = new ExpoSQLite.NativeStatement();
45
45
  await this.nativeDatabase.prepareAsync(nativeStatement, source);
46
- return new Statement(this.nativeDatabase, nativeStatement);
46
+ return new SQLiteStatement(this.nativeDatabase, nativeStatement);
47
47
  }
48
48
  /**
49
49
  * Execute a transaction and automatically commit/rollback based on the `task` result.
@@ -51,7 +51,7 @@ export class Database {
51
51
  * > **Note:** This transaction is not exclusive and can be interrupted by other async queries.
52
52
  * @example
53
53
  * ```ts
54
- * db.transactionAsync(async () => {
54
+ * db.withTransactionAsync(async () => {
55
55
  * await db.execAsync('UPDATE test SET name = "aaa"');
56
56
  *
57
57
  * //
@@ -64,11 +64,11 @@ export class Database {
64
64
  * });
65
65
  * db.execAsync('UPDATE test SET name = "bbb"');
66
66
  * ```
67
- * If you worry about the order of execution, use `transactionExclusiveAsync` instead.
67
+ * If you worry about the order of execution, use `withExclusiveTransactionAsync` instead.
68
68
  *
69
69
  * @param task An async function to execute within a transaction.
70
70
  */
71
- async transactionAsync(task) {
71
+ async withTransactionAsync(task) {
72
72
  try {
73
73
  await this.execAsync('BEGIN');
74
74
  await task();
@@ -87,16 +87,16 @@ export class Database {
87
87
  * the other async write queries will abort with `database is locked` error.
88
88
  *
89
89
  * @param task An async function to execute within a transaction. Any queries inside the transaction must be executed on the `txn` object.
90
- * The `txn` object has the same interfaces as the `Database` object. You can use `txn` like a `Database` object.
90
+ * The `txn` object has the same interfaces as the [`SQLiteDatabase`](#sqlitedatabase) object. You can use `txn` like a [`SQLiteDatabase`](#sqlitedatabase) object.
91
91
  *
92
92
  * @example
93
93
  * ```ts
94
- * db.transactionExclusiveAsync(async (txn) => {
94
+ * db.withExclusiveTransactionAsync(async (txn) => {
95
95
  * await txn.execAsync('UPDATE test SET name = "aaa"');
96
96
  * });
97
97
  * ```
98
98
  */
99
- async transactionExclusiveAsync(task) {
99
+ async withExclusiveTransactionAsync(task) {
100
100
  const transaction = await Transaction.createAsync(this);
101
101
  let error;
102
102
  try {
@@ -140,7 +140,7 @@ export class Database {
140
140
  return this.nativeDatabase.execSync(source);
141
141
  }
142
142
  /**
143
- * Prepare a SQL statement.
143
+ * Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).
144
144
  *
145
145
  * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
146
146
  *
@@ -149,7 +149,7 @@ export class Database {
149
149
  prepareSync(source) {
150
150
  const nativeStatement = new ExpoSQLite.NativeStatement();
151
151
  this.nativeDatabase.prepareSync(nativeStatement, source);
152
- return new Statement(this.nativeDatabase, nativeStatement);
152
+ return new SQLiteStatement(this.nativeDatabase, nativeStatement);
153
153
  }
154
154
  /**
155
155
  * Execute a transaction and automatically commit/rollback based on the `task` result.
@@ -158,7 +158,7 @@ export class Database {
158
158
  *
159
159
  * @param task An async function to execute within a transaction.
160
160
  */
161
- transactionSync(task) {
161
+ withTransactionSync(task) {
162
162
  try {
163
163
  this.execSync('BEGIN');
164
164
  task();
@@ -173,151 +173,161 @@ export class Database {
173
173
  const statement = await this.prepareAsync(source);
174
174
  let result;
175
175
  try {
176
- result = await statement.runAsync(...params);
176
+ result = await statement.executeAsync(...params);
177
177
  }
178
178
  finally {
179
179
  await statement.finalizeAsync();
180
180
  }
181
181
  return result;
182
182
  }
183
- async getAsync(source, ...params) {
183
+ async getFirstAsync(source, ...params) {
184
184
  const statement = await this.prepareAsync(source);
185
- let result;
185
+ let firstRow;
186
186
  try {
187
- result = await statement.getAsync(...params);
187
+ const result = await statement.executeAsync(...params);
188
+ firstRow = await result.getFirstAsync();
188
189
  }
189
190
  finally {
190
191
  await statement.finalizeAsync();
191
192
  }
192
- return result;
193
+ return firstRow;
193
194
  }
194
- async *eachAsync(source, ...params) {
195
+ async *getEachAsync(source, ...params) {
195
196
  const statement = await this.prepareAsync(source);
196
197
  try {
197
- yield* await statement.eachAsync(...params);
198
+ const result = await statement.executeAsync(...params);
199
+ for await (const row of result) {
200
+ yield row;
201
+ }
198
202
  }
199
203
  finally {
200
204
  await statement.finalizeAsync();
201
205
  }
202
206
  }
203
- async allAsync(source, ...params) {
207
+ async getAllAsync(source, ...params) {
204
208
  const statement = await this.prepareAsync(source);
205
- let result;
209
+ let allRows;
206
210
  try {
207
- result = await statement.allAsync(...params);
211
+ const result = await statement.executeAsync(...params);
212
+ allRows = await result.getAllAsync();
208
213
  }
209
214
  finally {
210
215
  await statement.finalizeAsync();
211
216
  }
212
- return result;
217
+ return allRows;
213
218
  }
214
219
  runSync(source, ...params) {
215
220
  const statement = this.prepareSync(source);
216
221
  let result;
217
222
  try {
218
- result = statement.runSync(...params);
223
+ result = statement.executeSync(...params);
219
224
  }
220
225
  finally {
221
226
  statement.finalizeSync();
222
227
  }
223
228
  return result;
224
229
  }
225
- getSync(source, ...params) {
230
+ getFirstSync(source, ...params) {
226
231
  const statement = this.prepareSync(source);
227
- let result;
232
+ let firstRow;
228
233
  try {
229
- result = statement.getSync(...params);
234
+ const result = statement.executeSync(...params);
235
+ firstRow = result.getFirstSync();
230
236
  }
231
237
  finally {
232
238
  statement.finalizeSync();
233
239
  }
234
- return result;
240
+ return firstRow;
235
241
  }
236
- *eachSync(source, ...params) {
242
+ *getEachSync(source, ...params) {
237
243
  const statement = this.prepareSync(source);
238
244
  try {
239
- yield* statement.eachSync(...params);
245
+ const result = statement.executeSync(...params);
246
+ for (const row of result) {
247
+ yield row;
248
+ }
240
249
  }
241
250
  finally {
242
251
  statement.finalizeSync();
243
252
  }
244
253
  }
245
- allSync(source, ...params) {
254
+ getAllSync(source, ...params) {
246
255
  const statement = this.prepareSync(source);
247
- let result;
256
+ let allRows;
248
257
  try {
249
- result = statement.allSync(...params);
258
+ const result = statement.executeSync(...params);
259
+ allRows = result.getAllSync();
250
260
  }
251
261
  finally {
252
262
  statement.finalizeSync();
253
263
  }
254
- return result;
264
+ return allRows;
255
265
  }
256
266
  }
257
267
  /**
258
268
  * Open a database.
259
269
  *
260
- * @param dbName The name of the database file to open.
270
+ * @param databaseName The name of the database file to open.
261
271
  * @param options Open options.
262
272
  */
263
- export async function openDatabaseAsync(dbName, options) {
273
+ export async function openDatabaseAsync(databaseName, options) {
264
274
  const openOptions = options ?? {};
265
- const nativeDatabase = new ExpoSQLite.NativeDatabase(dbName, openOptions);
275
+ const nativeDatabase = new ExpoSQLite.NativeDatabase(databaseName, openOptions);
266
276
  await nativeDatabase.initAsync();
267
- return new Database(dbName, openOptions, nativeDatabase);
277
+ return new SQLiteDatabase(databaseName, openOptions, nativeDatabase);
268
278
  }
269
279
  /**
270
280
  * Open a database.
271
281
  *
272
282
  * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
273
283
  *
274
- * @param dbName The name of the database file to open.
284
+ * @param databaseName The name of the database file to open.
275
285
  * @param options Open options.
276
286
  */
277
- export function openDatabaseSync(dbName, options) {
287
+ export function openDatabaseSync(databaseName, options) {
278
288
  const openOptions = options ?? {};
279
- const nativeDatabase = new ExpoSQLite.NativeDatabase(dbName, openOptions);
289
+ const nativeDatabase = new ExpoSQLite.NativeDatabase(databaseName, openOptions);
280
290
  nativeDatabase.initSync();
281
- return new Database(dbName, openOptions, nativeDatabase);
291
+ return new SQLiteDatabase(databaseName, openOptions, nativeDatabase);
282
292
  }
283
293
  /**
284
294
  * Delete a database file.
285
295
  *
286
- * @param dbName The name of the database file to delete.
296
+ * @param databaseName The name of the database file to delete.
287
297
  */
288
- export async function deleteDatabaseAsync(dbName) {
289
- return await ExpoSQLite.deleteDatabaseAsync(dbName);
298
+ export async function deleteDatabaseAsync(databaseName) {
299
+ return await ExpoSQLite.deleteDatabaseAsync(databaseName);
290
300
  }
291
301
  /**
292
302
  * Delete a database file.
293
303
  *
294
304
  * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
295
305
  *
296
- * @param dbName The name of the database file to delete.
306
+ * @param databaseName The name of the database file to delete.
297
307
  */
298
- export function deleteDatabaseSync(dbName) {
299
- return ExpoSQLite.deleteDatabaseSync(dbName);
308
+ export function deleteDatabaseSync(databaseName) {
309
+ return ExpoSQLite.deleteDatabaseSync(databaseName);
300
310
  }
301
311
  /**
302
312
  * Add a listener for database changes.
303
- * > Note: to enable this feature, you must set [`enableChangeListener` to `true`](#openoptions) when opening the database.
313
+ * > Note: to enable this feature, you must set [`enableChangeListener` to `true`](#sqliteopenoptions) when opening the database.
304
314
  *
305
- * @param listener A function that receives the `dbFilePath`, `dbName`, `tableName` and `rowId` of the modified data.
315
+ * @param listener A function that receives the `databaseName`, `databaseFilePath`, `tableName` and `rowId` of the modified data.
306
316
  * @returns A `Subscription` object that you can call `remove()` on when you would like to unsubscribe the listener.
307
317
  */
308
318
  export function addDatabaseChangeListener(listener) {
309
319
  return emitter.addListener('onDatabaseChange', listener);
310
320
  }
311
321
  /**
312
- * A new connection specific used for [`transactionExclusiveAsync`](#transactionexclusiveasynctask).
322
+ * A new connection specific used for [`withExclusiveTransactionAsync`](#withexclusivetransactionasynctask).
313
323
  * @hidden not going to pull all the database methods to the document.
314
324
  */
315
- class Transaction extends Database {
325
+ class Transaction extends SQLiteDatabase {
316
326
  static async createAsync(db) {
317
327
  const options = { ...db.options, useNewConnection: true };
318
- const nativeDatabase = new ExpoSQLite.NativeDatabase(db.dbName, options);
328
+ const nativeDatabase = new ExpoSQLite.NativeDatabase(db.databaseName, options);
319
329
  await nativeDatabase.initAsync();
320
- return new Transaction(db.dbName, options, nativeDatabase);
330
+ return new Transaction(db.databaseName, options, nativeDatabase);
321
331
  }
322
332
  }
323
- //# sourceMappingURL=Database.js.map
333
+ //# sourceMappingURL=SQLiteDatabase.js.map
@@ -0,0 +1 @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AAE,CAAC;IAClC,MAAM,cAAc,GAAG,IAAI,UAAU,CAAC,cAAc,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IAChF,cAAc,CAAC,QAAQ,EAAE,CAAC;IAC1B,OAAO,IAAI,cAAc,CAAC,YAAY,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;AACvE,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,YAAoB;IAC5D,OAAO,MAAM,UAAU,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,YAAoB;IACrD,OAAO,UAAU,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;AACrD,CAAC;AAmBD;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CACvC,QAA8C;IAE9C,OAAO,OAAO,CAAC,WAAW,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;AAC3D,CAAC;AAED;;;GAGG;AACH,MAAM,WAAY,SAAQ,cAAc;IAC/B,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,EAAkB;QAChD,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC;QAC1D,MAAM,cAAc,GAAG,IAAI,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAC/E,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 { EventEmitter, Subscription } from 'expo-modules-core';\n\nimport ExpoSQLite from './ExpoSQLiteNext';\nimport { NativeDatabase, SQLiteOpenOptions } from './NativeDatabase';\nimport {\n SQLiteBindParams,\n SQLiteExecuteAsyncResult,\n SQLiteExecuteSyncResult,\n SQLiteRunResult,\n SQLiteStatement,\n SQLiteVariadicBindParams,\n} from './SQLiteStatement';\n\nexport { SQLiteOpenOptions };\n\nconst emitter = new EventEmitter(ExpoSQLite);\n\n/**\n * A SQLite database.\n */\nexport class SQLiteDatabase {\n constructor(\n public readonly databaseName: string,\n public readonly options: SQLiteOpenOptions,\n private 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 * 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 * 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 * @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.getAsync<{ 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 * @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 * @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 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 * 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 * 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 //#endregion\n}\n\n/**\n * Open a database.\n *\n * @param databaseName The name of the database file to open.\n * @param options Open options.\n */\nexport async function openDatabaseAsync(\n databaseName: string,\n options?: SQLiteOpenOptions\n): Promise<SQLiteDatabase> {\n const openOptions = options ?? {};\n const nativeDatabase = new ExpoSQLite.NativeDatabase(databaseName, openOptions);\n await nativeDatabase.initAsync();\n return new SQLiteDatabase(databaseName, 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 */\nexport function openDatabaseSync(\n databaseName: string,\n options?: SQLiteOpenOptions\n): SQLiteDatabase {\n const openOptions = options ?? {};\n const nativeDatabase = new ExpoSQLite.NativeDatabase(databaseName, openOptions);\n nativeDatabase.initSync();\n return new SQLiteDatabase(databaseName, openOptions, nativeDatabase);\n}\n\n/**\n * Delete a database file.\n *\n * @param databaseName The name of the database file to delete.\n */\nexport async function deleteDatabaseAsync(databaseName: string): Promise<void> {\n return await ExpoSQLite.deleteDatabaseAsync(databaseName);\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 */\nexport function deleteDatabaseSync(databaseName: string): void {\n return ExpoSQLite.deleteDatabaseSync(databaseName);\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): Subscription {\n return emitter.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(db.databaseName, options);\n await nativeDatabase.initAsync();\n return new Transaction(db.databaseName, options, nativeDatabase);\n }\n}\n"]}
@@ -0,0 +1,190 @@
1
+ import { NativeDatabase } from './NativeDatabase';
2
+ import { SQLiteBindParams, SQLiteBindValue, NativeStatement, SQLiteVariadicBindParams, type SQLiteRunResult } from './NativeStatement';
3
+ export { SQLiteBindParams, SQLiteBindValue, SQLiteRunResult, SQLiteVariadicBindParams };
4
+ /**
5
+ * A prepared statement returned by [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource) or [`SQLiteDatabase.prepareSync()`](#preparesyncsource) that can be binded with parameters and executed.
6
+ */
7
+ export declare class SQLiteStatement {
8
+ private readonly nativeDatabase;
9
+ private readonly nativeStatement;
10
+ constructor(nativeDatabase: NativeDatabase, nativeStatement: NativeStatement);
11
+ /**
12
+ * Run the prepared statement and return the [`SQLiteExecuteAsyncResult`](#sqliteexecuteasyncresult) instance.
13
+ * @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.
14
+ */
15
+ executeAsync<T>(params: SQLiteBindParams): Promise<SQLiteExecuteAsyncResult<T>>;
16
+ /**
17
+ * @hidden
18
+ */
19
+ executeAsync<T>(...params: SQLiteVariadicBindParams): Promise<SQLiteExecuteAsyncResult<T>>;
20
+ /**
21
+ * Get the column names of the prepared statement.
22
+ */
23
+ getColumnNamesAsync(): Promise<string[]>;
24
+ /**
25
+ * Finalize the prepared statement. This will call the [`sqlite3_finalize()`](https://www.sqlite.org/c3ref/finalize.html) C function under the hood.
26
+ *
27
+ * Attempting to access a finalized statement will result in an error.
28
+ * > **Note:** While expo-sqlite will automatically finalize any orphaned prepared statements upon closing the database, it is considered best practice to manually finalize prepared statements as soon as they are no longer needed. This helps to prevent resource leaks. You can use the `try...finally` statement to ensure that prepared statements are finalized even if an error occurs.
29
+ */
30
+ finalizeAsync(): Promise<void>;
31
+ /**
32
+ * Run the prepared statement and return the [`SQLiteExecuteSyncResult`](#sqliteexecutesyncresult) instance.
33
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
34
+ * @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.
35
+ */
36
+ executeSync<T>(params: SQLiteBindParams): SQLiteExecuteSyncResult<T>;
37
+ /**
38
+ * @hidden
39
+ */
40
+ executeSync<T>(...params: SQLiteVariadicBindParams): SQLiteExecuteSyncResult<T>;
41
+ /**
42
+ * Get the column names of the prepared statement.
43
+ */
44
+ getColumnNamesSync(): string[];
45
+ /**
46
+ * Finalize the prepared statement. This will call the [`sqlite3_finalize()`](https://www.sqlite.org/c3ref/finalize.html) C function under the hood.
47
+ *
48
+ * Attempting to access a finalized statement will result in an error.
49
+ * > **Note:** While expo-sqlite will automatically finalize any orphaned prepared statements upon closing the database, it is considered best practice to manually finalize prepared statements as soon as they are no longer needed. This helps to prevent resource leaks. You can use the `try...finally` statement to ensure that prepared statements are finalized even if an error occurs.
50
+ */
51
+ finalizeSync(): void;
52
+ }
53
+ /**
54
+ * A result returned by [`SQLiteStatement.executeAsync()`](#executeasyncparams).
55
+ *
56
+ * @example
57
+ * The result includes the [`lastInsertRowId`](https://www.sqlite.org/c3ref/last_insert_rowid.html) and [`changes`](https://www.sqlite.org/c3ref/changes.html) properties. You can get the information from the write operations.
58
+ * ```ts
59
+ * const statement = await db.prepareAsync('INSERT INTO test (value) VALUES (?)');
60
+ * try {
61
+ * const result = await statement.executeAsync(101);
62
+ * console.log('lastInsertRowId:', result.lastInsertRowId);
63
+ * console.log('changes:', result.changes);
64
+ * } finally {
65
+ * await statement.finalizeAsync();
66
+ * }
67
+ * ```
68
+ *
69
+ * @example
70
+ * The result implements the [`AsyncIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator) interface, so you can use it in `for await...of` loops.
71
+ * ```ts
72
+ * const statement = await db.prepareAsync('SELECT value FROM test WHERE value > ?');
73
+ * try {
74
+ * const result = await statement.executeAsync<{ value: number }>(100);
75
+ * for await (const row of result) {
76
+ * console.log('row value:', row.value);
77
+ * }
78
+ * } finally {
79
+ * await statement.finalizeAsync();
80
+ * }
81
+ * ```
82
+ *
83
+ * @example
84
+ * If your write operations also return values, you can mix all of them together.
85
+ * ```ts
86
+ * const statement = await db.prepareAsync('INSERT INTO test (name, value) VALUES (?, ?) RETURNING name');
87
+ * try {
88
+ * const result = await statement.executeAsync<{ name: string }>('John Doe', 101);
89
+ * console.log('lastInsertRowId:', result.lastInsertRowId);
90
+ * console.log('changes:', result.changes);
91
+ * for await (const row of result) {
92
+ * console.log('name:', row.name);
93
+ * }
94
+ * } finally {
95
+ * await statement.finalizeAsync();
96
+ * }
97
+ * ```
98
+ */
99
+ export interface SQLiteExecuteAsyncResult<T> extends AsyncIterableIterator<T> {
100
+ /**
101
+ * The last inserted row ID. Returned from the [`sqlite3_last_insert_rowid()`](https://www.sqlite.org/c3ref/last_insert_rowid.html) function.
102
+ */
103
+ readonly lastInsertRowId: number;
104
+ /**
105
+ * The number of rows affected. Returned from the [`sqlite3_changes()`](https://www.sqlite.org/c3ref/changes.html) function.
106
+ */
107
+ readonly changes: number;
108
+ /**
109
+ * Get the first row of the result set. This requires the SQLite cursor to be in its initial state. If you have already retrieved rows from the result set, you need to reset the cursor first by calling [`resetAsync()`](#resetasync). Otherwise, an error will be thrown.
110
+ */
111
+ getFirstAsync(): Promise<T | null>;
112
+ /**
113
+ * Get all rows of the result set. This requires the SQLite cursor to be in its initial state. If you have already retrieved rows from the result set, you need to reset the cursor first by calling [`resetAsync()`](#resetasync). Otherwise, an error will be thrown.
114
+ */
115
+ getAllAsync(): Promise<T[]>;
116
+ /**
117
+ * Reset the prepared statement cursor. This will call the [`sqlite3_reset()`](https://www.sqlite.org/c3ref/reset.html) C function under the hood.
118
+ */
119
+ resetAsync(): Promise<void>;
120
+ }
121
+ /**
122
+ * A result returned by [`SQLiteStatement.executeSync()`](#executesyncparams).
123
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
124
+
125
+ * @example
126
+ * The result includes the [`lastInsertRowId`](https://www.sqlite.org/c3ref/last_insert_rowid.html) and [`changes`](https://www.sqlite.org/c3ref/changes.html) properties. You can get the information from the write operations.
127
+ * ```ts
128
+ * const statement = db.prepareSync('INSERT INTO test (value) VALUES (?)');
129
+ * try {
130
+ * const result = statement.executeSync(101);
131
+ * console.log('lastInsertRowId:', result.lastInsertRowId);
132
+ * console.log('changes:', result.changes);
133
+ * } finally {
134
+ * statement.finalizeSync();
135
+ * }
136
+ * ```
137
+ *
138
+ * @example
139
+ * The result implements the [`Iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) interface, so you can use it in `for...of` loops.
140
+ * ```ts
141
+ * const statement = db.prepareSync('SELECT value FROM test WHERE value > ?');
142
+ * try {
143
+ * const result = statement.executeSync<{ value: number }>(100);
144
+ * for (const row of result) {
145
+ * console.log('row value:', row.value);
146
+ * }
147
+ * } finally {
148
+ * statement.finalizeSync();
149
+ * }
150
+ * ```
151
+ *
152
+ * @example
153
+ * If your write operations also return values, you can mix all of them together.
154
+ * ```ts
155
+ * const statement = db.prepareSync('INSERT INTO test (name, value) VALUES (?, ?) RETURNING name');
156
+ * try {
157
+ * const result = statement.executeSync<{ name: string }>('John Doe', 101);
158
+ * console.log('lastInsertRowId:', result.lastInsertRowId);
159
+ * console.log('changes:', result.changes);
160
+ * for (const row of result) {
161
+ * console.log('name:', row.name);
162
+ * }
163
+ * } finally {
164
+ * statement.finalizeSync();
165
+ * }
166
+ * ```
167
+ */
168
+ export interface SQLiteExecuteSyncResult<T> extends IterableIterator<T> {
169
+ /**
170
+ * The last inserted row ID. Returned from the [`sqlite3_last_insert_rowid()`](https://www.sqlite.org/c3ref/last_insert_rowid.html) function.
171
+ */
172
+ readonly lastInsertRowId: number;
173
+ /**
174
+ * The number of rows affected. Returned from the [`sqlite3_changes()`](https://www.sqlite.org/c3ref/changes.html) function.
175
+ */
176
+ readonly changes: number;
177
+ /**
178
+ * Get the first row of the result set. This requires the SQLite cursor to be in its initial state. If you have already retrieved rows from the result set, you need to reset the cursor first by calling [`resetSync()`](#resetsync). Otherwise, an error will be thrown.
179
+ */
180
+ getFirstSync(): T | null;
181
+ /**
182
+ * Get all rows of the result set. This requires the SQLite cursor to be in its initial state. If you have already retrieved rows from the result set, you need to reset the cursor first by calling [`resetSync()`](#resetsync). Otherwise, an error will be thrown.
183
+ */
184
+ getAllSync(): T[];
185
+ /**
186
+ * Reset the prepared statement cursor. This will call the [`sqlite3_reset()`](https://www.sqlite.org/c3ref/reset.html) C function under the hood.
187
+ */
188
+ resetSync(): void;
189
+ }
190
+ //# sourceMappingURL=SQLiteStatement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SQLiteStat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