expo-sqlite 11.7.1 → 12.0.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 +31 -0
- package/android/CMakeLists.txt +35 -0
- package/android/build.gradle +114 -29
- package/android/src/main/cpp/NativeDatabaseBinding.cpp +142 -0
- package/android/src/main/cpp/NativeDatabaseBinding.h +75 -0
- package/android/src/main/cpp/NativeStatementBinding.cpp +146 -0
- package/android/src/main/cpp/NativeStatementBinding.h +95 -0
- package/android/src/main/cpp/SQLite3Main.cpp +15 -0
- package/android/src/main/cpp/SQLite3Wrapper.cpp +223 -0
- package/android/src/main/cpp/SQLite3Wrapper.h +55 -0
- package/android/src/main/java/expo/modules/sqlite/NativeDatabase.kt +11 -0
- package/android/src/main/java/expo/modules/sqlite/NativeDatabaseBinding.kt +79 -0
- package/android/src/main/java/expo/modules/sqlite/NativeStatement.kt +11 -0
- package/android/src/main/java/expo/modules/sqlite/NativeStatementBinding.kt +40 -0
- package/android/src/main/java/expo/modules/sqlite/SQLExceptions.kt +17 -6
- package/android/src/main/java/expo/modules/sqlite/SQLRecords.kt +16 -3
- package/android/src/main/java/expo/modules/sqlite/SQLite3Wrapper.kt +51 -0
- package/android/src/main/java/expo/modules/sqlite/SQLiteHelpers.kt +0 -79
- package/android/src/main/java/expo/modules/sqlite/SQLiteModule.kt +31 -222
- package/android/src/main/java/expo/modules/sqlite/SQLiteModuleNext.kt +447 -0
- package/android/src/main/java/expo/modules/sqlite/SQLiteOptions.kt +20 -0
- package/build/next/Database.d.ts +254 -0
- package/build/next/Database.d.ts.map +1 -0
- package/build/next/Database.js +324 -0
- package/build/next/Database.js.map +1 -0
- package/build/next/ExpoSQLiteNext.d.ts +12 -0
- package/build/next/ExpoSQLiteNext.d.ts.map +1 -0
- package/build/next/ExpoSQLiteNext.js +26 -0
- package/build/next/ExpoSQLiteNext.js.map +1 -0
- package/build/next/ExpoSQLiteNext.native.d.ts +3 -0
- package/build/next/ExpoSQLiteNext.native.d.ts.map +1 -0
- package/build/next/ExpoSQLiteNext.native.js +3 -0
- package/build/next/ExpoSQLiteNext.native.js.map +1 -0
- package/build/next/NativeDatabase.d.ts +44 -0
- package/build/next/NativeDatabase.d.ts.map +1 -0
- package/build/next/NativeDatabase.js +2 -0
- package/build/next/NativeDatabase.js.map +1 -0
- package/build/next/NativeStatement.d.ts +68 -0
- package/build/next/NativeStatement.d.ts.map +1 -0
- package/build/next/NativeStatement.js +2 -0
- package/build/next/NativeStatement.js.map +1 -0
- package/build/next/Statement.d.ts +120 -0
- package/build/next/Statement.d.ts.map +1 -0
- package/build/next/Statement.js +135 -0
- package/build/next/Statement.js.map +1 -0
- package/build/next/hooks.d.ts +35 -0
- package/build/next/hooks.d.ts.map +1 -0
- package/build/next/hooks.js +57 -0
- package/build/next/hooks.js.map +1 -0
- package/build/next/index.d.ts +4 -0
- package/build/next/index.d.ts.map +1 -0
- package/build/next/index.js +4 -0
- package/build/next/index.js.map +1 -0
- package/expo-module.config.json +2 -2
- package/ios/CRSQLiteLoader.h +3 -1
- package/ios/CRSQLiteLoader.m +11 -6
- package/ios/Exceptions.swift +13 -0
- package/ios/ExpoSQLite.podspec +2 -2
- package/ios/NativeDatabase.swift +26 -0
- package/ios/NativeStatement.swift +13 -0
- package/ios/SQLAction.swift +23 -0
- package/ios/SQLiteModule.swift +0 -53
- package/ios/SQLiteModuleNext.swift +538 -0
- package/ios/SQLiteOptions.swift +26 -0
- package/next.d.ts +1 -0
- package/next.js +1 -0
- package/package.json +4 -2
- package/src/next/Database.ts +446 -0
- package/src/next/ExpoSQLiteNext.native.ts +2 -0
- package/src/next/ExpoSQLiteNext.ts +34 -0
- package/src/next/NativeDatabase.ts +58 -0
- package/src/next/NativeStatement.ts +85 -0
- package/src/next/Statement.ts +243 -0
- package/src/next/hooks.tsx +108 -0
- package/src/next/index.ts +3 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpoSQLiteNext.js","sourceRoot":"","sources":["../../src/next/ExpoSQLiteNext.ts"],"names":[],"mappings":"AAEA,eAAe;IACb,IAAI,IAAI;QACN,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED,cAAc,CAAC,MAAc,EAAE,OAAqB;QAClD,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED,eAAe;QACb,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,MAAc;QACtC,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED,kBAAkB,CAAC,MAAc;QAC/B,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED,sCAAsC;IAEtC,WAAW;QACT,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IACD,eAAe;QACb,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED,YAAY;CACb,CAAC","sourcesContent":["import { OpenOptions } from './NativeDatabase';\n\nexport default {\n get name(): string {\n return 'ExpoSQLiteNext';\n },\n\n NativeDatabase(dbName: string, options?: OpenOptions): void {\n throw new Error('Unimplemented');\n },\n\n NativeStatement(): void {\n throw new Error('Unimplemented');\n },\n\n async deleteDatabaseAsync(dbName: string): Promise<void> {\n throw new Error('Unimplemented');\n },\n\n deleteDatabaseSync(dbName: string): void {\n throw new Error('Unimplemented');\n },\n\n //#region EventEmitter implementations\n\n addListener() {\n throw new Error('Unimplemented');\n },\n removeListeners() {\n throw new Error('Unimplemented');\n },\n\n //#endregion\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpoSQLiteNext.native.d.ts","sourceRoot":"","sources":["../../src/next/ExpoSQLiteNext.native.ts"],"names":[],"mappings":";AACA,wBAAqD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpoSQLiteNext.native.js","sourceRoot":"","sources":["../../src/next/ExpoSQLiteNext.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,eAAe,mBAAmB,CAAC,gBAAgB,CAAC,CAAC","sourcesContent":["import { requireNativeModule } from 'expo-modules-core';\nexport default requireNativeModule('ExpoSQLiteNext');\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { NativeStatement } from './NativeStatement';
|
|
2
|
+
/**
|
|
3
|
+
* A class that represents an instance of the SQLite database.
|
|
4
|
+
*/
|
|
5
|
+
export declare class NativeDatabase {
|
|
6
|
+
constructor(dbName: string, options?: OpenOptions);
|
|
7
|
+
initAsync(): Promise<void>;
|
|
8
|
+
isInTransactionAsync(): Promise<boolean>;
|
|
9
|
+
closeAsync(): Promise<void>;
|
|
10
|
+
execAsync(source: string): Promise<void>;
|
|
11
|
+
prepareAsync(nativeStatement: NativeStatement, source: string): Promise<NativeStatement>;
|
|
12
|
+
initSync(): void;
|
|
13
|
+
isInTransactionSync(): boolean;
|
|
14
|
+
closeSync(): void;
|
|
15
|
+
execSync(source: string): void;
|
|
16
|
+
prepareSync(nativeStatement: NativeStatement, source: string): NativeStatement;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Options for opening a database.
|
|
20
|
+
*/
|
|
21
|
+
export interface OpenOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Whether to enable the CR-SQLite extension.
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
enableCRSQLite?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to call the `sqlite3_update_hook` function and enable the `onDatabaseChange` events.
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
enableChangeListener?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether to create new connection even if connection with the same database name exists in cache.
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
useNewConnection?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Finalized unclosed statements automatically when the database is closed.
|
|
39
|
+
* @default true
|
|
40
|
+
* @hidden
|
|
41
|
+
*/
|
|
42
|
+
finalizeUnusedStatementsBeforeClosing?: boolean;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=NativeDatabase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeDatabase.d.ts","sourceRoot":"","sources":["../../src/next/NativeDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,cAAc;gBACrB,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW;IAI1C,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAC1B,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC;IACxC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAC3B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IACxC,YAAY,CAAC,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAMxF,QAAQ,IAAI,IAAI;IAChB,mBAAmB,IAAI,OAAO;IAC9B,SAAS,IAAI,IAAI;IACjB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAC9B,WAAW,CAAC,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe;CAGtF;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;;OAIG;IACH,qCAAqC,CAAC,EAAE,OAAO,CAAC;CACjD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeDatabase.js","sourceRoot":"","sources":["../../src/next/NativeDatabase.ts"],"names":[],"mappings":"","sourcesContent":["import { NativeStatement } from './NativeStatement';\n\n/**\n * A class that represents an instance of the SQLite database.\n */\nexport declare class NativeDatabase {\n constructor(dbName: string, options?: OpenOptions);\n\n //#region Asynchronous API\n\n public initAsync(): Promise<void>;\n public isInTransactionAsync(): Promise<boolean>;\n public closeAsync(): Promise<void>;\n public execAsync(source: string): Promise<void>;\n public prepareAsync(nativeStatement: NativeStatement, source: string): Promise<NativeStatement>;\n\n //#endregion\n\n //#region Synchronous API\n\n public initSync(): void;\n public isInTransactionSync(): boolean;\n public closeSync(): void;\n public execSync(source: string): void;\n public prepareSync(nativeStatement: NativeStatement, source: string): NativeStatement;\n\n //#endregion\n}\n\n/**\n * Options for opening a database.\n */\nexport interface OpenOptions {\n /**\n * Whether to enable the CR-SQLite extension.\n * @default false\n */\n enableCRSQLite?: boolean;\n\n /**\n * Whether to call the `sqlite3_update_hook` function and enable the `onDatabaseChange` events.\n * @default false\n */\n enableChangeListener?: boolean;\n\n /**\n * Whether to create new connection even if connection with the same database name exists in cache.\n * @default false\n */\n useNewConnection?: boolean;\n\n /**\n * Finalized unclosed statements automatically when the database is closed.\n * @default true\n * @hidden\n */\n finalizeUnusedStatementsBeforeClosing?: boolean;\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result of a `runAsync` call.
|
|
3
|
+
*/
|
|
4
|
+
export interface RunResult {
|
|
5
|
+
/**
|
|
6
|
+
* The last inserted row ID.
|
|
7
|
+
*/
|
|
8
|
+
lastInsertRowid: number;
|
|
9
|
+
/**
|
|
10
|
+
* The number of rows affected.
|
|
11
|
+
*/
|
|
12
|
+
changes: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Bind parameters to the prepared statement.
|
|
16
|
+
* You can either pass the parameters in the following forms:
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* - Variadic arguments for unnamed parameters.
|
|
20
|
+
* ```ts
|
|
21
|
+
* const statement = await db.prepareAsync('SELECT * FROM test WHERE value = ? AND intValue = ?');
|
|
22
|
+
* await statement.getAsync('test1', 789);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* - A single array for unnamed parameters.
|
|
27
|
+
* ```ts
|
|
28
|
+
* const statement = await db.prepareAsync('SELECT * FROM test WHERE value = ? AND intValue = ?');
|
|
29
|
+
* await statement.getAsync(['test1', 789]);
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* - A single object for [named parameters](https://www.sqlite.org/lang_expr.html)
|
|
34
|
+
*
|
|
35
|
+
* Through we support multiple named parameter forms like `:VVV`, `@VVV`, and `$VVV`. We recommend using `$VVV` because JavaScript allows using `$` in identifiers without escaping.
|
|
36
|
+
* ```ts
|
|
37
|
+
* const statement = await db.prepareAsync('SELECT * FROM test WHERE value = $value AND intValue = $intValue');
|
|
38
|
+
* await statement.getAsync({ $value: 'test1', $intValue: 789 });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export type BindValue = string | number | null | boolean;
|
|
42
|
+
export type BindParams = Record<string, BindValue> | BindValue[];
|
|
43
|
+
export type VariadicBindParams = BindValue[];
|
|
44
|
+
type Row = any;
|
|
45
|
+
type AnyDatabase = any;
|
|
46
|
+
/**
|
|
47
|
+
* A class that represents an instance of the SQLite statement.
|
|
48
|
+
*/
|
|
49
|
+
export declare class NativeStatement {
|
|
50
|
+
arrayRunAsync(database: AnyDatabase, params: BindParams): Promise<RunResult>;
|
|
51
|
+
objectRunAsync(database: AnyDatabase, params: BindParams): Promise<RunResult>;
|
|
52
|
+
arrayGetAsync(database: AnyDatabase, params: BindParams): Promise<Row | null | undefined>;
|
|
53
|
+
objectGetAsync(database: AnyDatabase, params: BindParams): Promise<Row | null | undefined>;
|
|
54
|
+
arrayGetAllAsync(database: AnyDatabase, params: BindParams): Promise<Row[]>;
|
|
55
|
+
objectGetAllAsync(database: AnyDatabase, params: BindParams): Promise<Row[]>;
|
|
56
|
+
resetAsync(database: AnyDatabase): Promise<void>;
|
|
57
|
+
finalizeAsync(database: AnyDatabase): Promise<void>;
|
|
58
|
+
arrayRunSync(database: AnyDatabase, params: BindParams): RunResult;
|
|
59
|
+
objectRunSync(database: AnyDatabase, params: BindParams): RunResult;
|
|
60
|
+
arrayGetSync(database: AnyDatabase, params: BindParams): Row | null | undefined;
|
|
61
|
+
objectGetSync(database: AnyDatabase, params: BindParams): Row | null | undefined;
|
|
62
|
+
arrayGetAllSync(database: AnyDatabase, params: BindParams): Row[];
|
|
63
|
+
objectGetAllSync(database: AnyDatabase, params: BindParams): Row[];
|
|
64
|
+
resetSync(database: AnyDatabase): void;
|
|
65
|
+
finalizeSync(database: AnyDatabase): void;
|
|
66
|
+
}
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=NativeStatement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeStatement.d.ts","sourceRoot":"","sources":["../../src/next/NativeStatement.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC;AACzD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,SAAS,EAAE,CAAC;AACjE,MAAM,MAAM,kBAAkB,GAAG,SAAS,EAAE,CAAC;AAE7C,KAAK,GAAG,GAAG,GAAG,CAAC;AACf,KAAK,WAAW,GAAG,GAAG,CAAC;AAEvB;;GAEG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CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,GAAG,GAAG,EAAE;IAElE,SAAS,CAAC,QAAQ,EAAE,WAAW,GAAG,IAAI;IACtC,YAAY,CAAC,QAAQ,EAAE,WAAW,GAAG,IAAI;CAGjD"}
|
|
@@ -0,0 +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 * - 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 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 * - A single object for [named parameters](https://www.sqlite.org/lang_expr.html)\n *\n * Through we support multiple named parameter forms like `: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\ntype Row = 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(database: AnyDatabase, params: BindParams): Promise<Row | null | undefined>;\n public objectGetAsync(database: AnyDatabase, params: BindParams): Promise<Row | null | undefined>;\n\n public arrayGetAllAsync(database: AnyDatabase, params: BindParams): Promise<Row[]>;\n public objectGetAllAsync(database: AnyDatabase, params: BindParams): Promise<Row[]>;\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): Row | null | undefined;\n public objectGetSync(database: AnyDatabase, params: BindParams): Row | null | undefined;\n\n public arrayGetAllSync(database: AnyDatabase, params: BindParams): Row[];\n public objectGetAllSync(database: AnyDatabase, params: BindParams): Row[];\n\n public resetSync(database: AnyDatabase): void;\n public finalizeSync(database: AnyDatabase): void;\n\n //#endregion\n}\n"]}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { NativeDatabase } from './NativeDatabase';
|
|
2
|
+
import { BindParams, BindValue, NativeStatement, RunResult, VariadicBindParams } from './NativeStatement';
|
|
3
|
+
export { BindParams, BindValue, RunResult, VariadicBindParams };
|
|
4
|
+
/**
|
|
5
|
+
* A prepared statement returned by `Database.prepareAsync()` that can be binded with parameters and executed.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Statement {
|
|
8
|
+
private readonly nativeDatabase;
|
|
9
|
+
private readonly nativeStatement;
|
|
10
|
+
constructor(nativeDatabase: NativeDatabase, nativeStatement: NativeStatement);
|
|
11
|
+
/**
|
|
12
|
+
* Run the prepared statement and return the result.
|
|
13
|
+
*
|
|
14
|
+
* @param params @see `BindParams`
|
|
15
|
+
*/
|
|
16
|
+
runAsync(...params: VariadicBindParams): Promise<RunResult>;
|
|
17
|
+
runAsync(params: BindParams): Promise<RunResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Iterate the prepared statement and return results as an async iterable.
|
|
20
|
+
*
|
|
21
|
+
* @param params @see `BindParams`
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const statement = await db.prepareAsync('SELECT * FROM test');
|
|
26
|
+
* for await (const row of statement.eachAsync<any>()) {
|
|
27
|
+
* console.log(row);
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
eachAsync<T>(...params: VariadicBindParams): AsyncIterableIterator<T>;
|
|
32
|
+
eachAsync<T>(params: BindParams): AsyncIterableIterator<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Get one row from the prepared statement.
|
|
35
|
+
*
|
|
36
|
+
* @param params @see `BindParams`
|
|
37
|
+
*/
|
|
38
|
+
getAsync<T>(...params: VariadicBindParams): Promise<T | null>;
|
|
39
|
+
getAsync<T>(params: BindParams): Promise<T | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Get all rows from the prepared statement.
|
|
42
|
+
*
|
|
43
|
+
* @param params @see `BindParams`
|
|
44
|
+
*/
|
|
45
|
+
allAsync<T>(...params: VariadicBindParams): Promise<T[]>;
|
|
46
|
+
allAsync<T>(params: BindParams): Promise<T[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Reset the prepared statement cursor.
|
|
49
|
+
*/
|
|
50
|
+
resetAsync(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Finalize the prepared statement.
|
|
53
|
+
* > **Note:** Remember to finalize the prepared statement whenever you call `prepareAsync()` to avoid resource leaks.
|
|
54
|
+
*/
|
|
55
|
+
finalizeAsync(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Run the prepared statement and return the result.
|
|
58
|
+
*
|
|
59
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.
|
|
60
|
+
*
|
|
61
|
+
* @param params @see `BindParams`
|
|
62
|
+
*/
|
|
63
|
+
runSync(...params: VariadicBindParams): RunResult;
|
|
64
|
+
runSync(params: BindParams): RunResult;
|
|
65
|
+
/**
|
|
66
|
+
* Iterate the prepared statement and return results as an iterable.
|
|
67
|
+
*
|
|
68
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.
|
|
69
|
+
*
|
|
70
|
+
* @param params @see `BindParams`
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const statement = await db.prepareSync('SELECT * FROM test');
|
|
75
|
+
* for (const row of statement.eachSync<any>()) {
|
|
76
|
+
* console.log(row);
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
eachSync<T>(...params: VariadicBindParams): IterableIterator<T>;
|
|
81
|
+
eachSync<T>(params: BindParams): IterableIterator<T>;
|
|
82
|
+
/**
|
|
83
|
+
* Get one row from the prepared statement.
|
|
84
|
+
*
|
|
85
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.
|
|
86
|
+
*
|
|
87
|
+
* @param params @see `BindParams`
|
|
88
|
+
*/
|
|
89
|
+
getSync<T>(...params: VariadicBindParams): T | null;
|
|
90
|
+
getSync<T>(params: BindParams): T | null;
|
|
91
|
+
/**
|
|
92
|
+
* Get all rows from the prepared statement.
|
|
93
|
+
*
|
|
94
|
+
* > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.
|
|
95
|
+
*
|
|
96
|
+
* @param params @see `BindParams`
|
|
97
|
+
*/
|
|
98
|
+
allSync<T>(...params: VariadicBindParams): T[];
|
|
99
|
+
allSync<T>(params: BindParams): T[];
|
|
100
|
+
/**
|
|
101
|
+
* Reset the prepared statement cursor.
|
|
102
|
+
*/
|
|
103
|
+
resetSync(): void;
|
|
104
|
+
/**
|
|
105
|
+
* Finalize the prepared statement.
|
|
106
|
+
*
|
|
107
|
+
* > **Note:** Remember to finalize the prepared statement whenever you call `prepareSync()` to avoid resource leaks.
|
|
108
|
+
*
|
|
109
|
+
*/
|
|
110
|
+
finalizeSync(): void;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Normalize the bind params to an array or object.
|
|
114
|
+
* @hidden
|
|
115
|
+
*/
|
|
116
|
+
export declare function normalizeParams(...params: any[]): {
|
|
117
|
+
params: BindParams;
|
|
118
|
+
shouldPassAsObject: boolean;
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=Statement.d.ts.map
|
|
@@ -0,0 +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,EACnB,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;;;;OAIG;IACI,QAAQ,CAAC,GAAG,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,SAAS,CAAC;IAC3D,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;IAUvD;;;;;;;;;;;;OAYG;IACI,SAAS,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,kBAAkB,GAAG,qBAAqB,CAAC,CAAC,CAAC;IACrE,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,GAAG,qBAAqB,CAAC,CAAC,CAAC;IAgBjE;;;;OAIG;IACI,QAAQ,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAC7D,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,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7B,CAUA"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A prepared statement returned by `Database.prepareAsync()` that can be binded with parameters and executed.
|
|
3
|
+
*/
|
|
4
|
+
export class Statement {
|
|
5
|
+
nativeDatabase;
|
|
6
|
+
nativeStatement;
|
|
7
|
+
constructor(nativeDatabase, nativeStatement) {
|
|
8
|
+
this.nativeDatabase = nativeDatabase;
|
|
9
|
+
this.nativeStatement = nativeStatement;
|
|
10
|
+
}
|
|
11
|
+
async runAsync(...params) {
|
|
12
|
+
const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);
|
|
13
|
+
if (shouldPassAsObject) {
|
|
14
|
+
return await this.nativeStatement.objectRunAsync(this.nativeDatabase, bindParams);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return await this.nativeStatement.arrayRunAsync(this.nativeDatabase, bindParams);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async *eachAsync(...params) {
|
|
21
|
+
const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);
|
|
22
|
+
const func = shouldPassAsObject
|
|
23
|
+
? this.nativeStatement.objectGetAsync.bind(this.nativeStatement)
|
|
24
|
+
: this.nativeStatement.arrayGetAsync.bind(this.nativeStatement);
|
|
25
|
+
let result = null;
|
|
26
|
+
do {
|
|
27
|
+
result = await func(this.nativeDatabase, bindParams);
|
|
28
|
+
if (result != null) {
|
|
29
|
+
yield result;
|
|
30
|
+
}
|
|
31
|
+
} while (result != null);
|
|
32
|
+
}
|
|
33
|
+
async getAsync(...params) {
|
|
34
|
+
const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);
|
|
35
|
+
if (shouldPassAsObject) {
|
|
36
|
+
return (await this.nativeStatement.objectGetAsync(this.nativeDatabase, bindParams)) ?? null;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return (await this.nativeStatement.arrayGetAsync(this.nativeDatabase, bindParams)) ?? null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async allAsync(...params) {
|
|
43
|
+
const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);
|
|
44
|
+
if (shouldPassAsObject) {
|
|
45
|
+
return await this.nativeStatement.objectGetAllAsync(this.nativeDatabase, bindParams);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return await this.nativeStatement.arrayGetAllAsync(this.nativeDatabase, bindParams);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reset the prepared statement cursor.
|
|
53
|
+
*/
|
|
54
|
+
async resetAsync() {
|
|
55
|
+
await this.nativeStatement.resetAsync(this.nativeDatabase);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Finalize the prepared statement.
|
|
59
|
+
* > **Note:** Remember to finalize the prepared statement whenever you call `prepareAsync()` to avoid resource leaks.
|
|
60
|
+
*/
|
|
61
|
+
async finalizeAsync() {
|
|
62
|
+
await this.nativeStatement.finalizeAsync(this.nativeDatabase);
|
|
63
|
+
}
|
|
64
|
+
runSync(...params) {
|
|
65
|
+
const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);
|
|
66
|
+
if (shouldPassAsObject) {
|
|
67
|
+
return this.nativeStatement.objectRunSync(this.nativeDatabase, bindParams);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return this.nativeStatement.arrayRunSync(this.nativeDatabase, bindParams);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
*eachSync(...params) {
|
|
74
|
+
const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);
|
|
75
|
+
const func = shouldPassAsObject
|
|
76
|
+
? this.nativeStatement.objectGetSync.bind(this.nativeStatement)
|
|
77
|
+
: this.nativeStatement.arrayGetSync.bind(this.nativeStatement);
|
|
78
|
+
let result = null;
|
|
79
|
+
do {
|
|
80
|
+
result = func(this.nativeDatabase, bindParams);
|
|
81
|
+
if (result != null) {
|
|
82
|
+
yield result;
|
|
83
|
+
}
|
|
84
|
+
} while (result != null);
|
|
85
|
+
}
|
|
86
|
+
getSync(...params) {
|
|
87
|
+
const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);
|
|
88
|
+
if (shouldPassAsObject) {
|
|
89
|
+
return this.nativeStatement.objectGetSync(this.nativeDatabase, bindParams) ?? null;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return this.nativeStatement.arrayGetSync(this.nativeDatabase, bindParams) ?? null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
allSync(...params) {
|
|
96
|
+
const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);
|
|
97
|
+
if (shouldPassAsObject) {
|
|
98
|
+
return this.nativeStatement.objectGetAllSync(this.nativeDatabase, bindParams);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
return this.nativeStatement.arrayGetAllSync(this.nativeDatabase, bindParams);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Reset the prepared statement cursor.
|
|
106
|
+
*/
|
|
107
|
+
resetSync() {
|
|
108
|
+
this.nativeStatement.resetSync(this.nativeDatabase);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Finalize the prepared statement.
|
|
112
|
+
*
|
|
113
|
+
* > **Note:** Remember to finalize the prepared statement whenever you call `prepareSync()` to avoid resource leaks.
|
|
114
|
+
*
|
|
115
|
+
*/
|
|
116
|
+
finalizeSync() {
|
|
117
|
+
this.nativeStatement.finalizeSync(this.nativeDatabase);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Normalize the bind params to an array or object.
|
|
122
|
+
* @hidden
|
|
123
|
+
*/
|
|
124
|
+
export function normalizeParams(...params) {
|
|
125
|
+
let bindParams = params.length > 1 ? params : params[0];
|
|
126
|
+
if (typeof bindParams !== 'object') {
|
|
127
|
+
bindParams = [bindParams];
|
|
128
|
+
}
|
|
129
|
+
const shouldPassAsObject = !Array.isArray(bindParams);
|
|
130
|
+
return {
|
|
131
|
+
params: bindParams,
|
|
132
|
+
shouldPassAsObject,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=Statement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Statement.js","sourceRoot":"","sources":["../../src/next/Statement.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,OAAO,SAAS;IAED;IACA;IAFnB,YACmB,cAA8B,EAC9B,eAAgC;QADhC,mBAAc,GAAd,cAAc,CAAgB;QAC9B,oBAAe,GAAf,eAAe,CAAiB;IAChD,CAAC;IAWG,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,cAAc,CAAC,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;SACnF;aAAM;YACL,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;SAClF;IACH,CAAC;IAiBM,KAAK,CAAC,CAAC,SAAS,CAAI,GAAG,MAAiB;QAC7C,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE,GAAG,eAAe,CAAC,GAAG,MAAM,CAAC,CAAC;QAC9E,MAAM,IAAI,GAAG,kBAAkB;YAC7B,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC;YAChE,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAElE,IAAI,MAAM,GAAa,IAAI,CAAC;QAC5B,GAAG;YACD,MAAM,GAAG,MAAM,IAAI,CAAC,IA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VariadicBindParams,\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 let result: T | null = null;\n do {\n result = await func(this.nativeDatabase, bindParams);\n if (result != null) {\n yield 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 if (shouldPassAsObject) {\n return (await this.nativeStatement.objectGetAsync(this.nativeDatabase, bindParams)) ?? null;\n } else {\n return (await this.nativeStatement.arrayGetAsync(this.nativeDatabase, bindParams)) ?? null;\n }\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 if (shouldPassAsObject) {\n return await this.nativeStatement.objectGetAllAsync(this.nativeDatabase, bindParams);\n } else {\n return await this.nativeStatement.arrayGetAllAsync(this.nativeDatabase, bindParams);\n }\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 let result: T | null = null;\n do {\n result = func(this.nativeDatabase, bindParams);\n if (result != null) {\n yield 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 if (shouldPassAsObject) {\n return this.nativeStatement.objectGetSync(this.nativeDatabase, bindParams) ?? null;\n } else {\n return this.nativeStatement.arrayGetSync(this.nativeDatabase, bindParams) ?? null;\n }\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 if (shouldPassAsObject) {\n return this.nativeStatement.objectGetAllSync(this.nativeDatabase, bindParams);\n } else {\n return this.nativeStatement.arrayGetAllSync(this.nativeDatabase, bindParams);\n }\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 (typeof bindParams !== 'object') {\n bindParams = [bindParams];\n }\n const shouldPassAsObject = !Array.isArray(bindParams);\n return {\n params: bindParams,\n shouldPassAsObject,\n };\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type Database } from './Database';
|
|
3
|
+
import type { OpenOptions } from './NativeDatabase';
|
|
4
|
+
export interface SQLiteProviderProps {
|
|
5
|
+
/**
|
|
6
|
+
* The name of the database file to open.
|
|
7
|
+
*/
|
|
8
|
+
dbName: string;
|
|
9
|
+
/**
|
|
10
|
+
* Open options.
|
|
11
|
+
*/
|
|
12
|
+
options?: OpenOptions;
|
|
13
|
+
/**
|
|
14
|
+
* The children to render.
|
|
15
|
+
*/
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* A custom initialization handler to run before rendering the children.
|
|
19
|
+
* You can use this to run database migrations or other setup tasks.
|
|
20
|
+
*/
|
|
21
|
+
initHandler?: (db: Database) => Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* A custom loading fallback to render before the database is ready.
|
|
24
|
+
* @default null
|
|
25
|
+
*/
|
|
26
|
+
loadingFallback?: React.ReactNode;
|
|
27
|
+
/**
|
|
28
|
+
* Handle errors from SQLiteProvider.
|
|
29
|
+
* @default rethrow the error
|
|
30
|
+
*/
|
|
31
|
+
errorHandler?: (error: Error) => void;
|
|
32
|
+
}
|
|
33
|
+
export declare function SQLiteProvider({ dbName, options, children, initHandler, loadingFallback, errorHandler, }: SQLiteProviderProps): JSX.Element | null;
|
|
34
|
+
export declare function useSQLiteContext(): Database;
|
|
35
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/next/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyD,MAAM,OAAO,CAAC;AAE9E,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;AAMD,wBAAgB,cAAc,CAAC,EAC7B,MAAM,EACN,OAAO,EACP,QAAQ,EACR,WAAW,EACX,eAAe,EACf,YAAY,GACb,EAAE,mBAAmB,sBA+CrB;AAGD,wBAAgB,gBAAgB,aAM/B"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
2
|
+
import { openDatabaseAsync } from './Database';
|
|
3
|
+
// Create a context for the SQLite database
|
|
4
|
+
const SQLiteContext = createContext(null);
|
|
5
|
+
// Create a provider component
|
|
6
|
+
export function SQLiteProvider({ dbName, options, children, initHandler, loadingFallback, errorHandler, }) {
|
|
7
|
+
const [database, setDatabase] = useState(null);
|
|
8
|
+
const [loading, setLoading] = useState(true);
|
|
9
|
+
const [error, setError] = useState(null);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
async function setup() {
|
|
12
|
+
try {
|
|
13
|
+
const db = await openDatabaseAsync(dbName, options);
|
|
14
|
+
setDatabase(db);
|
|
15
|
+
if (initHandler != null) {
|
|
16
|
+
await initHandler(db);
|
|
17
|
+
}
|
|
18
|
+
setLoading(false);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
setError(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function teardown() {
|
|
25
|
+
try {
|
|
26
|
+
await database?.closeAsync();
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
setError(e);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
setup();
|
|
33
|
+
return () => {
|
|
34
|
+
teardown();
|
|
35
|
+
};
|
|
36
|
+
}, [dbName, options, initHandler]);
|
|
37
|
+
if (error != null) {
|
|
38
|
+
const handler = errorHandler ??
|
|
39
|
+
((e) => {
|
|
40
|
+
throw e;
|
|
41
|
+
});
|
|
42
|
+
handler(error);
|
|
43
|
+
}
|
|
44
|
+
if (loading) {
|
|
45
|
+
return loadingFallback != null ? <>{loadingFallback}</> : null;
|
|
46
|
+
}
|
|
47
|
+
return <SQLiteContext.Provider value={database}>{children}</SQLiteContext.Provider>;
|
|
48
|
+
}
|
|
49
|
+
// Create a hook for accessing the SQLite database context
|
|
50
|
+
export function useSQLiteContext() {
|
|
51
|
+
const context = useContext(SQLiteContext);
|
|
52
|
+
if (context == null) {
|
|
53
|
+
throw new Error('useSQLiteContext must be used within a <SQLiteProvider>');
|
|
54
|
+
}
|
|
55
|
+
return context;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/next/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE9E,OAAO,EAAE,iBAAiB,EAAiB,MAAM,YAAY,CAAC;AAsC9D,2CAA2C;A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ACL,MAAM,CAAC,CAAC;YACV,CAAC,CAAC,CAAC;QACL,OAAO,CAAC,KAAK,CAAC,CAAC;KAChB;IAED,IAAI,OAAO,EAAE;QACX,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,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;AACtF,CAAC;AAED,0DAA0D;AAC1D,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, 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// Create a context for the SQLite database\nconst SQLiteContext = createContext<Database | null>(null);\n\n// Create a provider component\nexport function SQLiteProvider({\n dbName,\n options,\n children,\n initHandler,\n loadingFallback,\n errorHandler,\n}: SQLiteProviderProps) {\n const [database, setDatabase] = useState<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 setDatabase(db);\n if (initHandler != null) {\n await initHandler(db);\n }\n setLoading(false);\n } catch (e) {\n setError(e);\n }\n }\n\n async function teardown() {\n try {\n await database?.closeAsync();\n } catch (e) {\n setError(e);\n }\n }\n\n setup();\n\n return () => {\n teardown();\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) {\n return loadingFallback != null ? <>{loadingFallback}</> : null;\n }\n return <SQLiteContext.Provider value={database}>{children}</SQLiteContext.Provider>;\n}\n\n// Create a hook for accessing the SQLite database context\nexport function useSQLiteContext() {\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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC","sourcesContent":["export * from './Database';\nexport * from './Statement';\nexport * from './hooks';\n"]}
|
package/expo-module.config.json
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"name": "expo-sqlite",
|
|
3
3
|
"platforms": ["ios", "android"],
|
|
4
4
|
"ios": {
|
|
5
|
-
"modules": ["SQLiteModule"]
|
|
5
|
+
"modules": ["SQLiteModule", "SQLiteModuleNext"]
|
|
6
6
|
},
|
|
7
7
|
"android": {
|
|
8
|
-
"modules": ["expo.modules.sqlite.SQLiteModule"]
|
|
8
|
+
"modules": ["expo.modules.sqlite.SQLiteModule", "expo.modules.sqlite.SQLiteModuleNext"]
|
|
9
9
|
}
|
|
10
10
|
}
|
package/ios/CRSQLiteLoader.h
CHANGED
package/ios/CRSQLiteLoader.m
CHANGED
|
@@ -3,11 +3,16 @@
|
|
|
3
3
|
#import <ExpoSQLite/CRSQLiteLoader.h>
|
|
4
4
|
#import <sqlite3/sqlite3.h>
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
int result =
|
|
6
|
+
int crsqlite_init_from_swift(sqlite3 *db) {
|
|
7
|
+
sqlite3_enable_load_extension(db, 1);
|
|
8
|
+
char *errorMessage;
|
|
9
|
+
NSBundle *bundle = [NSBundle bundleWithIdentifier:@"io.vlcn.crsqlite"];
|
|
10
|
+
NSString *libPath = [bundle pathForResource:@"crsqlite" ofType:@""];
|
|
11
|
+
int result = sqlite3_load_extension(db, [libPath UTF8String], "sqlite3_crsqlite_init", &errorMessage);
|
|
12
|
+
if (result != SQLITE_OK) {
|
|
13
|
+
NSLog(@"Failed to load sqlite3 extension: %@", [NSString stringWithCString:errorMessage]);
|
|
14
|
+
sqlite3_free(errorMessage);
|
|
15
|
+
errorMessage = nil;
|
|
16
|
+
}
|
|
12
17
|
return result;
|
|
13
18
|
}
|