expo-sqlite 12.1.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 +10 -0
- package/android/build.gradle +2 -2
- 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/next/Database.d.ts +91 -73
- package/build/next/Database.d.ts.map +1 -1
- package/build/next/Database.js +22 -19
- 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 +5 -5
- package/build/next/NativeStatement.js.map +1 -1
- package/build/next/Statement.d.ts +46 -42
- package/build/next/Statement.d.ts.map +1 -1
- package/build/next/Statement.js +1 -1
- 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 +28 -3
- package/build/next/hooks.js.map +1 -1
- package/package.json +2 -2
- package/src/next/Database.ts +109 -86
- package/src/next/NativeDatabase.ts +1 -1
- package/src/next/NativeStatement.ts +5 -5
- package/src/next/Statement.ts +46 -42
- package/src/next/hooks.tsx +29 -4
- package/android/src/main/jniLibs/arm64/libcrsqlite.so +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeStatement.js","sourceRoot":"","sources":["../../src/next/NativeStatement.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Result of a `runAsync` call.\n */\nexport interface RunResult {\n /**\n * The last inserted row ID.\n */\n lastInsertRowid: number;\n\n /**\n * The number of rows affected.\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 * -
|
|
1
|
+
{"version":3,"file":"NativeStatement.js","sourceRoot":"","sources":["../../src/next/NativeStatement.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Result of a `runAsync` call.\n */\nexport interface RunResult {\n /**\n * The last inserted row ID.\n */\n lastInsertRowid: number;\n\n /**\n * The number of rows affected.\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 * await statement.getAsync(['test1', 789]);\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 * await statement.getAsync('test1', 789);\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 * await statement.getAsync({ $value: 'test1', $intValue: 789 });\n * ```\n */\nexport type BindValue = string | number | null | boolean;\nexport type BindParams = Record<string, BindValue> | BindValue[];\nexport type VariadicBindParams = BindValue[];\n\nexport type ColumnNames = string[];\nexport type ColumnValues = any[];\ntype AnyDatabase = 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 arrayRunAsync(database: AnyDatabase, params: BindParams): Promise<RunResult>;\n public objectRunAsync(database: AnyDatabase, params: BindParams): Promise<RunResult>;\n\n public arrayGetAsync(\n database: AnyDatabase,\n params: BindParams\n ): Promise<ColumnValues | null | undefined>;\n public objectGetAsync(\n database: AnyDatabase,\n params: BindParams\n ): Promise<ColumnValues | null | undefined>;\n\n public arrayGetAllAsync(database: AnyDatabase, params: BindParams): Promise<ColumnValues[]>;\n public objectGetAllAsync(database: AnyDatabase, params: BindParams): Promise<ColumnValues[]>;\n\n public getColumnNamesAsync(): Promise<ColumnNames>;\n\n public resetAsync(database: AnyDatabase): Promise<void>;\n public finalizeAsync(database: AnyDatabase): Promise<void>;\n\n //#endregion\n\n //#region Synchronous API\n\n public arrayRunSync(database: AnyDatabase, params: BindParams): RunResult;\n public objectRunSync(database: AnyDatabase, params: BindParams): RunResult;\n\n public arrayGetSync(database: AnyDatabase, params: BindParams): ColumnValues | null | undefined;\n public objectGetSync(database: AnyDatabase, params: BindParams): ColumnValues | null | undefined;\n\n public arrayGetAllSync(database: AnyDatabase, params: BindParams): ColumnValues[];\n public objectGetAllSync(database: AnyDatabase, params: BindParams): ColumnValues[];\n\n public getColumnNamesSync(): string[];\n\n public resetSync(database: AnyDatabase): void;\n public finalizeSync(database: AnyDatabase): void;\n\n //#endregion\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import { NativeDatabase } from './NativeDatabase';
|
|
|
2
2
|
import { BindParams, BindValue, NativeStatement, RunResult, VariadicBindParams, type ColumnNames, type ColumnValues } from './NativeStatement';
|
|
3
3
|
export { BindParams, BindValue, RunResult, VariadicBindParams };
|
|
4
4
|
/**
|
|
5
|
-
* A prepared statement returned by `Database.prepareAsync()` that can be binded with parameters and executed.
|
|
5
|
+
* A prepared statement returned by [`Database.prepareAsync()`](#prepareasyncsource) or [`Database.prepareSync()`](#preparesyncsource) that can be binded with parameters and executed.
|
|
6
6
|
*/
|
|
7
7
|
export declare class Statement {
|
|
8
8
|
private readonly nativeDatabase;
|
|
@@ -10,40 +10,48 @@ export declare class Statement {
|
|
|
10
10
|
constructor(nativeDatabase: NativeDatabase, nativeStatement: NativeStatement);
|
|
11
11
|
/**
|
|
12
12
|
* Run the prepared statement and return the result.
|
|
13
|
-
*
|
|
14
|
-
* @param params @see `BindParams`
|
|
13
|
+
* @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.
|
|
15
14
|
*/
|
|
16
|
-
runAsync(...params: VariadicBindParams): Promise<RunResult>;
|
|
17
15
|
runAsync(params: BindParams): Promise<RunResult>;
|
|
16
|
+
/**
|
|
17
|
+
* @hidden
|
|
18
|
+
*/
|
|
19
|
+
runAsync(...params: VariadicBindParams): Promise<RunResult>;
|
|
18
20
|
/**
|
|
19
21
|
* Iterate the prepared statement and return results as an async iterable.
|
|
20
|
-
*
|
|
21
|
-
* @param params @see `BindParams`
|
|
22
|
-
*
|
|
22
|
+
* @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.
|
|
23
23
|
* @example
|
|
24
24
|
* ```ts
|
|
25
25
|
* const statement = await db.prepareAsync('SELECT * FROM test');
|
|
26
26
|
* for await (const row of statement.eachAsync<any>()) {
|
|
27
27
|
* console.log(row);
|
|
28
28
|
* }
|
|
29
|
+
* await statement.finalizeAsync();
|
|
29
30
|
* ```
|
|
30
31
|
*/
|
|
31
|
-
eachAsync<T>(...params: VariadicBindParams): AsyncIterableIterator<T>;
|
|
32
32
|
eachAsync<T>(params: BindParams): AsyncIterableIterator<T>;
|
|
33
|
+
/**
|
|
34
|
+
* @hidden
|
|
35
|
+
*/
|
|
36
|
+
eachAsync<T>(...params: VariadicBindParams): AsyncIterableIterator<T>;
|
|
33
37
|
/**
|
|
34
38
|
* Get one row from the prepared statement.
|
|
35
|
-
*
|
|
36
|
-
* @param params @see `BindParams`
|
|
39
|
+
* @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.
|
|
37
40
|
*/
|
|
38
|
-
getAsync<T>(...params: VariadicBindParams): Promise<T | null>;
|
|
39
41
|
getAsync<T>(params: BindParams): Promise<T | null>;
|
|
42
|
+
/**
|
|
43
|
+
* @hidden
|
|
44
|
+
*/
|
|
45
|
+
getAsync<T>(...params: VariadicBindParams): Promise<T | null>;
|
|
40
46
|
/**
|
|
41
47
|
* Get all rows from the prepared statement.
|
|
42
|
-
*
|
|
43
|
-
* @param params @see `BindParams`
|
|
48
|
+
* @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.
|
|
44
49
|
*/
|
|
45
|
-
allAsync<T>(...params: VariadicBindParams): Promise<T[]>;
|
|
46
50
|
allAsync<T>(params: BindParams): Promise<T[]>;
|
|
51
|
+
/**
|
|
52
|
+
* @hidden
|
|
53
|
+
*/
|
|
54
|
+
allAsync<T>(...params: VariadicBindParams): Promise<T[]>;
|
|
47
55
|
/**
|
|
48
56
|
* Get the column names of the prepared statement.
|
|
49
57
|
*/
|
|
@@ -59,48 +67,44 @@ export declare class Statement {
|
|
|
59
67
|
finalizeAsync(): Promise<void>;
|
|
60
68
|
/**
|
|
61
69
|
* Run the prepared statement and return the result.
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* @param params @see `BindParams`
|
|
70
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
71
|
+
* @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.
|
|
66
72
|
*/
|
|
67
|
-
runSync(...params: VariadicBindParams): RunResult;
|
|
68
73
|
runSync(params: BindParams): RunResult;
|
|
74
|
+
/**
|
|
75
|
+
* @hidden
|
|
76
|
+
*/
|
|
77
|
+
runSync(...params: VariadicBindParams): RunResult;
|
|
69
78
|
/**
|
|
70
79
|
* Iterate the prepared statement and return results as an iterable.
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* @param params @see `BindParams`
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```ts
|
|
78
|
-
* const statement = await db.prepareSync('SELECT * FROM test');
|
|
79
|
-
* for (const row of statement.eachSync<any>()) {
|
|
80
|
-
* console.log(row);
|
|
81
|
-
* }
|
|
82
|
-
* ```
|
|
80
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
81
|
+
* @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.
|
|
83
82
|
*/
|
|
84
|
-
eachSync<T>(...params: VariadicBindParams): IterableIterator<T>;
|
|
85
83
|
eachSync<T>(params: BindParams): IterableIterator<T>;
|
|
84
|
+
/**
|
|
85
|
+
* @hidden
|
|
86
|
+
*/
|
|
87
|
+
eachSync<T>(...params: VariadicBindParams): IterableIterator<T>;
|
|
86
88
|
/**
|
|
87
89
|
* Get one row from the prepared statement.
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* @param params @see `BindParams`
|
|
90
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
91
|
+
* @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.
|
|
92
92
|
*/
|
|
93
|
-
getSync<T>(...params: VariadicBindParams): T | null;
|
|
94
93
|
getSync<T>(params: BindParams): T | null;
|
|
94
|
+
/**
|
|
95
|
+
* @hidden
|
|
96
|
+
*/
|
|
97
|
+
getSync<T>(...params: VariadicBindParams): T | null;
|
|
95
98
|
/**
|
|
96
99
|
* Get all rows from the prepared statement.
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* @param params @see `BindParams`
|
|
100
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
|
|
101
|
+
* @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.
|
|
101
102
|
*/
|
|
102
|
-
allSync<T>(...params: VariadicBindParams): T[];
|
|
103
103
|
allSync<T>(params: BindParams): T[];
|
|
104
|
+
/**
|
|
105
|
+
* @hidden
|
|
106
|
+
*/
|
|
107
|
+
allSync<T>(...params: VariadicBindParams): T[];
|
|
104
108
|
/**
|
|
105
109
|
* Get the column names of the prepared statement.
|
|
106
110
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Statement.d.ts","sourceRoot":"","sources":["../../src/next/Statement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,UAAU,EACV,SAAS,EACT,eAAe,EACf,SAAS,EACT,kBAAkB,EAClB,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC;AAEhE;;GAEG;AACH,qBAAa,SAAS;IAElB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,eAAe;gBADf,cAAc,EAAE,cAAc,EAC9B,eAAe,EAAE,eAAe;IAKnD
|
|
1
|
+
{"version":3,"file":"Statement.d.ts","sourceRoot":"","sources":["../../src/next/Statement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,UAAU,EACV,SAAS,EACT,eAAe,EACf,SAAS,EACT,kBAAkB,EAClB,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC;AAEhE;;GAEG;AACH,qBAAa,SAAS;IAElB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,eAAe;gBADf,cAAc,EAAE,cAAc,EAC9B,eAAe,EAAE,eAAe;IAKnD;;;OAGG;IACI,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;IACvD;;OAEG;IACI,QAAQ,CAAC,GAAG,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,SAAS,CAAC;IAUlE;;;;;;;;;;;OAWG;IACI,SAAS,C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AAE,GAAG,MAAM,EAAE,kBAAkB,GAAG,CAAC,GAAG,IAAI;IAU1D;;;;OAIG;IACI,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,GAAG,CAAC,EAAE;IAC1C;;OAEG;IACI,OAAO,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,kBAAkB,GAAG,CAAC,EAAE;IAUrD;;OAEG;IACI,kBAAkB,IAAI,MAAM,EAAE;IAIrC;;OAEG;IACI,SAAS,IAAI,IAAI;IAIxB;;;;;OAKG;IACI,YAAY,IAAI,IAAI;CAK5B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG;IACjD,MAAM,EAAE,UAAU,CAAC;IACnB,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAaA;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,GAAG,CAAC,CAWrF;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,GAAG,CAAC,EAAE,CAmB9F"}
|
package/build/next/Statement.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A prepared statement returned by `Database.prepareAsync()` that can be binded with parameters and executed.
|
|
2
|
+
* A prepared statement returned by [`Database.prepareAsync()`](#prepareasyncsource) or [`Database.prepareSync()`](#preparesyncsource) that can be binded with parameters and executed.
|
|
3
3
|
*/
|
|
4
4
|
export class Statement {
|
|
5
5
|
nativeDatabase;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Statement.js","sourceRoot":"","sources":["../../src/next/Statement.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,MAAM,OAAO,SAAS;IAED;IACA;IAFnB,YACmB,cAA8B,EAC9B,eAAgC;QADhC,mBAAc,GAAd,cAAc,CAA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AAE;QACrD,yFAAyF;QACzF,MAAM,IAAI,KAAK,CACb,kDAAkD,WAAW,CAAC,MAAM,aAAa,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAC9G,CAAC;KACH;IACD,MAAM,OAAO,GAAQ,EAAE,CAAC;IACxB,KAAK,MAAM,YAAY,IAAI,gBAAgB,EAAE;QAC3C,MAAM,GAAG,GAAG,EAAE,CAAC;QACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC3C,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;SACvC;QACD,OAAO,CAAC,IAAI,CAAC,GAAQ,CAAC,CAAC;KACxB;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { NativeDatabase } from './NativeDatabase';\nimport {\n BindParams,\n BindValue,\n NativeStatement,\n RunResult,\n VariadicBindParams,\n type ColumnNames,\n type ColumnValues,\n} from './NativeStatement';\n\nexport { BindParams, BindValue, RunResult, VariadicBindParams };\n\n/**\n * A prepared statement returned by `Database.prepareAsync()` that can be binded with parameters and executed.\n */\nexport class Statement {\n constructor(\n private readonly nativeDatabase: NativeDatabase,\n private readonly nativeStatement: NativeStatement\n ) {}\n\n //#region Asynchronous API\n\n /**\n * Run the prepared statement and return the result.\n *\n * @param params @see `BindParams`\n */\n public runAsync(...params: VariadicBindParams): Promise<RunResult>;\n public runAsync(params: BindParams): Promise<RunResult>;\n public async runAsync(...params: unknown[]): Promise<RunResult> {\n const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);\n if (shouldPassAsObject) {\n return await this.nativeStatement.objectRunAsync(this.nativeDatabase, bindParams);\n } else {\n return await this.nativeStatement.arrayRunAsync(this.nativeDatabase, bindParams);\n }\n }\n\n /**\n * Iterate the prepared statement and return results as an async iterable.\n *\n * @param params @see `BindParams`\n *\n * @example\n * ```ts\n * const statement = await db.prepareAsync('SELECT * FROM test');\n * for await (const row of statement.eachAsync<any>()) {\n * console.log(row);\n * }\n * ```\n */\n public eachAsync<T>(...params: VariadicBindParams): AsyncIterableIterator<T>;\n public eachAsync<T>(params: BindParams): AsyncIterableIterator<T>;\n public async *eachAsync<T>(...params: unknown[]): AsyncIterableIterator<T> {\n const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);\n const func = shouldPassAsObject\n ? this.nativeStatement.objectGetAsync.bind(this.nativeStatement)\n : this.nativeStatement.arrayGetAsync.bind(this.nativeStatement);\n\n const columnNames = await this.getColumnNamesAsync();\n let result = null;\n do {\n result = await func(this.nativeDatabase, bindParams);\n if (result != null) {\n yield composeRow<T>(columnNames, result);\n }\n } while (result != null);\n }\n\n /**\n * Get one row from the prepared statement.\n *\n * @param params @see `BindParams`\n */\n public getAsync<T>(...params: VariadicBindParams): Promise<T | null>;\n public getAsync<T>(params: BindParams): Promise<T | null>;\n public async getAsync<T>(...params: unknown[]): Promise<T | null> {\n const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);\n const columnNames = await this.getColumnNamesAsync();\n const columnValues = shouldPassAsObject\n ? await this.nativeStatement.objectGetAsync(this.nativeDatabase, bindParams)\n : await this.nativeStatement.arrayGetAsync(this.nativeDatabase, bindParams);\n return columnValues != null ? composeRow<T>(columnNames, columnValues) : null;\n }\n\n /**\n * Get all rows from the prepared statement.\n *\n * @param params @see `BindParams`\n */\n public allAsync<T>(...params: VariadicBindParams): Promise<T[]>;\n public allAsync<T>(params: BindParams): Promise<T[]>;\n public async allAsync<T>(...params: unknown[]): Promise<T[]> {\n const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);\n const columnNames = await this.getColumnNamesAsync();\n const columnValuesList = shouldPassAsObject\n ? await this.nativeStatement.objectGetAllAsync(this.nativeDatabase, bindParams)\n : await this.nativeStatement.arrayGetAllAsync(this.nativeDatabase, bindParams);\n return composeRows<T>(columnNames, columnValuesList);\n }\n\n /**\n * Get the column names of the prepared statement.\n */\n public getColumnNamesAsync(): Promise<string[]> {\n return this.nativeStatement.getColumnNamesAsync();\n }\n\n /**\n * Reset the prepared statement cursor.\n */\n public async resetAsync(): Promise<void> {\n await this.nativeStatement.resetAsync(this.nativeDatabase);\n }\n\n /**\n * Finalize the prepared statement.\n * > **Note:** Remember to finalize the prepared statement whenever you call `prepareAsync()` to avoid resource leaks.\n */\n public async finalizeAsync(): Promise<void> {\n await this.nativeStatement.finalizeAsync(this.nativeDatabase);\n }\n\n //#endregion\n\n //#region Synchronous API\n\n /**\n * Run the prepared statement and return the result.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param params @see `BindParams`\n */\n public runSync(...params: VariadicBindParams): RunResult;\n public runSync(params: BindParams): RunResult;\n public runSync(...params: unknown[]): RunResult {\n const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);\n if (shouldPassAsObject) {\n return this.nativeStatement.objectRunSync(this.nativeDatabase, bindParams);\n } else {\n return this.nativeStatement.arrayRunSync(this.nativeDatabase, bindParams);\n }\n }\n\n /**\n * Iterate the prepared statement and return results as an iterable.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param params @see `BindParams`\n *\n * @example\n * ```ts\n * const statement = await db.prepareSync('SELECT * FROM test');\n * for (const row of statement.eachSync<any>()) {\n * console.log(row);\n * }\n * ```\n */\n public eachSync<T>(...params: VariadicBindParams): IterableIterator<T>;\n public eachSync<T>(params: BindParams): IterableIterator<T>;\n public *eachSync<T>(...params: unknown[]): IterableIterator<T> {\n const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);\n const func = shouldPassAsObject\n ? this.nativeStatement.objectGetSync.bind(this.nativeStatement)\n : this.nativeStatement.arrayGetSync.bind(this.nativeStatement);\n\n const columnNames = this.getColumnNamesSync();\n let result = null;\n do {\n result = func(this.nativeDatabase, bindParams);\n if (result != null) {\n yield composeRow<T>(columnNames, result);\n }\n } while (result != null);\n }\n\n /**\n * Get one row from the prepared statement.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param params @see `BindParams`\n */\n public getSync<T>(...params: VariadicBindParams): T | null;\n public getSync<T>(params: BindParams): T | null;\n public getSync<T>(...params: unknown[]): T | null {\n const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);\n const columnNames = this.getColumnNamesSync();\n const columnValues = shouldPassAsObject\n ? this.nativeStatement.objectGetSync(this.nativeDatabase, bindParams)\n : this.nativeStatement.arrayGetSync(this.nativeDatabase, bindParams);\n return columnValues != null ? composeRow<T>(columnNames, columnValues) : null;\n }\n\n /**\n * Get all rows from the prepared statement.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param params @see `BindParams`\n */\n public allSync<T>(...params: VariadicBindParams): T[];\n public allSync<T>(params: BindParams): T[];\n public allSync<T>(...params: unknown[]): T[] {\n const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);\n const columnNames = this.getColumnNamesSync();\n const columnValuesList = shouldPassAsObject\n ? this.nativeStatement.objectGetAllSync(this.nativeDatabase, bindParams)\n : this.nativeStatement.arrayGetAllSync(this.nativeDatabase, bindParams);\n return composeRows<T>(columnNames, columnValuesList);\n }\n\n /**\n * Get the column names of the prepared statement.\n */\n public getColumnNamesSync(): string[] {\n return this.nativeStatement.getColumnNamesSync();\n }\n\n /**\n * Reset the prepared statement cursor.\n */\n public resetSync(): void {\n this.nativeStatement.resetSync(this.nativeDatabase);\n }\n\n /**\n * Finalize the prepared statement.\n *\n * > **Note:** Remember to finalize the prepared statement whenever you call `prepareSync()` to avoid resource leaks.\n *\n */\n public finalizeSync(): void {\n this.nativeStatement.finalizeSync(this.nativeDatabase);\n }\n\n //#endregion\n}\n\n/**\n * Normalize the bind params to an array or object.\n * @hidden\n */\nexport function normalizeParams(...params: any[]): {\n params: BindParams;\n shouldPassAsObject: boolean;\n} {\n let bindParams = params.length > 1 ? params : (params[0] as BindParams);\n if (bindParams == null) {\n bindParams = [];\n }\n if (typeof bindParams !== 'object') {\n bindParams = [bindParams];\n }\n const shouldPassAsObject = !Array.isArray(bindParams);\n return {\n params: bindParams,\n shouldPassAsObject,\n };\n}\n\n/**\n * Compose `columnNames` and `columnValues` to an row object.\n * @hidden\n */\nexport function composeRow<T>(columnNames: ColumnNames, columnValues: ColumnValues): T {\n const row = {};\n if (columnNames.length !== columnValues.length) {\n throw new Error(\n `Column names and values count mismatch. Names: ${columnNames.length}, Values: ${columnValues.length}`\n );\n }\n for (let i = 0; i < columnNames.length; i++) {\n row[columnNames[i]] = columnValues[i];\n }\n return row as T;\n}\n\n/**\n * Compose `columnNames` and `columnValuesList` to an array of row objects.\n * @hidden\n */\nexport function composeRows<T>(columnNames: ColumnNames, columnValuesList: ColumnValues[]): T[] {\n if (columnValuesList.length === 0) {\n return [];\n }\n if (columnNames.length !== columnValuesList[0].length) {\n // We only check the first row because SQLite returns the same column count for all rows.\n throw new Error(\n `Column names and values count mismatch. Names: ${columnNames.length}, Values: ${columnValuesList[0].length}`\n );\n }\n const results: T[] = [];\n for (const columnValues of columnValuesList) {\n const row = {};\n for (let i = 0; i < columnNames.length; i++) {\n row[columnNames[i]] = columnValues[i];\n }\n results.push(row as T);\n }\n return results;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Statement.js","sourceRoot":"","sources":["../../src/next/Statement.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,MAAM,OAAO,SAAS;IAED;IACA;IAFnB,YACmB,cAA8B,EAC9B,eAAgC;QADhC,mBAAc,GAAd,cAAc,CAAgB;QAC9B,oBAAe,GAAf,eAAe,CAAiB;IAChD,CAAC;IAaG,KAAK,CAAC,QAAQ,CAAC,GAAG,MAAiB;QACxC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE,GAAG,eAAe,CAAC,GAAG,MAAM,CAAC,CAAC;QAC9E,IAAI,kBAAkB,EAAE;YACtB,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,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;QACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC3C,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;SACvC;QACD,OAAO,CAAC,IAAI,CAAC,GAAQ,CAAC,CAAC;KACxB;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { NativeDatabase } from './NativeDatabase';\nimport {\n BindParams,\n BindValue,\n NativeStatement,\n RunResult,\n VariadicBindParams,\n type ColumnNames,\n type ColumnValues,\n} from './NativeStatement';\n\nexport { BindParams, BindValue, RunResult, VariadicBindParams };\n\n/**\n * A prepared statement returned by [`Database.prepareAsync()`](#prepareasyncsource) or [`Database.prepareSync()`](#preparesyncsource) that can be binded with parameters and executed.\n */\nexport class Statement {\n constructor(\n private readonly nativeDatabase: NativeDatabase,\n private readonly nativeStatement: NativeStatement\n ) {}\n\n //#region Asynchronous API\n\n /**\n * Run the prepared statement and return the result.\n * @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.\n */\n public runAsync(params: BindParams): Promise<RunResult>;\n /**\n * @hidden\n */\n public runAsync(...params: VariadicBindParams): Promise<RunResult>;\n public async runAsync(...params: unknown[]): Promise<RunResult> {\n const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);\n if (shouldPassAsObject) {\n return await this.nativeStatement.objectRunAsync(this.nativeDatabase, bindParams);\n } else {\n return await this.nativeStatement.arrayRunAsync(this.nativeDatabase, bindParams);\n }\n }\n\n /**\n * Iterate the prepared statement and return results as an async iterable.\n * @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.\n * @example\n * ```ts\n * const statement = await db.prepareAsync('SELECT * FROM test');\n * for await (const row of statement.eachAsync<any>()) {\n * console.log(row);\n * }\n * await statement.finalizeAsync();\n * ```\n */\n public eachAsync<T>(params: BindParams): AsyncIterableIterator<T>;\n /**\n * @hidden\n */\n public eachAsync<T>(...params: VariadicBindParams): AsyncIterableIterator<T>;\n public async *eachAsync<T>(...params: unknown[]): AsyncIterableIterator<T> {\n const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);\n const func = shouldPassAsObject\n ? this.nativeStatement.objectGetAsync.bind(this.nativeStatement)\n : this.nativeStatement.arrayGetAsync.bind(this.nativeStatement);\n\n const columnNames = await this.getColumnNamesAsync();\n let result = null;\n do {\n result = await func(this.nativeDatabase, bindParams);\n if (result != null) {\n yield composeRow<T>(columnNames, result);\n }\n } while (result != null);\n }\n\n /**\n * Get one row from the prepared statement.\n * @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.\n */\n public getAsync<T>(params: BindParams): Promise<T | null>;\n /**\n * @hidden\n */\n public getAsync<T>(...params: VariadicBindParams): Promise<T | null>;\n public async getAsync<T>(...params: unknown[]): Promise<T | null> {\n const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);\n const columnNames = await this.getColumnNamesAsync();\n const columnValues = shouldPassAsObject\n ? await this.nativeStatement.objectGetAsync(this.nativeDatabase, bindParams)\n : await this.nativeStatement.arrayGetAsync(this.nativeDatabase, bindParams);\n return columnValues != null ? composeRow<T>(columnNames, columnValues) : null;\n }\n\n /**\n * Get all rows from the prepared statement.\n * @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.\n */\n public allAsync<T>(params: BindParams): Promise<T[]>;\n /**\n * @hidden\n */\n public allAsync<T>(...params: VariadicBindParams): Promise<T[]>;\n public async allAsync<T>(...params: unknown[]): Promise<T[]> {\n const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);\n const columnNames = await this.getColumnNamesAsync();\n const columnValuesList = shouldPassAsObject\n ? await this.nativeStatement.objectGetAllAsync(this.nativeDatabase, bindParams)\n : await this.nativeStatement.arrayGetAllAsync(this.nativeDatabase, bindParams);\n return composeRows<T>(columnNames, columnValuesList);\n }\n\n /**\n * Get the column names of the prepared statement.\n */\n public getColumnNamesAsync(): Promise<string[]> {\n return this.nativeStatement.getColumnNamesAsync();\n }\n\n /**\n * Reset the prepared statement cursor.\n */\n public async resetAsync(): Promise<void> {\n await this.nativeStatement.resetAsync(this.nativeDatabase);\n }\n\n /**\n * Finalize the prepared statement.\n * > **Note:** Remember to finalize the prepared statement whenever you call `prepareAsync()` to avoid resource leaks.\n */\n public async finalizeAsync(): Promise<void> {\n await this.nativeStatement.finalizeAsync(this.nativeDatabase);\n }\n\n //#endregion\n\n //#region Synchronous API\n\n /**\n * Run the prepared statement and return the result.\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @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.\n */\n public runSync(params: BindParams): RunResult;\n /**\n * @hidden\n */\n public runSync(...params: VariadicBindParams): RunResult;\n public runSync(...params: unknown[]): RunResult {\n const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);\n if (shouldPassAsObject) {\n return this.nativeStatement.objectRunSync(this.nativeDatabase, bindParams);\n } else {\n return this.nativeStatement.arrayRunSync(this.nativeDatabase, bindParams);\n }\n }\n\n /**\n * Iterate the prepared statement and return results as an iterable.\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @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.\n */\n public eachSync<T>(params: BindParams): IterableIterator<T>;\n /**\n * @hidden\n */\n public eachSync<T>(...params: VariadicBindParams): IterableIterator<T>;\n public *eachSync<T>(...params: unknown[]): IterableIterator<T> {\n const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);\n const func = shouldPassAsObject\n ? this.nativeStatement.objectGetSync.bind(this.nativeStatement)\n : this.nativeStatement.arrayGetSync.bind(this.nativeStatement);\n\n const columnNames = this.getColumnNamesSync();\n let result = null;\n do {\n result = func(this.nativeDatabase, bindParams);\n if (result != null) {\n yield composeRow<T>(columnNames, result);\n }\n } while (result != null);\n }\n\n /**\n * Get one row from the prepared statement.\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @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.\n */\n public getSync<T>(params: BindParams): T | null;\n /**\n * @hidden\n */\n public getSync<T>(...params: VariadicBindParams): T | null;\n public getSync<T>(...params: unknown[]): T | null {\n const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);\n const columnNames = this.getColumnNamesSync();\n const columnValues = shouldPassAsObject\n ? this.nativeStatement.objectGetSync(this.nativeDatabase, bindParams)\n : this.nativeStatement.arrayGetSync(this.nativeDatabase, bindParams);\n return columnValues != null ? composeRow<T>(columnNames, columnValues) : null;\n }\n\n /**\n * Get all rows from the prepared statement.\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @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.\n */\n public allSync<T>(params: BindParams): T[];\n /**\n * @hidden\n */\n public allSync<T>(...params: VariadicBindParams): T[];\n public allSync<T>(...params: unknown[]): T[] {\n const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);\n const columnNames = this.getColumnNamesSync();\n const columnValuesList = shouldPassAsObject\n ? this.nativeStatement.objectGetAllSync(this.nativeDatabase, bindParams)\n : this.nativeStatement.arrayGetAllSync(this.nativeDatabase, bindParams);\n return composeRows<T>(columnNames, columnValuesList);\n }\n\n /**\n * Get the column names of the prepared statement.\n */\n public getColumnNamesSync(): string[] {\n return this.nativeStatement.getColumnNamesSync();\n }\n\n /**\n * Reset the prepared statement cursor.\n */\n public resetSync(): void {\n this.nativeStatement.resetSync(this.nativeDatabase);\n }\n\n /**\n * Finalize the prepared statement.\n *\n * > **Note:** Remember to finalize the prepared statement whenever you call `prepareSync()` to avoid resource leaks.\n *\n */\n public finalizeSync(): void {\n this.nativeStatement.finalizeSync(this.nativeDatabase);\n }\n\n //#endregion\n}\n\n/**\n * Normalize the bind params to an array or object.\n * @hidden\n */\nexport function normalizeParams(...params: any[]): {\n params: BindParams;\n shouldPassAsObject: boolean;\n} {\n let bindParams = params.length > 1 ? params : (params[0] as BindParams);\n if (bindParams == null) {\n bindParams = [];\n }\n if (typeof bindParams !== 'object') {\n bindParams = [bindParams];\n }\n const shouldPassAsObject = !Array.isArray(bindParams);\n return {\n params: bindParams,\n shouldPassAsObject,\n };\n}\n\n/**\n * Compose `columnNames` and `columnValues` to an row object.\n * @hidden\n */\nexport function composeRow<T>(columnNames: ColumnNames, columnValues: ColumnValues): T {\n const row = {};\n if (columnNames.length !== columnValues.length) {\n throw new Error(\n `Column names and values count mismatch. Names: ${columnNames.length}, Values: ${columnValues.length}`\n );\n }\n for (let i = 0; i < columnNames.length; i++) {\n row[columnNames[i]] = columnValues[i];\n }\n return row as T;\n}\n\n/**\n * Compose `columnNames` and `columnValuesList` to an array of row objects.\n * @hidden\n */\nexport function composeRows<T>(columnNames: ColumnNames, columnValuesList: ColumnValues[]): T[] {\n if (columnValuesList.length === 0) {\n return [];\n }\n if (columnNames.length !== columnValuesList[0].length) {\n // We only check the first row because SQLite returns the same column count for all rows.\n throw new Error(\n `Column names and values count mismatch. Names: ${columnNames.length}, Values: ${columnValuesList[0].length}`\n );\n }\n const results: T[] = [];\n for (const columnValues of columnValuesList) {\n const row = {};\n for (let i = 0; i < columnNames.length; i++) {\n row[columnNames[i]] = columnValues[i];\n }\n results.push(row as T);\n }\n return results;\n}\n"]}
|
package/build/next/hooks.d.ts
CHANGED
|
@@ -30,6 +30,31 @@ export interface SQLiteProviderProps {
|
|
|
30
30
|
*/
|
|
31
31
|
errorHandler?: (error: Error) => void;
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Context.Provider component that provides a SQLite database to all children.
|
|
35
|
+
* All descendants of this component will be able to access the database using the [`useSQLiteContext`](#usesqlitecontext) hook.
|
|
36
|
+
*/
|
|
33
37
|
export declare function SQLiteProvider({ dbName, options, children, initHandler, loadingFallback, errorHandler, }: SQLiteProviderProps): JSX.Element | null;
|
|
38
|
+
/**
|
|
39
|
+
* A global hook for accessing the SQLite database across components.
|
|
40
|
+
* This hook should only be used within a [`<SQLiteProvider>`](#sqliteprovider) component.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* export default function App() {
|
|
45
|
+
* return (
|
|
46
|
+
* <SQLiteProvider dbName="test.db">
|
|
47
|
+
* <Main />
|
|
48
|
+
* </SQLiteProvider>
|
|
49
|
+
* );
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* export function Main() {
|
|
53
|
+
* const db = useSQLiteContext();
|
|
54
|
+
* console.log('sqlite version', db.getSync('SELECT sqlite_version()'));
|
|
55
|
+
* return <View />
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
34
59
|
export declare function useSQLiteContext(): Database;
|
|
35
60
|
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/next/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiE,MAAM,OAAO,CAAC;AAEtF,OAAO,EAAqB,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,CAAC,EAAE,WAAW,CAAC;IAEtB;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAE1B;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9C;;;OAGG;IACH,eAAe,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAElC;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACvC;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/next/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiE,MAAM,OAAO,CAAC;AAEtF,OAAO,EAAqB,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,CAAC,EAAE,WAAW,CAAC;IAEtB;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAE1B;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9C;;;OAGG;IACH,eAAe,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAElC;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACvC;AAOD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAC7B,MAAM,EACN,OAAO,EACP,QAAQ,EACR,WAAW,EACX,eAAe,EACf,YAAY,GACb,EAAE,mBAAmB,sBAkDrB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gBAAgB,IAAI,QAAQ,CAM3C"}
|
package/build/next/hooks.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import React, { createContext, useContext, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { openDatabaseAsync } from './Database';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Create a context for the SQLite database
|
|
5
|
+
*/
|
|
4
6
|
const SQLiteContext = createContext(null);
|
|
5
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Context.Provider component that provides a SQLite database to all children.
|
|
9
|
+
* All descendants of this component will be able to access the database using the [`useSQLiteContext`](#usesqlitecontext) hook.
|
|
10
|
+
*/
|
|
6
11
|
export function SQLiteProvider({ dbName, options, children, initHandler, loadingFallback, errorHandler, }) {
|
|
7
12
|
const databaseRef = useRef(null);
|
|
8
13
|
const [loading, setLoading] = useState(true);
|
|
@@ -49,7 +54,27 @@ export function SQLiteProvider({ dbName, options, children, initHandler, loading
|
|
|
49
54
|
}
|
|
50
55
|
return <SQLiteContext.Provider value={databaseRef.current}>{children}</SQLiteContext.Provider>;
|
|
51
56
|
}
|
|
52
|
-
|
|
57
|
+
/**
|
|
58
|
+
* A global hook for accessing the SQLite database across components.
|
|
59
|
+
* This hook should only be used within a [`<SQLiteProvider>`](#sqliteprovider) component.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```tsx
|
|
63
|
+
* export default function App() {
|
|
64
|
+
* return (
|
|
65
|
+
* <SQLiteProvider dbName="test.db">
|
|
66
|
+
* <Main />
|
|
67
|
+
* </SQLiteProvider>
|
|
68
|
+
* );
|
|
69
|
+
* }
|
|
70
|
+
*
|
|
71
|
+
* export function Main() {
|
|
72
|
+
* const db = useSQLiteContext();
|
|
73
|
+
* console.log('sqlite version', db.getSync('SELECT sqlite_version()'));
|
|
74
|
+
* return <View />
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
53
78
|
export function useSQLiteContext() {
|
|
54
79
|
const context = useContext(SQLiteContext);
|
|
55
80
|
if (context == null) {
|
package/build/next/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/next/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,SAA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AE,CAAC;aACxB;YAAC,OAAO,CAAC,EAAE;gBACV,QAAQ,CAAC,CAAC,CAAC,CAAC;aACb;QACH,CAAC;QAED,KAAK,EAAE,CAAC;QAER,OAAO,GAAG,EAAE;YACV,MAAM,EAAE,GAAG,WAAW,CAAC,OAAO,CAAC;YAC/B,QAAQ,CAAC,EAAE,CAAC,CAAC;YACb,WAAW,CAAC,OAAO,GAAG,IAAI,CAAC;YAC3B,UAAU,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC;IAEnC,IAAI,KAAK,IAAI,IAAI,EAAE;QACjB,MAAM,OAAO,GACX,YAAY;YACZ,CAAC,CAAC,CAAC,EAAE,EAAE;gBACL,MAAM,CAAC,CAAC;YACV,CAAC,CAAC,CAAC;QACL,OAAO,CAAC,KAAK,CAAC,CAAC;KAChB;IAED,IAAI,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE;QACnC,OAAO,eAAe,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;KAChE;IACD,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;AACjG,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IAC1C,IAAI,OAAO,IAAI,IAAI,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;KAC5E;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import React, { createContext, useContext, useEffect, useRef, useState } from 'react';\n\nimport { openDatabaseAsync, type Database } from './Database';\nimport type { OpenOptions } from './NativeDatabase';\n\nexport interface SQLiteProviderProps {\n /**\n * The name of the database file to open.\n */\n dbName: string;\n\n /**\n * Open options.\n */\n options?: OpenOptions;\n\n /**\n * The children to render.\n */\n children: React.ReactNode;\n\n /**\n * A custom initialization handler to run before rendering the children.\n * You can use this to run database migrations or other setup tasks.\n */\n initHandler?: (db: Database) => Promise<void>;\n\n /**\n * A custom loading fallback to render before the database is ready.\n * @default null\n */\n loadingFallback?: React.ReactNode;\n\n /**\n * Handle errors from SQLiteProvider.\n * @default rethrow the error\n */\n errorHandler?: (error: Error) => void;\n}\n\n/**\n * Create a context for the SQLite database\n */\nconst SQLiteContext = createContext<Database | null>(null);\n\n/**\n * Context.Provider component that provides a SQLite database to all children.\n * All descendants of this component will be able to access the database using the [`useSQLiteContext`](#usesqlitecontext) hook.\n */\nexport function SQLiteProvider({\n dbName,\n options,\n children,\n initHandler,\n loadingFallback,\n errorHandler,\n}: SQLiteProviderProps) {\n const databaseRef = useRef<Database | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n\n useEffect(() => {\n async function setup() {\n try {\n const db = await openDatabaseAsync(dbName, options);\n if (initHandler != null) {\n await initHandler(db);\n }\n databaseRef.current = db;\n setLoading(false);\n } catch (e) {\n setError(e);\n }\n }\n\n async function teardown(db: Database | null) {\n try {\n await db?.closeAsync();\n } catch (e) {\n setError(e);\n }\n }\n\n setup();\n\n return () => {\n const db = databaseRef.current;\n teardown(db);\n databaseRef.current = null;\n setLoading(true);\n };\n }, [dbName, options, initHandler]);\n\n if (error != null) {\n const handler =\n errorHandler ??\n ((e) => {\n throw e;\n });\n handler(error);\n }\n\n if (loading || !databaseRef.current) {\n return loadingFallback != null ? <>{loadingFallback}</> : null;\n }\n return <SQLiteContext.Provider value={databaseRef.current}>{children}</SQLiteContext.Provider>;\n}\n\n/**\n * A global hook for accessing the SQLite database across components.\n * This hook should only be used within a [`<SQLiteProvider>`](#sqliteprovider) component.\n *\n * @example\n * ```tsx\n * export default function App() {\n * return (\n * <SQLiteProvider dbName=\"test.db\">\n * <Main />\n * </SQLiteProvider>\n * );\n * }\n *\n * export function Main() {\n * const db = useSQLiteContext();\n * console.log('sqlite version', db.getSync('SELECT sqlite_version()'));\n * return <View />\n * }\n * ```\n */\nexport function useSQLiteContext(): Database {\n const context = useContext(SQLiteContext);\n if (context == null) {\n throw new Error('useSQLiteContext must be used within a <SQLiteProvider>');\n }\n return context;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-sqlite",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.2.0",
|
|
4
4
|
"description": "Provides access to a database that can be queried through a WebSQL-like API (https://www.w3.org/TR/webdatabase/). The database is persisted across restarts of your app.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"expo": "*"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "3142a086578deffd8704a8f1b6f0f661527d836c"
|
|
50
50
|
}
|