expo-sqlite 12.2.1 → 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.
- package/CHANGELOG.md +22 -0
- package/android/CMakeLists.txt +1 -1
- package/android/build.gradle +2 -2
- package/android/src/main/cpp/NativeDatabaseBinding.cpp +4 -4
- package/android/src/main/cpp/NativeDatabaseBinding.h +2 -2
- package/android/src/main/cpp/NativeStatementBinding.cpp +22 -15
- package/android/src/main/cpp/NativeStatementBinding.h +1 -0
- package/android/src/main/java/expo/modules/sqlite/NativeDatabase.kt +3 -1
- package/android/src/main/java/expo/modules/sqlite/NativeDatabaseBinding.kt +4 -4
- package/android/src/main/java/expo/modules/sqlite/NativeStatement.kt +2 -0
- package/android/src/main/java/expo/modules/sqlite/NativeStatementBinding.kt +5 -4
- package/android/src/main/java/expo/modules/sqlite/SQLExceptions.kt +6 -0
- package/android/src/main/java/expo/modules/sqlite/SQLiteModule.kt +21 -21
- package/android/src/main/java/expo/modules/sqlite/SQLiteModuleNext.kt +122 -132
- package/build/next/ExpoSQLiteNext.d.ts +4 -4
- package/build/next/ExpoSQLiteNext.d.ts.map +1 -1
- package/build/next/ExpoSQLiteNext.js +3 -3
- package/build/next/ExpoSQLiteNext.js.map +1 -1
- package/build/next/NativeDatabase.d.ts +3 -3
- package/build/next/NativeDatabase.d.ts.map +1 -1
- package/build/next/NativeDatabase.js.map +1 -1
- package/build/next/NativeStatement.d.ts +37 -35
- package/build/next/NativeStatement.d.ts.map +1 -1
- package/build/next/NativeStatement.js.map +1 -1
- package/build/next/SQLiteDatabase.d.ts +266 -0
- package/build/next/SQLiteDatabase.d.ts.map +1 -0
- package/build/next/{Database.js → SQLiteDatabase.js} +69 -59
- package/build/next/SQLiteDatabase.js.map +1 -0
- package/build/next/SQLiteStatement.d.ts +190 -0
- package/build/next/SQLiteStatement.d.ts.map +1 -0
- package/build/next/SQLiteStatement.js +275 -0
- package/build/next/SQLiteStatement.js.map +1 -0
- package/build/next/hooks.d.ts +26 -14
- package/build/next/hooks.d.ts.map +1 -1
- package/build/next/hooks.js +121 -33
- package/build/next/hooks.js.map +1 -1
- package/build/next/index.d.ts +2 -2
- package/build/next/index.d.ts.map +1 -1
- package/build/next/index.js +2 -2
- package/build/next/index.js.map +1 -1
- package/build/next/paramUtils.d.ts +18 -0
- package/build/next/paramUtils.d.ts.map +1 -0
- package/build/next/paramUtils.js +72 -0
- package/build/next/paramUtils.js.map +1 -0
- package/ios/Exceptions.swift +12 -0
- package/ios/NativeDatabase.swift +4 -3
- package/ios/NativeStatement.swift +1 -0
- package/ios/SQLiteModule.swift +20 -21
- package/ios/SQLiteModuleNext.swift +126 -131
- package/ios/crsqlite.xcframework/Info.plist +4 -0
- package/ios/crsqlite.xcframework/ios-arm64/crsqlite.framework/Info.plist +4 -0
- package/package.json +4 -3
- package/src/next/ExpoSQLiteNext.ts +4 -4
- package/src/next/NativeDatabase.ts +3 -3
- package/src/next/NativeStatement.ts +43 -48
- package/src/next/{Database.ts → SQLiteDatabase.ts} +134 -112
- package/src/next/SQLiteStatement.ts +528 -0
- package/src/next/hooks.tsx +202 -51
- package/src/next/index.ts +2 -2
- package/src/next/paramUtils.ts +94 -0
- package/build/next/Database.d.ts +0 -272
- package/build/next/Database.d.ts.map +0 -1
- package/build/next/Database.js.map +0 -1
- package/build/next/Statement.d.ts +0 -142
- package/build/next/Statement.d.ts.map +0 -1
- package/build/next/Statement.js +0 -184
- package/build/next/Statement.js.map +0 -1
- package/src/next/Statement.ts +0 -310
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeStatement.js","sourceRoot":"","sources":["../../src/next/NativeStatement.ts"],"names":[],"mappings":"","sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"file":"NativeStatement.js","sourceRoot":"","sources":["../../src/next/NativeStatement.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * A result returned by [`SQLiteDatabase.runAsync`](#runasyncsource-params) or [`SQLiteDatabase.runSync`](#runsyncsource-params).\n */\nexport interface SQLiteRunResult {\n /**\n * The last inserted row ID. Returned from the [`sqlite3_last_insert_rowid()`](https://www.sqlite.org/c3ref/last_insert_rowid.html) function.\n */\n lastInsertRowId: number;\n\n /**\n * The number of rows affected. Returned from the [`sqlite3_changes()`](https://www.sqlite.org/c3ref/changes.html) function.\n */\n changes: number;\n}\n\n/**\n * Bind parameters to the prepared statement.\n * You can either pass the parameters in the following forms:\n *\n * @example\n * A single array for unnamed parameters.\n * ```ts\n * const statement = await db.prepareAsync('SELECT * FROM test WHERE value = ? AND intValue = ?');\n * const result = await statement.executeAsync(['test1', 789]);\n * const firstRow = await result.getFirstAsync();\n * ```\n *\n * @example\n * Variadic arguments for unnamed parameters.\n * ```ts\n * const statement = await db.prepareAsync('SELECT * FROM test WHERE value = ? AND intValue = ?');\n * const result = await statement.executeAsync('test1', 789);\n * const firstRow = await result.getFirstAsync();\n * ```\n *\n * @example\n * A single object for [named parameters](https://www.sqlite.org/lang_expr.html)\n *\n * We support multiple named parameter forms such as `:VVV`, `@VVV`, and `$VVV`. We recommend using `$VVV` because JavaScript allows using `$` in identifiers without escaping.\n * ```ts\n * const statement = await db.prepareAsync('SELECT * FROM test WHERE value = $value AND intValue = $intValue');\n * const result = await statement.executeAsync({ $value: 'test1', $intValue: 789 });\n * const firstRow = await result.getFirstAsync();\n * ```\n */\nexport type SQLiteBindValue = string | number | null | boolean | Uint8Array;\nexport type SQLiteBindParams = Record<string, SQLiteBindValue> | SQLiteBindValue[];\nexport type SQLiteVariadicBindParams = SQLiteBindValue[];\n\nexport type SQLiteBindPrimitiveParams = Record<string, Exclude<SQLiteBindValue, Uint8Array>>;\nexport type SQLiteBindBlobParams = Record<string, Uint8Array>;\nexport type SQLiteColumnNames = string[];\nexport type SQLiteColumnValues = any[];\nexport type SQLiteAnyDatabase = any;\n\n/**\n * A class that represents an instance of the SQLite statement.\n */\nexport declare class NativeStatement {\n //#region Asynchronous API\n\n public runAsync(\n database: SQLiteAnyDatabase,\n bindParams: SQLiteBindPrimitiveParams,\n bindBlobParams: SQLiteBindBlobParams,\n shouldPassAsArray: boolean\n ): Promise<SQLiteRunResult & { firstRowValues: SQLiteColumnValues }>;\n public stepAsync(database: SQLiteAnyDatabase): Promise<SQLiteColumnValues | null | undefined>;\n public getAllAsync(database: SQLiteAnyDatabase): Promise<SQLiteColumnValues[]>;\n public resetAsync(database: SQLiteAnyDatabase): Promise<void>;\n public getColumnNamesAsync(): Promise<SQLiteColumnNames>;\n public finalizeAsync(database: SQLiteAnyDatabase): Promise<void>;\n\n //#endregion\n\n //#region Synchronous API\n\n public runSync(\n database: SQLiteAnyDatabase,\n bindParams: SQLiteBindPrimitiveParams,\n bindBlobParams: SQLiteBindBlobParams,\n shouldPassAsArray: boolean\n ): SQLiteRunResult & { firstRowValues: SQLiteColumnValues };\n public stepSync(database: SQLiteAnyDatabase): SQLiteColumnValues | null | undefined;\n public getAllSync(database: SQLiteAnyDatabase): SQLiteColumnValues[];\n public resetSync(database: SQLiteAnyDatabase): void;\n public getColumnNamesSync(): string[];\n public finalizeSync(database: SQLiteAnyDatabase): void;\n\n //#endregion\n}\n"]}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { Subscription } from 'expo-modules-core';
|
|
2
|
+
import { NativeDatabase, SQLiteOpenOptions } from './NativeDatabase';
|
|
3
|
+
import { SQLiteBindParams, SQLiteRunResult, SQLiteStatement, SQLiteVariadicBindParams } from './SQLiteStatement';
|
|
4
|
+
export { SQLiteOpenOptions };
|
|
5
|
+
/**
|
|
6
|
+
* A SQLite database.
|
|
7
|
+
*/
|
|
8
|
+
export declare class SQLiteDatabase {
|
|
9
|
+
readonly databaseName: string;
|
|
10
|
+
readonly options: SQLiteOpenOptions;
|
|
11
|
+
private readonly nativeDatabase;
|
|
12
|
+
constructor(databaseName: string, options: SQLiteOpenOptions, nativeDatabase: NativeDatabase);
|
|
13
|
+
/**
|
|
14
|
+
* Asynchronous call to return whether the database is currently in a transaction.
|
|
15
|
+
*/
|
|
16
|
+
isInTransactionAsync(): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Close the database.
|
|
19
|
+
*/
|
|
20
|
+
closeAsync(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Execute all SQL queries in the supplied string.
|
|
23
|
+
* > Note: The queries are not escaped for you! Be careful when constructing your queries.
|
|
24
|
+
*
|
|
25
|
+
* @param source A string containing all the SQL queries.
|
|
26
|
+
*/
|
|
27
|
+
execAsync(source: string): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).
|
|
30
|
+
*
|
|
31
|
+
* @param source A string containing the SQL query.
|
|
32
|
+
*/
|
|
33
|
+
prepareAsync(source: string): Promise<SQLiteStatement>;
|
|
34
|
+
/**
|
|
35
|
+
* Execute a transaction and automatically commit/rollback based on the `task` result.
|
|
36
|
+
*
|
|
37
|
+
* > **Note:** This transaction is not exclusive and can be interrupted by other async queries.
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* db.withTransactionAsync(async () => {
|
|
41
|
+
* await db.execAsync('UPDATE test SET name = "aaa"');
|
|
42
|
+
*
|
|
43
|
+
* //
|
|
44
|
+
* // We cannot control the order of async/await order, so order of execution is not guaranteed.
|
|
45
|
+
* // The following UPDATE query out of transaction may be executed here and break the expectation.
|
|
46
|
+
* //
|
|
47
|
+
*
|
|
48
|
+
* const result = await db.getAsync<{ name: string }>('SELECT name FROM Users');
|
|
49
|
+
* expect(result?.name).toBe('aaa');
|
|
50
|
+
* });
|
|
51
|
+
* db.execAsync('UPDATE test SET name = "bbb"');
|
|
52
|
+
* ```
|
|
53
|
+
* If you worry about the order of execution, use `withExclusiveTransactionAsync` instead.
|
|
54
|
+
*
|
|
55
|
+
* @param task An async function to execute within a transaction.
|
|
56
|
+
*/
|
|
57
|
+
withTransactionAsync(task: () => Promise<void>): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Execute a transaction and automatically commit/rollback based on the `task` result.
|
|
60
|
+
*
|
|
61
|
+
* The transaction may be exclusive.
|
|
62
|
+
* As long as the transaction is converted into a write transaction,
|
|
63
|
+
* the other async write queries will abort with `database is locked` error.
|
|
64
|
+
*
|
|
65
|
+
* @param task An async function to execute within a transaction. Any queries inside the transaction must be executed on the `txn` object.
|
|
66
|
+
* The `txn` object has the same interfaces as the [`SQLiteDatabase`](#sqlitedatabase) object. You can use `txn` like a [`SQLiteDatabase`](#sqlitedatabase) object.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* db.withExclusiveTransactionAsync(async (txn) => {
|
|
71
|
+
* await txn.execAsync('UPDATE test SET name = "aaa"');
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
withExclusiveTransactionAsync(task: (txn: Transaction) => Promise<void>): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Synchronous call to return whether the database is currently in a transaction.
|
|
78
|
+
*/
|
|
79
|
+
isInTransactionSync(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Close the database.
|
|
82
|
+
*/
|
|
83
|
+
closeSync(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Execute all SQL queries in the supplied string.
|
|
86
|
+
*
|
|
87
|
+
* > **Note:** The queries are not escaped for you! Be careful when constructing your queries.
|
|
88
|
+
*
|
|
89
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
90
|
+
*
|
|
91
|
+
* @param source A string containing all the SQL queries.
|
|
92
|
+
*/
|
|
93
|
+
execSync(source: string): void;
|
|
94
|
+
/**
|
|
95
|
+
* Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).
|
|
96
|
+
*
|
|
97
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
98
|
+
*
|
|
99
|
+
* @param source A string containing the SQL query.
|
|
100
|
+
*/
|
|
101
|
+
prepareSync(source: string): SQLiteStatement;
|
|
102
|
+
/**
|
|
103
|
+
* Execute a transaction and automatically commit/rollback based on the `task` result.
|
|
104
|
+
*
|
|
105
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
106
|
+
*
|
|
107
|
+
* @param task An async function to execute within a transaction.
|
|
108
|
+
*/
|
|
109
|
+
withTransactionSync(task: () => void): void;
|
|
110
|
+
/**
|
|
111
|
+
* A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).
|
|
112
|
+
* @param source A string containing the SQL query.
|
|
113
|
+
* @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.
|
|
114
|
+
*/
|
|
115
|
+
runAsync(source: string, params: SQLiteBindParams): Promise<SQLiteRunResult>;
|
|
116
|
+
/**
|
|
117
|
+
* @hidden
|
|
118
|
+
*/
|
|
119
|
+
runAsync(source: string, ...params: SQLiteVariadicBindParams): Promise<SQLiteRunResult>;
|
|
120
|
+
/**
|
|
121
|
+
* A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), [`SQLiteExecuteAsyncResult.getFirstAsync()`](#getfirstasync), and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).
|
|
122
|
+
* @param source A string containing the SQL query.
|
|
123
|
+
* @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.
|
|
124
|
+
*/
|
|
125
|
+
getFirstAsync<T>(source: string, params: SQLiteBindParams): Promise<T | null>;
|
|
126
|
+
/**
|
|
127
|
+
* @hidden
|
|
128
|
+
*/
|
|
129
|
+
getFirstAsync<T>(source: string, ...params: SQLiteVariadicBindParams): Promise<T | null>;
|
|
130
|
+
/**
|
|
131
|
+
* A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), [`SQLiteExecuteAsyncResult`](#sqliteexecuteasyncresult) `AsyncIterator`, and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).
|
|
132
|
+
* @param source A string containing the SQL query.
|
|
133
|
+
* @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.
|
|
134
|
+
* @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.
|
|
135
|
+
*/
|
|
136
|
+
getEachAsync<T>(source: string, params: SQLiteBindParams): AsyncIterableIterator<T>;
|
|
137
|
+
/**
|
|
138
|
+
* @hidden
|
|
139
|
+
*/
|
|
140
|
+
getEachAsync<T>(source: string, ...params: SQLiteVariadicBindParams): AsyncIterableIterator<T>;
|
|
141
|
+
/**
|
|
142
|
+
* A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), [`SQLiteExecuteAsyncResult.getAllAsync()`](#getallasync), and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).
|
|
143
|
+
* @param source A string containing the SQL query.
|
|
144
|
+
* @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.
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* // For unnamed parameters, you pass values in an array.
|
|
148
|
+
* db.getAllAsync('SELECT * FROM test WHERE intValue = ? AND name = ?', [1, 'Hello']);
|
|
149
|
+
*
|
|
150
|
+
* // For unnamed parameters, you pass values in variadic arguments.
|
|
151
|
+
* db.getAllAsync('SELECT * FROM test WHERE intValue = ? AND name = ?', 1, 'Hello');
|
|
152
|
+
*
|
|
153
|
+
* // For named parameters, you should pass values in object.
|
|
154
|
+
* db.getAllAsync('SELECT * FROM test WHERE intValue = $intValue AND name = $name', { $intValue: 1, $name: 'Hello' });
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
getAllAsync<T>(source: string, params: SQLiteBindParams): Promise<T[]>;
|
|
158
|
+
/**
|
|
159
|
+
* @hidden
|
|
160
|
+
*/
|
|
161
|
+
getAllAsync<T>(source: string, ...params: SQLiteVariadicBindParams): Promise<T[]>;
|
|
162
|
+
/**
|
|
163
|
+
* A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), and [`SQLiteStatement.finalizeSync()`](#finalizesync).
|
|
164
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
165
|
+
* @param source A string containing the SQL query.
|
|
166
|
+
* @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.
|
|
167
|
+
*/
|
|
168
|
+
runSync(source: string, params: SQLiteBindParams): SQLiteRunResult;
|
|
169
|
+
/**
|
|
170
|
+
* @hidden
|
|
171
|
+
*/
|
|
172
|
+
runSync(source: string, ...params: SQLiteVariadicBindParams): SQLiteRunResult;
|
|
173
|
+
/**
|
|
174
|
+
* A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), [`SQLiteExecuteSyncResult.getFirstSync()`](#getfirstsync), and [`SQLiteStatement.finalizeSync()`](#finalizesync).
|
|
175
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
176
|
+
* @param source A string containing the SQL query.
|
|
177
|
+
* @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.
|
|
178
|
+
*/
|
|
179
|
+
getFirstSync<T>(source: string, params: SQLiteBindParams): T | null;
|
|
180
|
+
/**
|
|
181
|
+
* @hidden
|
|
182
|
+
*/
|
|
183
|
+
getFirstSync<T>(source: string, ...params: SQLiteVariadicBindParams): T | null;
|
|
184
|
+
/**
|
|
185
|
+
* A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), [`SQLiteExecuteSyncResult`](#sqliteexecutesyncresult) `Iterator`, and [`SQLiteStatement.finalizeSync()`](#finalizesync).
|
|
186
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
187
|
+
* @param source A string containing the SQL query.
|
|
188
|
+
* @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.
|
|
189
|
+
* @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.
|
|
190
|
+
*/
|
|
191
|
+
getEachSync<T>(source: string, params: SQLiteBindParams): IterableIterator<T>;
|
|
192
|
+
/**
|
|
193
|
+
* @hidden
|
|
194
|
+
*/
|
|
195
|
+
getEachSync<T>(source: string, ...params: SQLiteVariadicBindParams): IterableIterator<T>;
|
|
196
|
+
/**
|
|
197
|
+
* A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), [`SQLiteExecuteSyncResult.getAllSync()`](#getallsync), and [`SQLiteStatement.finalizeSync()`](#finalizesync).
|
|
198
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
199
|
+
* @param source A string containing the SQL query.
|
|
200
|
+
* @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.
|
|
201
|
+
*/
|
|
202
|
+
getAllSync<T>(source: string, params: SQLiteBindParams): T[];
|
|
203
|
+
/**
|
|
204
|
+
* @hidden
|
|
205
|
+
*/
|
|
206
|
+
getAllSync<T>(source: string, ...params: SQLiteVariadicBindParams): T[];
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Open a database.
|
|
210
|
+
*
|
|
211
|
+
* @param databaseName The name of the database file to open.
|
|
212
|
+
* @param options Open options.
|
|
213
|
+
*/
|
|
214
|
+
export declare function openDatabaseAsync(databaseName: string, options?: SQLiteOpenOptions): Promise<SQLiteDatabase>;
|
|
215
|
+
/**
|
|
216
|
+
* Open a database.
|
|
217
|
+
*
|
|
218
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
219
|
+
*
|
|
220
|
+
* @param databaseName The name of the database file to open.
|
|
221
|
+
* @param options Open options.
|
|
222
|
+
*/
|
|
223
|
+
export declare function openDatabaseSync(databaseName: string, options?: SQLiteOpenOptions): SQLiteDatabase;
|
|
224
|
+
/**
|
|
225
|
+
* Delete a database file.
|
|
226
|
+
*
|
|
227
|
+
* @param databaseName The name of the database file to delete.
|
|
228
|
+
*/
|
|
229
|
+
export declare function deleteDatabaseAsync(databaseName: string): Promise<void>;
|
|
230
|
+
/**
|
|
231
|
+
* Delete a database file.
|
|
232
|
+
*
|
|
233
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
234
|
+
*
|
|
235
|
+
* @param databaseName The name of the database file to delete.
|
|
236
|
+
*/
|
|
237
|
+
export declare function deleteDatabaseSync(databaseName: string): void;
|
|
238
|
+
/**
|
|
239
|
+
* The event payload for the listener of [`addDatabaseChangeListener`](#sqliteadddatabasechangelistenerlistener)
|
|
240
|
+
*/
|
|
241
|
+
export type DatabaseChangeEvent = {
|
|
242
|
+
/** The database name. The value would be `main` by default and other database names if you use `ATTACH DATABASE` statement. */
|
|
243
|
+
databaseName: string;
|
|
244
|
+
/** The absolute file path to the database. */
|
|
245
|
+
databaseFilePath: string;
|
|
246
|
+
/** The table name. */
|
|
247
|
+
tableName: string;
|
|
248
|
+
/** The changed row ID. */
|
|
249
|
+
rowId: number;
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* Add a listener for database changes.
|
|
253
|
+
* > Note: to enable this feature, you must set [`enableChangeListener` to `true`](#sqliteopenoptions) when opening the database.
|
|
254
|
+
*
|
|
255
|
+
* @param listener A function that receives the `databaseName`, `databaseFilePath`, `tableName` and `rowId` of the modified data.
|
|
256
|
+
* @returns A `Subscription` object that you can call `remove()` on when you would like to unsubscribe the listener.
|
|
257
|
+
*/
|
|
258
|
+
export declare function addDatabaseChangeListener(listener: (event: DatabaseChangeEvent) => void): Subscription;
|
|
259
|
+
/**
|
|
260
|
+
* A new connection specific used for [`withExclusiveTransactionAsync`](#withexclusivetransactionasynctask).
|
|
261
|
+
* @hidden not going to pull all the database methods to the document.
|
|
262
|
+
*/
|
|
263
|
+
declare class Transaction extends SQLiteDatabase {
|
|
264
|
+
static createAsync(db: SQLiteDatabase): Promise<Transaction>;
|
|
265
|
+
}
|
|
266
|
+
//# sourceMappingURL=SQLiteDatabase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SQLiteDatabase.d.ts","sourceRoot":"","sources":["../../src/next/SQLiteDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAG/D,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EACL,gBAAgB,EAGhB,eAAe,EACf,eAAe,EACf,wBAAwB,EACzB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAI7B;;GAEG;AACH,qBAAa,cAAc;aAEP,YAAY,EAAE,MAAM;aACpB,OAAO,EAAE,iBAAiB;IAC1C,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAFf,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,iBAAiB,EACzB,cAAc,EAAE,cAAc;IAGjD;;O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o-modules-core';
|
|
2
2
|
import ExpoSQLite from './ExpoSQLiteNext';
|
|
3
|
-
import {
|
|
3
|
+
import { SQLiteStatement, } from './SQLiteStatement';
|
|
4
4
|
const emitter = new EventEmitter(ExpoSQLite);
|
|
5
5
|
/**
|
|
6
6
|
* A SQLite database.
|
|
7
7
|
*/
|
|
8
|
-
export class
|
|
9
|
-
|
|
8
|
+
export class SQLiteDatabase {
|
|
9
|
+
databaseName;
|
|
10
10
|
options;
|
|
11
11
|
nativeDatabase;
|
|
12
|
-
constructor(
|
|
13
|
-
this.
|
|
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
|
-
*
|
|
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
|
|
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.
|
|
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 `
|
|
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
|
|
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 `
|
|
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.
|
|
94
|
+
* db.withExclusiveTransactionAsync(async (txn) => {
|
|
95
95
|
* await txn.execAsync('UPDATE test SET name = "aaa"');
|
|
96
96
|
* });
|
|
97
97
|
* ```
|
|
98
98
|
*/
|
|
99
|
-
async
|
|
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
|
-
*
|
|
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
|
|
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
|
-
|
|
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.
|
|
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
|
|
183
|
+
async getFirstAsync(source, ...params) {
|
|
184
184
|
const statement = await this.prepareAsync(source);
|
|
185
|
-
let
|
|
185
|
+
let firstRow;
|
|
186
186
|
try {
|
|
187
|
-
result = await statement.
|
|
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
|
|
193
|
+
return firstRow;
|
|
193
194
|
}
|
|
194
|
-
async *
|
|
195
|
+
async *getEachAsync(source, ...params) {
|
|
195
196
|
const statement = await this.prepareAsync(source);
|
|
196
197
|
try {
|
|
197
|
-
|
|
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
|
|
207
|
+
async getAllAsync(source, ...params) {
|
|
204
208
|
const statement = await this.prepareAsync(source);
|
|
205
|
-
let
|
|
209
|
+
let allRows;
|
|
206
210
|
try {
|
|
207
|
-
result = await statement.
|
|
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
|
|
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.
|
|
223
|
+
result = statement.executeSync(...params);
|
|
219
224
|
}
|
|
220
225
|
finally {
|
|
221
226
|
statement.finalizeSync();
|
|
222
227
|
}
|
|
223
228
|
return result;
|
|
224
229
|
}
|
|
225
|
-
|
|
230
|
+
getFirstSync(source, ...params) {
|
|
226
231
|
const statement = this.prepareSync(source);
|
|
227
|
-
let
|
|
232
|
+
let firstRow;
|
|
228
233
|
try {
|
|
229
|
-
result = statement.
|
|
234
|
+
const result = statement.executeSync(...params);
|
|
235
|
+
firstRow = result.getFirstSync();
|
|
230
236
|
}
|
|
231
237
|
finally {
|
|
232
238
|
statement.finalizeSync();
|
|
233
239
|
}
|
|
234
|
-
return
|
|
240
|
+
return firstRow;
|
|
235
241
|
}
|
|
236
|
-
*
|
|
242
|
+
*getEachSync(source, ...params) {
|
|
237
243
|
const statement = this.prepareSync(source);
|
|
238
244
|
try {
|
|
239
|
-
|
|
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
|
-
|
|
254
|
+
getAllSync(source, ...params) {
|
|
246
255
|
const statement = this.prepareSync(source);
|
|
247
|
-
let
|
|
256
|
+
let allRows;
|
|
248
257
|
try {
|
|
249
|
-
result = statement.
|
|
258
|
+
const result = statement.executeSync(...params);
|
|
259
|
+
allRows = result.getAllSync();
|
|
250
260
|
}
|
|
251
261
|
finally {
|
|
252
262
|
statement.finalizeSync();
|
|
253
263
|
}
|
|
254
|
-
return
|
|
264
|
+
return allRows;
|
|
255
265
|
}
|
|
256
266
|
}
|
|
257
267
|
/**
|
|
258
268
|
* Open a database.
|
|
259
269
|
*
|
|
260
|
-
* @param
|
|
270
|
+
* @param databaseName The name of the database file to open.
|
|
261
271
|
* @param options Open options.
|
|
262
272
|
*/
|
|
263
|
-
export async function openDatabaseAsync(
|
|
273
|
+
export async function openDatabaseAsync(databaseName, options) {
|
|
264
274
|
const openOptions = options ?? {};
|
|
265
|
-
const nativeDatabase = new ExpoSQLite.NativeDatabase(
|
|
275
|
+
const nativeDatabase = new ExpoSQLite.NativeDatabase(databaseName, openOptions);
|
|
266
276
|
await nativeDatabase.initAsync();
|
|
267
|
-
return new
|
|
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
|
|
284
|
+
* @param databaseName The name of the database file to open.
|
|
275
285
|
* @param options Open options.
|
|
276
286
|
*/
|
|
277
|
-
export function openDatabaseSync(
|
|
287
|
+
export function openDatabaseSync(databaseName, options) {
|
|
278
288
|
const openOptions = options ?? {};
|
|
279
|
-
const nativeDatabase = new ExpoSQLite.NativeDatabase(
|
|
289
|
+
const nativeDatabase = new ExpoSQLite.NativeDatabase(databaseName, openOptions);
|
|
280
290
|
nativeDatabase.initSync();
|
|
281
|
-
return new
|
|
291
|
+
return new SQLiteDatabase(databaseName, openOptions, nativeDatabase);
|
|
282
292
|
}
|
|
283
293
|
/**
|
|
284
294
|
* Delete a database file.
|
|
285
295
|
*
|
|
286
|
-
* @param
|
|
296
|
+
* @param databaseName The name of the database file to delete.
|
|
287
297
|
*/
|
|
288
|
-
export async function deleteDatabaseAsync(
|
|
289
|
-
return await ExpoSQLite.deleteDatabaseAsync(
|
|
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
|
|
306
|
+
* @param databaseName The name of the database file to delete.
|
|
297
307
|
*/
|
|
298
|
-
export function deleteDatabaseSync(
|
|
299
|
-
return ExpoSQLite.deleteDatabaseSync(
|
|
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`](#
|
|
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 `
|
|
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 [`
|
|
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
|
|
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.
|
|
328
|
+
const nativeDatabase = new ExpoSQLite.NativeDatabase(db.databaseName, options);
|
|
319
329
|
await nativeDatabase.initAsync();
|
|
320
|
-
return new Transaction(db.
|
|
330
|
+
return new Transaction(db.databaseName, options, nativeDatabase);
|
|
321
331
|
}
|
|
322
332
|
}
|
|
323
|
-
//# sourceMappingURL=
|
|
333
|
+
//# sourceMappingURL=SQLiteDatabase.js.map
|