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.
- package/CHANGELOG.md +6 -0
- 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 +6 -0
- package/android/src/main/cpp/NativeStatementBinding.h +1 -0
- package/android/src/main/java/expo/modules/sqlite/NativeDatabase.kt +1 -1
- package/android/src/main/java/expo/modules/sqlite/NativeDatabaseBinding.kt +4 -4
- package/android/src/main/java/expo/modules/sqlite/NativeStatementBinding.kt +5 -4
- package/android/src/main/java/expo/modules/sqlite/SQLiteModule.kt +21 -21
- package/android/src/main/java/expo/modules/sqlite/SQLiteModuleNext.kt +55 -68
- 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 -31
- 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/NativeDatabase.swift +3 -3
- package/ios/SQLiteModule.swift +17 -17
- package/ios/SQLiteModuleNext.swift +56 -77
- package/package.json +4 -3
- package/src/next/ExpoSQLiteNext.ts +4 -4
- package/src/next/NativeDatabase.ts +3 -3
- package/src/next/NativeStatement.ts +39 -58
- 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 -140
- package/build/next/Statement.d.ts.map +0 -1
- package/build/next/Statement.js +0 -173
- package/build/next/Statement.js.map +0 -1
- package/src/next/Statement.ts +0 -315
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* A result returned by [`SQLiteDatabase.runAsync`](#runasyncsource-params) or [`SQLiteDatabase.runSync`](#runsyncsource-params).
|
|
3
3
|
*/
|
|
4
|
-
export interface
|
|
4
|
+
export interface SQLiteRunResult {
|
|
5
5
|
/**
|
|
6
|
-
* The last inserted row ID.
|
|
6
|
+
* The last inserted row ID. Returned from the [`sqlite3_last_insert_rowid()`](https://www.sqlite.org/c3ref/last_insert_rowid.html) function.
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
lastInsertRowId: number;
|
|
9
9
|
/**
|
|
10
|
-
* The number of rows affected.
|
|
10
|
+
* The number of rows affected. Returned from the [`sqlite3_changes()`](https://www.sqlite.org/c3ref/changes.html) function.
|
|
11
11
|
*/
|
|
12
12
|
changes: number;
|
|
13
13
|
}
|
|
@@ -16,52 +16,58 @@ export interface RunResult {
|
|
|
16
16
|
* You can either pass the parameters in the following forms:
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
|
-
*
|
|
19
|
+
* A single array for unnamed parameters.
|
|
20
20
|
* ```ts
|
|
21
21
|
* const statement = await db.prepareAsync('SELECT * FROM test WHERE value = ? AND intValue = ?');
|
|
22
|
-
* await statement.
|
|
22
|
+
* const result = await statement.executeAsync(['test1', 789]);
|
|
23
|
+
* const firstRow = await result.getFirstAsync();
|
|
23
24
|
* ```
|
|
24
25
|
*
|
|
25
26
|
* @example
|
|
26
|
-
*
|
|
27
|
+
* Variadic arguments for unnamed parameters.
|
|
27
28
|
* ```ts
|
|
28
29
|
* const statement = await db.prepareAsync('SELECT * FROM test WHERE value = ? AND intValue = ?');
|
|
29
|
-
* await statement.
|
|
30
|
+
* const result = await statement.executeAsync('test1', 789);
|
|
31
|
+
* const firstRow = await result.getFirstAsync();
|
|
30
32
|
* ```
|
|
31
33
|
*
|
|
32
34
|
* @example
|
|
33
|
-
*
|
|
35
|
+
* A single object for [named parameters](https://www.sqlite.org/lang_expr.html)
|
|
34
36
|
*
|
|
35
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.
|
|
36
38
|
* ```ts
|
|
37
39
|
* const statement = await db.prepareAsync('SELECT * FROM test WHERE value = $value AND intValue = $intValue');
|
|
38
|
-
* await statement.
|
|
40
|
+
* const result = await statement.executeAsync({ $value: 'test1', $intValue: 789 });
|
|
41
|
+
* const firstRow = await result.getFirstAsync();
|
|
39
42
|
* ```
|
|
40
43
|
*/
|
|
41
|
-
export type
|
|
42
|
-
export type
|
|
43
|
-
export type
|
|
44
|
-
export type
|
|
45
|
-
export type
|
|
46
|
-
export type
|
|
47
|
-
export type
|
|
48
|
-
type
|
|
44
|
+
export type SQLiteBindValue = string | number | null | boolean | Uint8Array;
|
|
45
|
+
export type SQLiteBindParams = Record<string, SQLiteBindValue> | SQLiteBindValue[];
|
|
46
|
+
export type SQLiteVariadicBindParams = SQLiteBindValue[];
|
|
47
|
+
export type SQLiteBindPrimitiveParams = Record<string, Exclude<SQLiteBindValue, Uint8Array>>;
|
|
48
|
+
export type SQLiteBindBlobParams = Record<string, Uint8Array>;
|
|
49
|
+
export type SQLiteColumnNames = string[];
|
|
50
|
+
export type SQLiteColumnValues = any[];
|
|
51
|
+
export type SQLiteAnyDatabase = any;
|
|
49
52
|
/**
|
|
50
53
|
* A class that represents an instance of the SQLite statement.
|
|
51
54
|
*/
|
|
52
55
|
export declare class NativeStatement {
|
|
53
|
-
runAsync(database:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
runAsync(database: SQLiteAnyDatabase, bindParams: SQLiteBindPrimitiveParams, bindBlobParams: SQLiteBindBlobParams, shouldPassAsArray: boolean): Promise<SQLiteRunResult & {
|
|
57
|
+
firstRowValues: SQLiteColumnValues;
|
|
58
|
+
}>;
|
|
59
|
+
stepAsync(database: SQLiteAnyDatabase): Promise<SQLiteColumnValues | null | undefined>;
|
|
60
|
+
getAllAsync(database: SQLiteAnyDatabase): Promise<SQLiteColumnValues[]>;
|
|
61
|
+
resetAsync(database: SQLiteAnyDatabase): Promise<void>;
|
|
62
|
+
getColumnNamesAsync(): Promise<SQLiteColumnNames>;
|
|
63
|
+
finalizeAsync(database: SQLiteAnyDatabase): Promise<void>;
|
|
64
|
+
runSync(database: SQLiteAnyDatabase, bindParams: SQLiteBindPrimitiveParams, bindBlobParams: SQLiteBindBlobParams, shouldPassAsArray: boolean): SQLiteRunResult & {
|
|
65
|
+
firstRowValues: SQLiteColumnValues;
|
|
66
|
+
};
|
|
67
|
+
stepSync(database: SQLiteAnyDatabase): SQLiteColumnValues | null | undefined;
|
|
68
|
+
getAllSync(database: SQLiteAnyDatabase): SQLiteColumnValues[];
|
|
69
|
+
resetSync(database: SQLiteAnyDatabase): void;
|
|
62
70
|
getColumnNamesSync(): string[];
|
|
63
|
-
|
|
64
|
-
finalizeSync(database: AnyDatabase): void;
|
|
71
|
+
finalizeSync(database: SQLiteAnyDatabase): void;
|
|
65
72
|
}
|
|
66
|
-
export {};
|
|
67
73
|
//# sourceMappingURL=NativeStatement.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeStatement.d.ts","sourceRoot":"","sources":["../../src/next/NativeStatement.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"NativeStatement.d.ts","sourceRoot":"","sources":["../../src/next/NativeStatement.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,UAAU,CAAC;AAC5E,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,eAAe,EAAE,CAAC;AACnF,MAAM,MAAM,wBAAwB,GAAG,eAAe,EAAE,CAAC;AAEzD,MAAM,MAAM,yBAAyB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC,CAAC;AAC7F,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAC9D,MAAM,MAAM,iBAAiB,GAAG,MAAM,EAAE,CAAC;AACzC,MAAM,MAAM,kBAAkB,GAAG,GAAG,EAAE,CAAC;AACvC,MAAM,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAEpC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;IAG3B,QAAQ,CACb,QAAQ,EAAE,iBAAiB,EAC3B,UAAU,EAAE,yBAAyB,EACrC,cAAc,EAAE,oBAAoB,EACpC,iBAAiB,EAAE,OAAO,GACzB,OAAO,CAAC,eAAe,GAAG;QAAE,cAAc,EAAE,kBAAkB,CAAA;KAAE,CAAC;IAC7D,SAAS,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,GAAG,SAAS,CAAC;IACtF,WAAW,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IACvE,UAAU,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IACtD,mBAAmB,IAAI,OAAO,CAAC,iBAAiB,CAAC;IACjD,aAAa,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMzD,OAAO,CACZ,QAAQ,EAAE,iBAAiB,EAC3B,UAAU,EAAE,yBAAyB,EACrC,cAAc,EAAE,oBAAoB,EACpC,iBAAiB,EAAE,OAAO,GACzB,eAAe,GAAG;QAAE,cAAc,EAAE,kBAAkB,CAAA;KAAE;IACpD,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,GAAG,kBAAkB,GAAG,IAAI,GAAG,SAAS;IAC5E,UAAU,CAAC,QAAQ,EAAE,iBAAiB,GAAG,kBAAkB,EAAE;IAC7D,SAAS,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IAC5C,kBAAkB,IAAI,MAAM,EAAE;IAC9B,YAAY,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;CAGvD"}
|
|
@@ -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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