expo-sqlite 12.0.0 → 12.2.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.
- package/CHANGELOG.md +23 -0
- package/android/build.gradle +4 -4
- package/android/src/main/cpp/NativeStatementBinding.cpp +19 -8
- package/android/src/main/cpp/NativeStatementBinding.h +2 -14
- package/android/src/main/java/expo/modules/sqlite/NativeStatementBinding.kt +4 -3
- package/android/src/main/java/expo/modules/sqlite/SQLiteModuleNext.kt +19 -12
- package/android/src/main/jniLibs/arm64-v8a/libcrsqlite.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libcrsqlite.so +0 -0
- package/android/src/main/jniLibs/x86/libcrsqlite.so +0 -0
- package/android/src/main/jniLibs/x86_64/libcrsqlite.so +0 -0
- package/build/SQLite.d.ts +2 -2
- package/build/SQLite.d.ts.map +1 -1
- package/build/SQLite.js.map +1 -1
- package/build/SQLite.types.d.ts +3 -2
- package/build/SQLite.types.d.ts.map +1 -1
- package/build/SQLite.types.js.map +1 -1
- package/build/next/Database.d.ts +91 -73
- package/build/next/Database.d.ts.map +1 -1
- package/build/next/Database.js +24 -25
- package/build/next/Database.js.map +1 -1
- package/build/next/NativeDatabase.d.ts +1 -1
- package/build/next/NativeDatabase.js.map +1 -1
- package/build/next/NativeStatement.d.ts +17 -14
- package/build/next/NativeStatement.d.ts.map +1 -1
- package/build/next/NativeStatement.js.map +1 -1
- package/build/next/Statement.d.ts +65 -43
- package/build/next/Statement.d.ts.map +1 -1
- package/build/next/Statement.js +76 -27
- package/build/next/Statement.js.map +1 -1
- package/build/next/hooks.d.ts +25 -0
- package/build/next/hooks.d.ts.map +1 -1
- package/build/next/hooks.js +39 -11
- package/build/next/hooks.js.map +1 -1
- package/ios/SQLiteModuleNext.swift +52 -35
- package/package.json +2 -2
- package/src/SQLite.ts +2 -1
- package/src/SQLite.types.ts +5 -2
- package/src/next/Database.ts +111 -92
- package/src/next/NativeDatabase.ts +1 -1
- package/src/next/NativeStatement.ts +25 -14
- package/src/next/Statement.ts +133 -66
- package/src/next/hooks.tsx +40 -12
- package/android/src/main/jniLibs/arm64/libcrsqlite.so +0 -0
package/src/next/Database.ts
CHANGED
|
@@ -14,6 +14,7 @@ const emitter = new EventEmitter(ExpoSQLite);
|
|
|
14
14
|
export class Database {
|
|
15
15
|
constructor(
|
|
16
16
|
public readonly dbName: string,
|
|
17
|
+
public readonly options: OpenOptions,
|
|
17
18
|
private readonly nativeDatabase: NativeDatabase
|
|
18
19
|
) {}
|
|
19
20
|
|
|
@@ -45,7 +46,6 @@ export class Database {
|
|
|
45
46
|
* Prepare a SQL statement.
|
|
46
47
|
*
|
|
47
48
|
* @param source A string containing the SQL query.
|
|
48
|
-
* @returns A `Statement` object.
|
|
49
49
|
*/
|
|
50
50
|
public async prepareAsync(source: string): Promise<Statement> {
|
|
51
51
|
const nativeStatement = new ExpoSQLite.NativeStatement();
|
|
@@ -140,7 +140,8 @@ export class Database {
|
|
|
140
140
|
* Execute all SQL queries in the supplied string.
|
|
141
141
|
*
|
|
142
142
|
* > **Note:** The queries are not escaped for you! Be careful when constructing your queries.
|
|
143
|
-
*
|
|
143
|
+
*
|
|
144
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
144
145
|
*
|
|
145
146
|
* @param source A string containing all the SQL queries.
|
|
146
147
|
*/
|
|
@@ -151,10 +152,9 @@ export class Database {
|
|
|
151
152
|
/**
|
|
152
153
|
* Prepare a SQL statement.
|
|
153
154
|
*
|
|
154
|
-
* > **Note:** Running heavy tasks with this function can block the JavaScript thread
|
|
155
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
155
156
|
*
|
|
156
157
|
* @param source A string containing the SQL query.
|
|
157
|
-
* @returns A `Statement` object.
|
|
158
158
|
*/
|
|
159
159
|
public prepareSync(source: string): Statement {
|
|
160
160
|
const nativeStatement = new ExpoSQLite.NativeStatement();
|
|
@@ -165,7 +165,7 @@ export class Database {
|
|
|
165
165
|
/**
|
|
166
166
|
* Execute a transaction and automatically commit/rollback based on the `task` result.
|
|
167
167
|
*
|
|
168
|
-
* > **Note:** Running heavy tasks with this function can block the JavaScript thread
|
|
168
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
169
169
|
*
|
|
170
170
|
* @param task An async function to execute within a transaction.
|
|
171
171
|
*/
|
|
@@ -183,16 +183,17 @@ export class Database {
|
|
|
183
183
|
//#region Statement API shorthands
|
|
184
184
|
|
|
185
185
|
/**
|
|
186
|
-
* Shorthand for `prepareAsync` and `Statement.runAsync
|
|
187
|
-
* Unlike `Statement.runAsync
|
|
188
|
-
*
|
|
189
|
-
* > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.
|
|
190
|
-
*
|
|
186
|
+
* Shorthand for [`prepareAsync()`](#prepareasyncsource) and [`Statement.runAsync()`](#runasyncparams).
|
|
187
|
+
* Unlike [`Statement.runAsync()`](#runasyncparams), this method finalizes the statement after execution.
|
|
191
188
|
* @param source A string containing the SQL query.
|
|
192
|
-
* @param params
|
|
189
|
+
* @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`BindValue`](#bindvalue) for more information about binding values.
|
|
193
190
|
*/
|
|
194
|
-
public runAsync(source: string, ...params: VariadicBindParams): Promise<RunResult>;
|
|
195
191
|
public runAsync(source: string, params: BindParams): Promise<RunResult>;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @hidden
|
|
195
|
+
*/
|
|
196
|
+
public runAsync(source: string, ...params: VariadicBindParams): Promise<RunResult>;
|
|
196
197
|
public async runAsync(source: string, ...params: any[]): Promise<RunResult> {
|
|
197
198
|
const statement = await this.prepareAsync(source);
|
|
198
199
|
let result;
|
|
@@ -205,16 +206,16 @@ export class Database {
|
|
|
205
206
|
}
|
|
206
207
|
|
|
207
208
|
/**
|
|
208
|
-
* Shorthand for `prepareAsync` and `Statement.getAsync
|
|
209
|
-
* Unlike `Statement.getAsync
|
|
210
|
-
*
|
|
211
|
-
* > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.
|
|
212
|
-
*
|
|
209
|
+
* Shorthand for [`prepareAsync()`](#prepareasyncsource) and [`Statement.getAsync()`](#getasyncparams).
|
|
210
|
+
* Unlike [`Statement.getAsync()`](#getasyncparams), this method finalizes the statement after execution.
|
|
213
211
|
* @param source A string containing the SQL query.
|
|
214
|
-
* @param params
|
|
212
|
+
* @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`BindValue`](#bindvalue) for more information about binding values.
|
|
215
213
|
*/
|
|
216
|
-
public getAsync<T>(source: string, ...params: VariadicBindParams): Promise<T | null>;
|
|
217
214
|
public getAsync<T>(source: string, params: BindParams): Promise<T | null>;
|
|
215
|
+
/**
|
|
216
|
+
* @hidden
|
|
217
|
+
*/
|
|
218
|
+
public getAsync<T>(source: string, ...params: VariadicBindParams): Promise<T | null>;
|
|
218
219
|
public async getAsync<T>(source: string, ...params: any[]): Promise<T | null> {
|
|
219
220
|
const statement = await this.prepareAsync(source);
|
|
220
221
|
let result;
|
|
@@ -227,38 +228,47 @@ export class Database {
|
|
|
227
228
|
}
|
|
228
229
|
|
|
229
230
|
/**
|
|
230
|
-
* Shorthand for `prepareAsync` and `Statement.eachAsync
|
|
231
|
-
* Unlike `Statement.eachAsync
|
|
232
|
-
*
|
|
233
|
-
* > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.
|
|
234
|
-
*
|
|
231
|
+
* Shorthand for [`prepareAsync()`](#prepareasyncsource) and [`Statement.eachAsync()`](#eachasyncparams).
|
|
232
|
+
* Unlike [`Statement.eachAsync()`](#eachasyncparams), this method finalizes the statement after execution.
|
|
235
233
|
* @param source A string containing the SQL query.
|
|
236
|
-
* @param params
|
|
234
|
+
* @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`BindValue`](#bindvalue) for more information about binding values.
|
|
237
235
|
*/
|
|
238
|
-
public eachAsync<T>(source: string, ...params: VariadicBindParams): AsyncIterableIterator<T>;
|
|
239
236
|
public eachAsync<T>(source: string, params: BindParams): AsyncIterableIterator<T>;
|
|
237
|
+
/**
|
|
238
|
+
* @hidden
|
|
239
|
+
*/
|
|
240
|
+
public eachAsync<T>(source: string, ...params: VariadicBindParams): AsyncIterableIterator<T>;
|
|
240
241
|
public async *eachAsync<T>(source: string, ...params: any[]): AsyncIterableIterator<T> {
|
|
241
242
|
const statement = await this.prepareAsync(source);
|
|
242
|
-
let result;
|
|
243
243
|
try {
|
|
244
|
-
|
|
244
|
+
yield* await statement.eachAsync<T>(...params);
|
|
245
245
|
} finally {
|
|
246
246
|
await statement.finalizeAsync();
|
|
247
247
|
}
|
|
248
|
-
yield* result;
|
|
249
248
|
}
|
|
250
249
|
|
|
251
250
|
/**
|
|
252
|
-
* Shorthand for `prepareAsync` and `Statement.allAsync
|
|
253
|
-
* Unlike `Statement.allAsync
|
|
251
|
+
* Shorthand for [`prepareAsync()`](#prepareasyncsource) and [`Statement.allAsync()`](#allasyncparams).
|
|
252
|
+
* Unlike [`Statement.allAsync()`](#allasyncparams), this method finalizes the statement after execution.
|
|
253
|
+
* @param source A string containing the SQL query.
|
|
254
|
+
* @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`BindValue`](#bindvalue) for more information about binding values.
|
|
255
|
+
* @example
|
|
256
|
+
* ```ts
|
|
257
|
+
* // For unnamed parameters, you pass values in an array.
|
|
258
|
+
* db.allAsync('SELECT * FROM test WHERE intValue = ? AND name = ?', [1, 'Hello']);
|
|
254
259
|
*
|
|
255
|
-
*
|
|
260
|
+
* // For unnamed parameters, you pass values in variadic arguments.
|
|
261
|
+
* db.allAsync('SELECT * FROM test WHERE intValue = ? AND name = ?', 1, 'Hello');
|
|
256
262
|
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
263
|
+
* // For named parameters, you should pass values in object.
|
|
264
|
+
* db.allAsync('SELECT * FROM test WHERE intValue = $intValue AND name = $name', { $intValue: 1, $name: 'Hello' });
|
|
265
|
+
* ```
|
|
259
266
|
*/
|
|
260
|
-
public allAsync<T>(source: string, ...params: VariadicBindParams): Promise<T[]>;
|
|
261
267
|
public allAsync<T>(source: string, params: BindParams): Promise<T[]>;
|
|
268
|
+
/**
|
|
269
|
+
* @hidden
|
|
270
|
+
*/
|
|
271
|
+
public allAsync<T>(source: string, ...params: VariadicBindParams): Promise<T[]>;
|
|
262
272
|
public async allAsync<T>(source: string, ...params: any[]): Promise<T[]> {
|
|
263
273
|
const statement = await this.prepareAsync(source);
|
|
264
274
|
let result;
|
|
@@ -271,16 +281,17 @@ export class Database {
|
|
|
271
281
|
}
|
|
272
282
|
|
|
273
283
|
/**
|
|
274
|
-
* Shorthand for `
|
|
275
|
-
* Unlike `Statement.runSync
|
|
276
|
-
*
|
|
277
|
-
* > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.
|
|
278
|
-
*
|
|
284
|
+
* Shorthand for [`prepareAsync()`](#prepareasyncsource) and [`Statement.runSync()`](#runsyncparams).
|
|
285
|
+
* Unlike [`Statement.runSync()`](#runsyncparams), this method finalizes the statement after execution.
|
|
286
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
279
287
|
* @param source A string containing the SQL query.
|
|
280
|
-
* @param params
|
|
288
|
+
* @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`BindValue`](#bindvalue) for more information about binding values.
|
|
281
289
|
*/
|
|
282
|
-
public runSync(source: string, ...params: VariadicBindParams): RunResult;
|
|
283
290
|
public runSync(source: string, params: BindParams): RunResult;
|
|
291
|
+
/**
|
|
292
|
+
* @hidden
|
|
293
|
+
*/
|
|
294
|
+
public runSync(source: string, ...params: VariadicBindParams): RunResult;
|
|
284
295
|
public runSync(source: string, ...params: any[]): RunResult {
|
|
285
296
|
const statement = this.prepareSync(source);
|
|
286
297
|
let result;
|
|
@@ -293,16 +304,17 @@ export class Database {
|
|
|
293
304
|
}
|
|
294
305
|
|
|
295
306
|
/**
|
|
296
|
-
* Shorthand for `
|
|
297
|
-
* Unlike `Statement.getSync
|
|
298
|
-
*
|
|
299
|
-
* > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.
|
|
300
|
-
*
|
|
307
|
+
* Shorthand for [`prepareAsync()`](#prepareasyncsource) and [`Statement.getSync()`](#getsyncparams).
|
|
308
|
+
* Unlike [`Statement.getSync()`](#getsyncparams), this method finalizes the statement after execution.
|
|
309
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
301
310
|
* @param source A string containing the SQL query.
|
|
302
|
-
* @param params
|
|
311
|
+
* @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`BindValue`](#bindvalue) for more information about binding values.
|
|
303
312
|
*/
|
|
304
|
-
public getSync<T>(source: string, ...params: VariadicBindParams): T | null;
|
|
305
313
|
public getSync<T>(source: string, params: BindParams): T | null;
|
|
314
|
+
/**
|
|
315
|
+
* @hidden
|
|
316
|
+
*/
|
|
317
|
+
public getSync<T>(source: string, ...params: VariadicBindParams): T | null;
|
|
306
318
|
public getSync<T>(source: string, ...params: any[]): T | null {
|
|
307
319
|
const statement = this.prepareSync(source);
|
|
308
320
|
let result;
|
|
@@ -315,38 +327,38 @@ export class Database {
|
|
|
315
327
|
}
|
|
316
328
|
|
|
317
329
|
/**
|
|
318
|
-
* Shorthand for `
|
|
319
|
-
* Unlike `Statement.eachSync
|
|
320
|
-
*
|
|
321
|
-
* > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.
|
|
322
|
-
*
|
|
330
|
+
* Shorthand for [`prepareAsync()`](#prepareasyncsource) and [`Statement.eachSync()`](#eachsyncparams).
|
|
331
|
+
* Unlike [`Statement.eachSync()`](#eachsyncparams), this method finalizes the statement after execution.
|
|
332
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
323
333
|
* @param source A string containing the SQL query.
|
|
324
|
-
* @param params
|
|
334
|
+
* @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`BindValue`](#bindvalue) for more information about binding values.
|
|
325
335
|
*/
|
|
326
|
-
public eachSync<T>(source: string, ...params: VariadicBindParams): IterableIterator<T>;
|
|
327
336
|
public eachSync<T>(source: string, params: BindParams): IterableIterator<T>;
|
|
337
|
+
/**
|
|
338
|
+
* @hidden
|
|
339
|
+
*/
|
|
340
|
+
public eachSync<T>(source: string, ...params: VariadicBindParams): IterableIterator<T>;
|
|
328
341
|
public *eachSync<T>(source: string, ...params: any[]): IterableIterator<T> {
|
|
329
342
|
const statement = this.prepareSync(source);
|
|
330
|
-
let result;
|
|
331
343
|
try {
|
|
332
|
-
|
|
344
|
+
yield* statement.eachSync<T>(...params);
|
|
333
345
|
} finally {
|
|
334
346
|
statement.finalizeSync();
|
|
335
347
|
}
|
|
336
|
-
yield* result;
|
|
337
348
|
}
|
|
338
349
|
|
|
339
350
|
/**
|
|
340
|
-
* Shorthand for `
|
|
341
|
-
* Unlike `Statement.allSync
|
|
342
|
-
*
|
|
343
|
-
* > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.
|
|
344
|
-
*
|
|
351
|
+
* Shorthand for [`prepareAsync()`](#prepareasyncsource) and [`Statement.allSync()`](#allsyncparams).
|
|
352
|
+
* Unlike [`Statement.allSync()`](#allsyncparams), this method finalizes the statement after execution.
|
|
353
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
345
354
|
* @param source A string containing the SQL query.
|
|
346
|
-
* @param params
|
|
355
|
+
* @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`BindValue`](#bindvalue) for more information about binding values.
|
|
347
356
|
*/
|
|
348
|
-
public allSync<T>(source: string, ...params: VariadicBindParams): T[];
|
|
349
357
|
public allSync<T>(source: string, params: BindParams): T[];
|
|
358
|
+
/**
|
|
359
|
+
* @hidden
|
|
360
|
+
*/
|
|
361
|
+
public allSync<T>(source: string, ...params: VariadicBindParams): T[];
|
|
350
362
|
public allSync<T>(source: string, ...params: any[]): T[] {
|
|
351
363
|
const statement = this.prepareSync(source);
|
|
352
364
|
let result;
|
|
@@ -366,27 +378,27 @@ export class Database {
|
|
|
366
378
|
*
|
|
367
379
|
* @param dbName The name of the database file to open.
|
|
368
380
|
* @param options Open options.
|
|
369
|
-
* @returns Database object.
|
|
370
381
|
*/
|
|
371
382
|
export async function openDatabaseAsync(dbName: string, options?: OpenOptions): Promise<Database> {
|
|
372
|
-
const
|
|
383
|
+
const openOptions = options ?? {};
|
|
384
|
+
const nativeDatabase = new ExpoSQLite.NativeDatabase(dbName, openOptions);
|
|
373
385
|
await nativeDatabase.initAsync();
|
|
374
|
-
return new Database(dbName, nativeDatabase);
|
|
386
|
+
return new Database(dbName, openOptions, nativeDatabase);
|
|
375
387
|
}
|
|
376
388
|
|
|
377
389
|
/**
|
|
378
390
|
* Open a database.
|
|
379
391
|
*
|
|
380
|
-
* > **Note:** Running heavy tasks with this function can block the JavaScript thread
|
|
392
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
381
393
|
*
|
|
382
394
|
* @param dbName The name of the database file to open.
|
|
383
395
|
* @param options Open options.
|
|
384
|
-
* @returns Database object.
|
|
385
396
|
*/
|
|
386
397
|
export function openDatabaseSync(dbName: string, options?: OpenOptions): Database {
|
|
387
|
-
const
|
|
398
|
+
const openOptions = options ?? {};
|
|
399
|
+
const nativeDatabase = new ExpoSQLite.NativeDatabase(dbName, openOptions);
|
|
388
400
|
nativeDatabase.initSync();
|
|
389
|
-
return new Database(dbName, nativeDatabase);
|
|
401
|
+
return new Database(dbName, openOptions, nativeDatabase);
|
|
390
402
|
}
|
|
391
403
|
|
|
392
404
|
/**
|
|
@@ -401,7 +413,7 @@ export async function deleteDatabaseAsync(dbName: string): Promise<void> {
|
|
|
401
413
|
/**
|
|
402
414
|
* Delete a database file.
|
|
403
415
|
*
|
|
404
|
-
* > **Note:** Running heavy tasks with this function can block the JavaScript thread
|
|
416
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
405
417
|
*
|
|
406
418
|
* @param dbName The name of the database file to delete.
|
|
407
419
|
*/
|
|
@@ -409,38 +421,45 @@ export function deleteDatabaseSync(dbName: string): void {
|
|
|
409
421
|
return ExpoSQLite.deleteDatabaseSync(dbName);
|
|
410
422
|
}
|
|
411
423
|
|
|
424
|
+
/**
|
|
425
|
+
* The event payload for the listener of [`addDatabaseChangeListener`](#sqliteadddatabasechangelistenerlistener)
|
|
426
|
+
*/
|
|
427
|
+
export type DatabaseChangeEvent = {
|
|
428
|
+
/** The database name. The value would be `main` by default and other database names if you use `ATTACH DATABASE` statement. */
|
|
429
|
+
dbName: string;
|
|
430
|
+
|
|
431
|
+
/** The absolute file path to the database. */
|
|
432
|
+
dbFilePath: string;
|
|
433
|
+
|
|
434
|
+
/** The table name. */
|
|
435
|
+
tableName: string;
|
|
436
|
+
|
|
437
|
+
/** The changed row ID. */
|
|
438
|
+
rowId: number;
|
|
439
|
+
};
|
|
440
|
+
|
|
412
441
|
/**
|
|
413
442
|
* Add a listener for database changes.
|
|
414
|
-
* > Note: to enable this feature, you must set `enableChangeListener` to `true` when opening the database.
|
|
443
|
+
* > Note: to enable this feature, you must set [`enableChangeListener` to `true`](#openoptions) when opening the database.
|
|
415
444
|
*
|
|
416
|
-
* @param listener A function that receives the `dbName`, `tableName` and `rowId` of the modified data.
|
|
445
|
+
* @param listener A function that receives the `dbFilePath`, `dbName`, `tableName` and `rowId` of the modified data.
|
|
417
446
|
* @returns A `Subscription` object that you can call `remove()` on when you would like to unsubscribe the listener.
|
|
418
447
|
*/
|
|
419
448
|
export function addDatabaseChangeListener(
|
|
420
|
-
listener: (event:
|
|
421
|
-
/** The database name. The value would be `main` by default and other database names if you use `ATTACH DATABASE` statement. */
|
|
422
|
-
dbName: string;
|
|
423
|
-
|
|
424
|
-
/** The absolute file path to the database. */
|
|
425
|
-
dbFilePath: string;
|
|
426
|
-
|
|
427
|
-
/** The table name. */
|
|
428
|
-
tableName: string;
|
|
429
|
-
|
|
430
|
-
/** The changed row ID. */
|
|
431
|
-
rowId: number;
|
|
432
|
-
}) => void
|
|
449
|
+
listener: (event: DatabaseChangeEvent) => void
|
|
433
450
|
): Subscription {
|
|
434
451
|
return emitter.addListener('onDatabaseChange', listener);
|
|
435
452
|
}
|
|
436
453
|
|
|
437
454
|
/**
|
|
438
|
-
* A new connection specific for `transactionExclusiveAsync
|
|
455
|
+
* A new connection specific used for [`transactionExclusiveAsync`](#transactionexclusiveasynctask).
|
|
456
|
+
* @hidden not going to pull all the database methods to the document.
|
|
439
457
|
*/
|
|
440
458
|
class Transaction extends Database {
|
|
441
459
|
public static async createAsync(db: Database): Promise<Transaction> {
|
|
442
|
-
const
|
|
460
|
+
const options = { ...db.options, useNewConnection: true };
|
|
461
|
+
const nativeDatabase = new ExpoSQLite.NativeDatabase(db.dbName, options);
|
|
443
462
|
await nativeDatabase.initAsync();
|
|
444
|
-
return new Transaction(db.dbName, nativeDatabase);
|
|
463
|
+
return new Transaction(db.dbName, options, nativeDatabase);
|
|
445
464
|
}
|
|
446
465
|
}
|
|
@@ -38,7 +38,7 @@ export interface OpenOptions {
|
|
|
38
38
|
enableCRSQLite?: boolean;
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* Whether to call the `sqlite3_update_hook` function and enable the `onDatabaseChange` events.
|
|
41
|
+
* Whether to call the [`sqlite3_update_hook`](https://www.sqlite.org/c3ref/update_hook.html) function and enable the `onDatabaseChange` events. You can later subscribe to the change events by [`addDatabaseChangeListener`](#sqliteadddatabasechangelistenerlistener).
|
|
42
42
|
* @default false
|
|
43
43
|
*/
|
|
44
44
|
enableChangeListener?: boolean;
|
|
@@ -18,23 +18,23 @@ export interface RunResult {
|
|
|
18
18
|
* You can either pass the parameters in the following forms:
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
|
-
* -
|
|
21
|
+
* - A single array for unnamed parameters.
|
|
22
22
|
* ```ts
|
|
23
23
|
* const statement = await db.prepareAsync('SELECT * FROM test WHERE value = ? AND intValue = ?');
|
|
24
|
-
* await statement.getAsync('test1', 789);
|
|
24
|
+
* await statement.getAsync(['test1', 789]);
|
|
25
25
|
* ```
|
|
26
26
|
*
|
|
27
27
|
* @example
|
|
28
|
-
* -
|
|
28
|
+
* - Variadic arguments for unnamed parameters.
|
|
29
29
|
* ```ts
|
|
30
30
|
* const statement = await db.prepareAsync('SELECT * FROM test WHERE value = ? AND intValue = ?');
|
|
31
|
-
* await statement.getAsync(
|
|
31
|
+
* await statement.getAsync('test1', 789);
|
|
32
32
|
* ```
|
|
33
33
|
*
|
|
34
34
|
* @example
|
|
35
35
|
* - A single object for [named parameters](https://www.sqlite.org/lang_expr.html)
|
|
36
36
|
*
|
|
37
|
-
*
|
|
37
|
+
* We support multiple named parameter forms such as `:VVV`, `@VVV`, and `$VVV`. We recommend using `$VVV` because JavaScript allows using `$` in identifiers without escaping.
|
|
38
38
|
* ```ts
|
|
39
39
|
* const statement = await db.prepareAsync('SELECT * FROM test WHERE value = $value AND intValue = $intValue');
|
|
40
40
|
* await statement.getAsync({ $value: 'test1', $intValue: 789 });
|
|
@@ -44,7 +44,8 @@ export type BindValue = string | number | null | boolean;
|
|
|
44
44
|
export type BindParams = Record<string, BindValue> | BindValue[];
|
|
45
45
|
export type VariadicBindParams = BindValue[];
|
|
46
46
|
|
|
47
|
-
type
|
|
47
|
+
export type ColumnNames = string[];
|
|
48
|
+
export type ColumnValues = any[];
|
|
48
49
|
type AnyDatabase = any;
|
|
49
50
|
|
|
50
51
|
/**
|
|
@@ -56,11 +57,19 @@ export declare class NativeStatement {
|
|
|
56
57
|
public arrayRunAsync(database: AnyDatabase, params: BindParams): Promise<RunResult>;
|
|
57
58
|
public objectRunAsync(database: AnyDatabase, params: BindParams): Promise<RunResult>;
|
|
58
59
|
|
|
59
|
-
public arrayGetAsync(
|
|
60
|
-
|
|
60
|
+
public arrayGetAsync(
|
|
61
|
+
database: AnyDatabase,
|
|
62
|
+
params: BindParams
|
|
63
|
+
): Promise<ColumnValues | null | undefined>;
|
|
64
|
+
public objectGetAsync(
|
|
65
|
+
database: AnyDatabase,
|
|
66
|
+
params: BindParams
|
|
67
|
+
): Promise<ColumnValues | null | undefined>;
|
|
61
68
|
|
|
62
|
-
public arrayGetAllAsync(database: AnyDatabase, params: BindParams): Promise<
|
|
63
|
-
public objectGetAllAsync(database: AnyDatabase, params: BindParams): Promise<
|
|
69
|
+
public arrayGetAllAsync(database: AnyDatabase, params: BindParams): Promise<ColumnValues[]>;
|
|
70
|
+
public objectGetAllAsync(database: AnyDatabase, params: BindParams): Promise<ColumnValues[]>;
|
|
71
|
+
|
|
72
|
+
public getColumnNamesAsync(): Promise<ColumnNames>;
|
|
64
73
|
|
|
65
74
|
public resetAsync(database: AnyDatabase): Promise<void>;
|
|
66
75
|
public finalizeAsync(database: AnyDatabase): Promise<void>;
|
|
@@ -72,11 +81,13 @@ export declare class NativeStatement {
|
|
|
72
81
|
public arrayRunSync(database: AnyDatabase, params: BindParams): RunResult;
|
|
73
82
|
public objectRunSync(database: AnyDatabase, params: BindParams): RunResult;
|
|
74
83
|
|
|
75
|
-
public arrayGetSync(database: AnyDatabase, params: BindParams):
|
|
76
|
-
public objectGetSync(database: AnyDatabase, params: BindParams):
|
|
84
|
+
public arrayGetSync(database: AnyDatabase, params: BindParams): ColumnValues | null | undefined;
|
|
85
|
+
public objectGetSync(database: AnyDatabase, params: BindParams): ColumnValues | null | undefined;
|
|
86
|
+
|
|
87
|
+
public arrayGetAllSync(database: AnyDatabase, params: BindParams): ColumnValues[];
|
|
88
|
+
public objectGetAllSync(database: AnyDatabase, params: BindParams): ColumnValues[];
|
|
77
89
|
|
|
78
|
-
public
|
|
79
|
-
public objectGetAllSync(database: AnyDatabase, params: BindParams): Row[];
|
|
90
|
+
public getColumnNamesSync(): string[];
|
|
80
91
|
|
|
81
92
|
public resetSync(database: AnyDatabase): void;
|
|
82
93
|
public finalizeSync(database: AnyDatabase): void;
|