expo-sqlite 12.0.0 → 12.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/android/build.gradle +4 -4
- package/android/src/main/cpp/NativeStatementBinding.cpp +19 -8
- package/android/src/main/cpp/NativeStatementBinding.h +2 -14
- package/android/src/main/java/expo/modules/sqlite/NativeStatementBinding.kt +4 -3
- package/android/src/main/java/expo/modules/sqlite/SQLiteModuleNext.kt +19 -12
- package/build/SQLite.d.ts +2 -2
- package/build/SQLite.d.ts.map +1 -1
- package/build/SQLite.js.map +1 -1
- package/build/SQLite.types.d.ts +3 -2
- package/build/SQLite.types.d.ts.map +1 -1
- package/build/SQLite.types.js.map +1 -1
- package/build/next/Database.d.ts.map +1 -1
- package/build/next/Database.js +2 -6
- package/build/next/Database.js.map +1 -1
- package/build/next/NativeStatement.d.ts +12 -9
- package/build/next/NativeStatement.d.ts.map +1 -1
- package/build/next/NativeStatement.js.map +1 -1
- package/build/next/Statement.d.ts +19 -1
- package/build/next/Statement.d.ts.map +1 -1
- package/build/next/Statement.js +75 -26
- package/build/next/Statement.js.map +1 -1
- package/build/next/hooks.d.ts.map +1 -1
- package/build/next/hooks.js +11 -8
- package/build/next/hooks.js.map +1 -1
- package/ios/SQLiteModuleNext.swift +52 -35
- package/package.json +2 -2
- package/src/SQLite.ts +2 -1
- package/src/SQLite.types.ts +5 -2
- package/src/next/Database.ts +2 -6
- package/src/next/NativeStatement.ts +20 -9
- package/src/next/Statement.ts +87 -24
- package/src/next/hooks.tsx +11 -8
package/CHANGELOG.md
CHANGED
|
@@ -10,12 +10,25 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 12.1.0 — 2023-11-10
|
|
14
|
+
|
|
15
|
+
### 🎉 New features
|
|
16
|
+
|
|
17
|
+
- Improved performance on the `expo-sqlite/next` API. ([#25314](https://github.com/expo/expo/pull/25314) by [@kudo](https://github.com/kudo))
|
|
18
|
+
|
|
19
|
+
### 🐛 Bug fixes
|
|
20
|
+
|
|
21
|
+
- Fix crash issues in `sqlite/next`. ([#25295](https://github.com/expo/expo/pull/25295) by [@kudo](https://github.com/kudo))
|
|
22
|
+
- Fix `executeSqlAsync` to accept null properly as arguments. ([#24761](https://github.com/expo/expo/pull/24761) by [@spencerc99](https://github.com/spencerc99))
|
|
23
|
+
- Fixed `useSQLiteContext()` and `finalizeUnusedStatementsBeforeClosing` issues in `expo-sqlite/next` API. ([#25328](https://github.com/expo/expo/pull/25328) by [@kudo](https://github.com/kudo))
|
|
24
|
+
|
|
13
25
|
## 12.0.0 — 2023-11-06
|
|
14
26
|
|
|
15
27
|
### 🛠 Breaking changes
|
|
16
28
|
|
|
17
29
|
- Bumped iOS deployment target to 13.4. ([#25063](https://github.com/expo/expo/pull/25063) by [@gabrieldonadel](https://github.com/gabrieldonadel))
|
|
18
30
|
- Remove CRSQLite support on legacy API. ([#25092](https://github.com/expo/expo/pull/25092) by [@kudo](https://github.com/kudo))
|
|
31
|
+
- On `Android` bump `compileSdkVersion` and `targetSdkVersion` to `34`. ([#24708](https://github.com/expo/expo/pull/24708) by [@alanjhughes](https://github.com/alanjhughes))
|
|
19
32
|
|
|
20
33
|
### 🎉 New features
|
|
21
34
|
|
package/android/build.gradle
CHANGED
|
@@ -4,7 +4,7 @@ apply plugin: 'maven-publish'
|
|
|
4
4
|
apply plugin: 'de.undercouch.download'
|
|
5
5
|
|
|
6
6
|
group = 'host.exp.exponent'
|
|
7
|
-
version = '12.
|
|
7
|
+
version = '12.1.0'
|
|
8
8
|
|
|
9
9
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
10
10
|
if (expoModulesCorePlugin.exists()) {
|
|
@@ -73,11 +73,11 @@ if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
|
73
73
|
android {
|
|
74
74
|
// Remove this if and it's contents, when support for SDK49 is dropped
|
|
75
75
|
if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
76
|
-
compileSdkVersion safeExtGet("compileSdkVersion",
|
|
76
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 34)
|
|
77
77
|
|
|
78
78
|
defaultConfig {
|
|
79
79
|
minSdkVersion safeExtGet("minSdkVersion", 23)
|
|
80
|
-
targetSdkVersion safeExtGet("targetSdkVersion",
|
|
80
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 34)
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
publishing {
|
|
@@ -106,7 +106,7 @@ android {
|
|
|
106
106
|
namespace "expo.modules.sqlite"
|
|
107
107
|
defaultConfig {
|
|
108
108
|
versionCode 18
|
|
109
|
-
versionName "12.
|
|
109
|
+
versionName "12.1.0"
|
|
110
110
|
|
|
111
111
|
externalNativeBuild {
|
|
112
112
|
cmake {
|
|
@@ -30,7 +30,10 @@ void NativeStatementBinding::registerNatives() {
|
|
|
30
30
|
makeNativeMethod("sqlite3_step", NativeStatementBinding::sqlite3_step),
|
|
31
31
|
makeNativeMethod("bindStatementParam",
|
|
32
32
|
NativeStatementBinding::bindStatementParam),
|
|
33
|
-
makeNativeMethod("
|
|
33
|
+
makeNativeMethod("getColumnNames",
|
|
34
|
+
NativeStatementBinding::getColumnNames),
|
|
35
|
+
makeNativeMethod("getColumnValues",
|
|
36
|
+
NativeStatementBinding::getColumnValues),
|
|
34
37
|
});
|
|
35
38
|
}
|
|
36
39
|
|
|
@@ -92,16 +95,24 @@ int NativeStatementBinding::bindStatementParam(
|
|
|
92
95
|
return ret;
|
|
93
96
|
}
|
|
94
97
|
|
|
95
|
-
jni::local_ref<
|
|
96
|
-
NativeStatementBinding::
|
|
98
|
+
jni::local_ref<jni::JArrayList<jni::JString>>
|
|
99
|
+
NativeStatementBinding::getColumnNames() {
|
|
97
100
|
int columnCount = sqlite3_column_count();
|
|
98
|
-
auto
|
|
101
|
+
auto columnNames = jni::JArrayList<jni::JString>::create(columnCount);
|
|
99
102
|
for (int i = 0; i < columnCount; ++i) {
|
|
100
|
-
|
|
101
|
-
auto value = getColumnValue(i);
|
|
102
|
-
row->put(jni::make_jstring(name), value);
|
|
103
|
+
columnNames->add(jni::make_jstring(sqlite3_column_name(i)));
|
|
103
104
|
}
|
|
104
|
-
return
|
|
105
|
+
return columnNames;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
jni::local_ref<jni::JArrayList<jni::JObject>>
|
|
109
|
+
NativeStatementBinding::getColumnValues() {
|
|
110
|
+
int columnCount = sqlite3_column_count();
|
|
111
|
+
auto columnValues = jni::JArrayList<jni::JObject>::create(columnCount);
|
|
112
|
+
for (int i = 0; i < columnCount; ++i) {
|
|
113
|
+
columnValues->add(getColumnValue(i));
|
|
114
|
+
}
|
|
115
|
+
return columnValues;
|
|
105
116
|
}
|
|
106
117
|
|
|
107
118
|
// static
|
|
@@ -13,19 +13,6 @@ namespace expo {
|
|
|
13
13
|
|
|
14
14
|
class NativeDatabaseBinding;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* A convenient wrapper for the ArrayMap
|
|
18
|
-
*/
|
|
19
|
-
template <typename K = jobject, typename V = jobject>
|
|
20
|
-
struct ArrayMap : public jni::JavaClass<ArrayMap<K, V>, jni::JMap<K, V>> {
|
|
21
|
-
static auto constexpr kJavaDescriptor = "Landroid/util/ArrayMap;";
|
|
22
|
-
|
|
23
|
-
static jni::local_ref<typename ArrayMap<K, V>::javaobject>
|
|
24
|
-
create(int capacity) {
|
|
25
|
-
return ArrayMap<K, V>::newInstance(capacity);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
16
|
class NativeStatementBinding : public jni::HybridClass<NativeStatementBinding> {
|
|
30
17
|
public:
|
|
31
18
|
static constexpr auto kJavaDescriptor =
|
|
@@ -43,7 +30,8 @@ public:
|
|
|
43
30
|
|
|
44
31
|
// helpers
|
|
45
32
|
int bindStatementParam(int index, jni::alias_ref<jni::JObject> param);
|
|
46
|
-
jni::local_ref<
|
|
33
|
+
jni::local_ref<jni::JArrayList<jni::JString>> getColumnNames();
|
|
34
|
+
jni::local_ref<jni::JArrayList<jni::JObject>> getColumnValues();
|
|
47
35
|
|
|
48
36
|
private:
|
|
49
37
|
explicit NativeStatementBinding(
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
package expo.modules.sqlite
|
|
4
4
|
|
|
5
|
-
import android.util.ArrayMap
|
|
6
5
|
import com.facebook.jni.HybridData
|
|
7
6
|
import expo.modules.core.interfaces.DoNotStrip
|
|
8
7
|
|
|
9
|
-
internal typealias
|
|
8
|
+
internal typealias ColumnNames = ArrayList<String>
|
|
9
|
+
internal typealias ColumnValues = ArrayList<Any>
|
|
10
10
|
|
|
11
11
|
@Suppress("KotlinJniMissingFunction")
|
|
12
12
|
@DoNotStrip
|
|
@@ -28,7 +28,8 @@ internal class NativeStatementBinding {
|
|
|
28
28
|
external fun sqlite3_step(): Int
|
|
29
29
|
|
|
30
30
|
external fun bindStatementParam(index: Int, param: Any): Int
|
|
31
|
-
external fun
|
|
31
|
+
external fun getColumnNames(): ColumnNames
|
|
32
|
+
external fun getColumnValues(): ColumnValues
|
|
32
33
|
|
|
33
34
|
// endregion
|
|
34
35
|
|
|
@@ -150,6 +150,13 @@ class SQLiteModuleNext : Module() {
|
|
|
150
150
|
return@Function objectGetAll(statement, database, bindParams)
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
AsyncFunction("getColumnNamesAsync") { statement: NativeStatement ->
|
|
154
|
+
return@AsyncFunction statement.ref.getColumnNames()
|
|
155
|
+
}
|
|
156
|
+
Function("getColumnNamesSync") { statement: NativeStatement ->
|
|
157
|
+
return@Function statement.ref.getColumnNames()
|
|
158
|
+
}
|
|
159
|
+
|
|
153
160
|
AsyncFunction("resetAsync") { statement: NativeStatement, database: NativeDatabase ->
|
|
154
161
|
return@AsyncFunction reset(statement, database)
|
|
155
162
|
}
|
|
@@ -231,13 +238,13 @@ class SQLiteModuleNext : Module() {
|
|
|
231
238
|
}
|
|
232
239
|
|
|
233
240
|
@Throws(InvalidConvertibleException::class, SQLiteErrorException::class)
|
|
234
|
-
private fun arrayGet(statement: NativeStatement, database: NativeDatabase, bindParams: List<Any>):
|
|
241
|
+
private fun arrayGet(statement: NativeStatement, database: NativeDatabase, bindParams: List<Any>): ColumnValues? {
|
|
235
242
|
for ((index, param) in bindParams.withIndex()) {
|
|
236
243
|
statement.ref.bindStatementParam(index + 1, param)
|
|
237
244
|
}
|
|
238
245
|
val ret = statement.ref.sqlite3_step()
|
|
239
246
|
if (ret == NativeDatabaseBinding.SQLITE_ROW) {
|
|
240
|
-
return statement.ref.
|
|
247
|
+
return statement.ref.getColumnValues()
|
|
241
248
|
}
|
|
242
249
|
if (ret != NativeDatabaseBinding.SQLITE_DONE) {
|
|
243
250
|
throw SQLiteErrorException(database.ref.convertSqlLiteErrorToString())
|
|
@@ -246,7 +253,7 @@ class SQLiteModuleNext : Module() {
|
|
|
246
253
|
}
|
|
247
254
|
|
|
248
255
|
@Throws(InvalidConvertibleException::class, SQLiteErrorException::class)
|
|
249
|
-
private fun objectGet(statement: NativeStatement, database: NativeDatabase, bindParams: Map<String, Any>):
|
|
256
|
+
private fun objectGet(statement: NativeStatement, database: NativeDatabase, bindParams: Map<String, Any>): ColumnValues? {
|
|
250
257
|
for ((name, param) in bindParams) {
|
|
251
258
|
val index = statement.ref.sqlite3_bind_parameter_index(name)
|
|
252
259
|
if (index > 0) {
|
|
@@ -255,7 +262,7 @@ class SQLiteModuleNext : Module() {
|
|
|
255
262
|
}
|
|
256
263
|
val ret = statement.ref.sqlite3_step()
|
|
257
264
|
if (ret == NativeDatabaseBinding.SQLITE_ROW) {
|
|
258
|
-
return statement.ref.
|
|
265
|
+
return statement.ref.getColumnValues()
|
|
259
266
|
}
|
|
260
267
|
if (ret != NativeDatabaseBinding.SQLITE_DONE) {
|
|
261
268
|
throw SQLiteErrorException(database.ref.convertSqlLiteErrorToString())
|
|
@@ -264,44 +271,44 @@ class SQLiteModuleNext : Module() {
|
|
|
264
271
|
}
|
|
265
272
|
|
|
266
273
|
@Throws(InvalidConvertibleException::class, SQLiteErrorException::class)
|
|
267
|
-
private fun arrayGetAll(statement: NativeStatement, database: NativeDatabase, bindParams: List<Any>): List<
|
|
274
|
+
private fun arrayGetAll(statement: NativeStatement, database: NativeDatabase, bindParams: List<Any>): List<ColumnValues> {
|
|
268
275
|
for ((index, param) in bindParams.withIndex()) {
|
|
269
276
|
statement.ref.bindStatementParam(index + 1, param)
|
|
270
277
|
}
|
|
271
|
-
val
|
|
278
|
+
val columnValuesList = mutableListOf<ColumnValues>()
|
|
272
279
|
while (true) {
|
|
273
280
|
val ret = statement.ref.sqlite3_step()
|
|
274
281
|
if (ret == NativeDatabaseBinding.SQLITE_ROW) {
|
|
275
|
-
|
|
282
|
+
columnValuesList.add(statement.ref.getColumnValues())
|
|
276
283
|
continue
|
|
277
284
|
} else if (ret == NativeDatabaseBinding.SQLITE_DONE) {
|
|
278
285
|
break
|
|
279
286
|
}
|
|
280
287
|
throw SQLiteErrorException(database.ref.convertSqlLiteErrorToString())
|
|
281
288
|
}
|
|
282
|
-
return
|
|
289
|
+
return columnValuesList
|
|
283
290
|
}
|
|
284
291
|
|
|
285
292
|
@Throws(InvalidConvertibleException::class, SQLiteErrorException::class)
|
|
286
|
-
private fun objectGetAll(statement: NativeStatement, database: NativeDatabase, bindParams: Map<String, Any>): List<
|
|
293
|
+
private fun objectGetAll(statement: NativeStatement, database: NativeDatabase, bindParams: Map<String, Any>): List<ColumnValues> {
|
|
287
294
|
for ((name, param) in bindParams) {
|
|
288
295
|
val index = statement.ref.sqlite3_bind_parameter_index(name)
|
|
289
296
|
if (index > 0) {
|
|
290
297
|
statement.ref.bindStatementParam(index, param)
|
|
291
298
|
}
|
|
292
299
|
}
|
|
293
|
-
val
|
|
300
|
+
val columnValuesList = mutableListOf<ColumnValues>()
|
|
294
301
|
while (true) {
|
|
295
302
|
val ret = statement.ref.sqlite3_step()
|
|
296
303
|
if (ret == NativeDatabaseBinding.SQLITE_ROW) {
|
|
297
|
-
|
|
304
|
+
columnValuesList.add(statement.ref.getColumnValues())
|
|
298
305
|
continue
|
|
299
306
|
} else if (ret == NativeDatabaseBinding.SQLITE_DONE) {
|
|
300
307
|
break
|
|
301
308
|
}
|
|
302
309
|
throw SQLiteErrorException(database.ref.convertSqlLiteErrorToString())
|
|
303
310
|
}
|
|
304
|
-
return
|
|
311
|
+
return columnValuesList
|
|
305
312
|
}
|
|
306
313
|
|
|
307
314
|
@Throws(SQLiteErrorException::class)
|
package/build/SQLite.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import './polyfillNextTick';
|
|
2
|
-
import type { Query, ResultSet, ResultSetError, SQLiteCallback, SQLTransactionAsyncCallback, SQLTransactionAsync, SQLTransactionCallback, SQLTransactionErrorCallback } from './SQLite.types';
|
|
2
|
+
import type { Query, ResultSet, ResultSetError, SQLiteCallback, SQLStatementArg, SQLTransactionAsyncCallback, SQLTransactionAsync, SQLTransactionCallback, SQLTransactionErrorCallback } from './SQLite.types';
|
|
3
3
|
/** The database returned by `openDatabase()` */
|
|
4
4
|
export declare class SQLiteDatabase {
|
|
5
5
|
_name: string;
|
|
@@ -84,6 +84,6 @@ export declare class ExpoSQLTransactionAsync implements SQLTransactionAsync {
|
|
|
84
84
|
private readonly db;
|
|
85
85
|
private readonly readOnly;
|
|
86
86
|
constructor(db: SQLiteDatabase, readOnly: boolean);
|
|
87
|
-
executeSqlAsync(sqlStatement: string, args?:
|
|
87
|
+
executeSqlAsync(sqlStatement: string, args?: SQLStatementArg[]): Promise<ResultSet>;
|
|
88
88
|
}
|
|
89
89
|
//# sourceMappingURL=SQLite.d.ts.map
|
package/build/SQLite.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SQLite.d.ts","sourceRoot":"","sources":["../src/SQLite.ts"],"names":[],"mappings":"AAAA,O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I,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAC3D,EAAE,CAAC,WAAW,GAAG,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACjD,EAAE,CAAC,gBAAgB,GAAG,EAAE,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAC3D,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAEf;IACA;IAFnB,YACmB,EAAkB,EAClB,QAAiB;QADjB,OAAE,GAAF,EAAE,CAAgB;QAClB,aAAQ,GAAR,QAAQ,CAAS;IACjC,CAAC;IAEJ,KAAK,CAAC,eAAe,CAAC,YAAoB,EAAE,IAA0B;QACpE,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,SAAS,CACxC,CAAC,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,EACzC,IAAI,CAAC,QAAQ,CACd,CAAC;QACF,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,gBAAgB,CAAC,MAAM,CAAC,EAAE;YAC5B,MAAM,MAAM,CAAC,KAAK,CAAC;SACpB;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,SAAS,gBAAgB,CAAC,MAAkC;IAC1D,OAAO,OAAO,IAAI,MAAM,CAAC;AAC3B,CAAC","sourcesContent":["import './polyfillNextTick';\n\nimport customOpenDatabase from '@expo/websql/custom';\nimport { requireNativeModule, EventEmitter } from 'expo-modules-core';\nimport { Platform } from 'react-native';\n\nimport type {\n Query,\n ResultSet,\n ResultSetError,\n SQLiteCallback,\n SQLTransactionAsyncCallback,\n SQLTransactionAsync,\n SQLTransactionCallback,\n SQLTransactionErrorCallback,\n} from './SQLite.types';\n\nconst ExpoSQLite = requireNativeModule('ExpoSQLite');\nconst emitter = new EventEmitter(ExpoSQLite);\n\nfunction zipObject(keys: string[], values: any[]) {\n const result = {};\n for (let i = 0; i < keys.length; i++) {\n result[keys[i]] = values[i];\n }\n return result;\n}\n\n/** The database returned by `openDatabase()` */\nexport class SQLiteDatabase {\n _name: string;\n _closed: boolean = false;\n\n constructor(name: string) {\n this._name = name;\n }\n\n /**\n * Executes the SQL statement and returns a callback resolving with the result.\n */\n exec(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void {\n if (this._closed) {\n throw new Error(`The SQLite database is closed`);\n }\n\n ExpoSQLite.exec(this._name, queries.map(_serializeQuery), readOnly).then(\n (nativeResultSets) => {\n callback(null, nativeResultSets.map(_deserializeResultSet));\n },\n (error) => {\n // TODO: make the native API consistently reject with an error, not a string or other type\n callback(error instanceof Error ? error : new Error(error));\n }\n );\n }\n\n /**\n * Due to limitations on `Android` this function is provided to allow raw SQL queries to be\n * executed on the database. This will be less efficient than using the `exec` function, please use\n * only when necessary.\n */\n execRawQuery(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void {\n if (Platform.OS === 'ios') {\n return this.exec(queries, readOnly, callback);\n }\n\n ExpoSQLite.execRawQuery(this._name, queries.map(_serializeQuery), readOnly).then(\n (nativeResultSets) => {\n callback(null, nativeResultSets.map(_deserializeResultSet));\n },\n (error) => {\n callback(error instanceof Error ? error : new Error(error));\n }\n );\n }\n\n /**\n * Executes the SQL statement and returns a Promise resolving with the result.\n */\n async execAsync(queries: Query[], readOnly: boolean): Promise<(ResultSetError | ResultSet)[]> {\n if (this._closed) {\n throw new Error(`The SQLite database is closed`);\n }\n\n const nativeResultSets = await ExpoSQLite.exec(\n this._name,\n queries.map(_serializeQuery),\n readOnly\n );\n return nativeResultSets.map(_deserializeResultSet);\n }\n\n /**\n * @deprecated Use `closeAsync()` instead.\n */\n close = this.closeAsync;\n\n /**\n * Close the database.\n */\n closeAsync(): Promise<void> {\n this._closed = true;\n return ExpoSQLite.close(this._name);\n }\n\n /**\n * Synchronously closes the database.\n */\n closeSync(): void {\n this._closed = true;\n return ExpoSQLite.closeSync(this._name);\n }\n\n /**\n * Delete the database file.\n * > The database has to be closed prior to deletion.\n */\n deleteAsync(): Promise<void> {\n if (!this._closed) {\n throw new Error(\n `Unable to delete '${this._name}' database that is currently open. Close it prior to deletion.`\n );\n }\n\n return ExpoSQLite.deleteAsync(this._name);\n }\n\n /**\n * Used to listen to changes in the database.\n * @param callback A function that receives the `tableName` and `rowId` of the modified data.\n */\n onDatabaseChange(cb: (result: { tableName: string; rowId: number }) => void) {\n return emitter.addListener('onDatabaseChange', cb);\n }\n\n /**\n * Creates a new transaction with Promise support.\n * @param asyncCallback A `SQLTransactionAsyncCallback` function that can perform SQL statements in a transaction.\n * @param readOnly true if all the SQL statements in the callback are read only.\n */\n async transactionAsync(\n asyncCallback: SQLTransactionAsyncCallback,\n readOnly: boolean = false\n ): Promise<void> {\n await this.execAsync([{ sql: 'BEGIN;', args: [] }], false);\n try {\n const transaction = new ExpoSQLTransactionAsync(this, readOnly);\n await asyncCallback(transaction);\n await this.execAsync([{ sql: 'END;', args: [] }], false);\n } catch (e: unknown) {\n await this.execAsync([{ sql: 'ROLLBACK;', args: [] }], false);\n throw e;\n }\n }\n\n // @ts-expect-error: properties that are added from websql\n version: string;\n\n /**\n * Execute a database transaction.\n * @param callback A function representing the transaction to perform. Takes a Transaction\n * (see below) as its only parameter, on which it can add SQL statements to execute.\n * @param errorCallback Called if an error occurred processing this transaction. Takes a single\n * parameter describing the error.\n * @param successCallback Called when the transaction has completed executing on the database.\n */\n // @ts-expect-error: properties that are added from websql\n transaction(\n callback: SQLTransactionCallback,\n errorCallback?: SQLTransactionErrorCallback,\n successCallback?: () => void\n ): void;\n\n // @ts-expect-error: properties that are added from websql\n readTransaction(\n callback: SQLTransactionCallback,\n errorCallback?: SQLTransactionErrorCallback,\n successCallback?: () => void\n ): void;\n}\n\nfunction _serializeQuery(query: Query): Query | [string, any[]] {\n return Platform.OS === 'android'\n ? {\n sql: query.sql,\n args: query.args.map(_escapeBlob),\n }\n : [query.sql, query.args];\n}\n\nfunction _deserializeResultSet(nativeResult): ResultSet | ResultSetError {\n const [errorMessage, insertId, rowsAffected, columns, rows] = nativeResult;\n // TODO: send more structured error information from the native module so we can better construct\n // a SQLException object\n if (errorMessage !== null) {\n return { error: new Error(errorMessage) } as ResultSetError;\n }\n\n return {\n insertId,\n rowsAffected,\n rows: rows.map((row) => zipObject(columns, row)),\n };\n}\n\nfunction _escapeBlob<T>(data: T): T {\n if (typeof data === 'string') {\n /* eslint-disable no-control-regex */\n return data\n .replace(/\\u0002/g, '\\u0002\\u0002')\n .replace(/\\u0001/g, '\\u0001\\u0002')\n .replace(/\\u0000/g, '\\u0001\\u0001') as any;\n /* eslint-enable no-control-regex */\n } else {\n return data;\n }\n}\n\nconst _openExpoSQLiteDatabase = customOpenDatabase(SQLiteDatabase);\n\n// @needsAudit @docsMissing\n/**\n * Open a database, creating it if it doesn't exist, and return a `Database` object. On disk,\n * the database will be created under the app's [documents directory](./filesystem), i.e.\n * `${FileSystem.documentDirectory}/SQLite/${name}`.\n * > The `version`, `description` and `size` arguments are ignored, but are accepted by the function\n * for compatibility with the WebSQL specification.\n * @param name Name of the database file to open.\n * @param version\n * @param description\n * @param size\n * @param callback\n * @return\n */\nexport function openDatabase(\n name: string,\n version: string = '1.0',\n description: string = name,\n size: number = 1,\n callback?: (db: SQLiteDatabase) => void\n): SQLiteDatabase {\n if (name === undefined) {\n throw new TypeError(`The database name must not be undefined`);\n }\n const db = _openExpoSQLiteDatabase(name, version, description, size, callback);\n db.exec = db._db.exec.bind(db._db);\n db.execRawQuery = db._db.execRawQuery.bind(db._db);\n db.execAsync = db._db.execAsync.bind(db._db);\n db.closeAsync = db._db.closeAsync.bind(db._db);\n db.closeSync = db._db.closeSync.bind(db._db);\n db.onDatabaseChange = db._db.onDatabaseChange.bind(db._db);\n db.deleteAsync = db._db.deleteAsync.bind(db._db);\n db.transactionAsync = db._db.transactionAsync.bind(db._db);\n return db;\n}\n\n/**\n * Internal data structure for the async transaction API.\n * @internal\n */\nexport class ExpoSQLTransactionAsync implements SQLTransactionAsync {\n constructor(\n private readonly db: SQLiteDatabase,\n private readonly readOnly: boolean\n ) {}\n\n async executeSqlAsync(sqlStatement: string, args?: (number | string)[]): Promise<ResultSet> {\n const resultSets = await this.db.execAsync(\n [{ sql: sqlStatement, args: args ?? [] }],\n this.readOnly\n );\n const result = resultSets[0];\n if (isResultSetError(result)) {\n throw result.error;\n }\n return result;\n }\n}\n\nfunction isResultSetError(result: ResultSet | ResultSetError): result is ResultSetError {\n return 'error' in result;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SQLite.js","sourceRoot":"","sources":["../src/SQLite.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAE5B,OAAO,kBAAkB,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAcxC,MAAM,UAAU,GAAG,mBAAmB,CAAC,YAAY,CAAC,CAAC;AACrD,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,UAAU,CAAC,CAAC;AAE7C,SAAS,SAAS,CAAC,IAAc,EAAE,MAAa;IAC9C,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACpC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;KAC7B;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,gDAAgD;AAChD,MAAM,OAAO,cAAc;IACzB,KAAK,CAAS;IACd,OAAO,GAAY,KAAK,CAAC;IAEzB,YAAY,IAAY;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;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SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAC7C,EAAE,CAAC,gBAAgB,GAAG,EAAE,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAC3D,EAAE,CAAC,WAAW,GAAG,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACjD,EAAE,CAAC,gBAAgB,GAAG,EAAE,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAC3D,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAEf;IACA;IAFnB,YACmB,EAAkB,EAClB,QAAiB;QADjB,OAAE,GAAF,EAAE,CAAgB;QAClB,aAAQ,GAAR,QAAQ,CAAS;IACjC,CAAC;IAEJ,KAAK,CAAC,eAAe,CAAC,YAAoB,EAAE,IAAwB;QAClE,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,SAAS,CACxC,CAAC,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,EACzC,IAAI,CAAC,QAAQ,CACd,CAAC;QACF,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,gBAAgB,CAAC,MAAM,CAAC,EAAE;YAC5B,MAAM,MAAM,CAAC,KAAK,CAAC;SACpB;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,SAAS,gBAAgB,CAAC,MAAkC;IAC1D,OAAO,OAAO,IAAI,MAAM,CAAC;AAC3B,CAAC","sourcesContent":["import './polyfillNextTick';\n\nimport customOpenDatabase from '@expo/websql/custom';\nimport { requireNativeModule, EventEmitter } from 'expo-modules-core';\nimport { Platform } from 'react-native';\n\nimport type {\n Query,\n ResultSet,\n ResultSetError,\n SQLiteCallback,\n SQLStatementArg,\n SQLTransactionAsyncCallback,\n SQLTransactionAsync,\n SQLTransactionCallback,\n SQLTransactionErrorCallback,\n} from './SQLite.types';\n\nconst ExpoSQLite = requireNativeModule('ExpoSQLite');\nconst emitter = new EventEmitter(ExpoSQLite);\n\nfunction zipObject(keys: string[], values: any[]) {\n const result = {};\n for (let i = 0; i < keys.length; i++) {\n result[keys[i]] = values[i];\n }\n return result;\n}\n\n/** The database returned by `openDatabase()` */\nexport class SQLiteDatabase {\n _name: string;\n _closed: boolean = false;\n\n constructor(name: string) {\n this._name = name;\n }\n\n /**\n * Executes the SQL statement and returns a callback resolving with the result.\n */\n exec(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void {\n if (this._closed) {\n throw new Error(`The SQLite database is closed`);\n }\n\n ExpoSQLite.exec(this._name, queries.map(_serializeQuery), readOnly).then(\n (nativeResultSets) => {\n callback(null, nativeResultSets.map(_deserializeResultSet));\n },\n (error) => {\n // TODO: make the native API consistently reject with an error, not a string or other type\n callback(error instanceof Error ? error : new Error(error));\n }\n );\n }\n\n /**\n * Due to limitations on `Android` this function is provided to allow raw SQL queries to be\n * executed on the database. This will be less efficient than using the `exec` function, please use\n * only when necessary.\n */\n execRawQuery(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void {\n if (Platform.OS === 'ios') {\n return this.exec(queries, readOnly, callback);\n }\n\n ExpoSQLite.execRawQuery(this._name, queries.map(_serializeQuery), readOnly).then(\n (nativeResultSets) => {\n callback(null, nativeResultSets.map(_deserializeResultSet));\n },\n (error) => {\n callback(error instanceof Error ? error : new Error(error));\n }\n );\n }\n\n /**\n * Executes the SQL statement and returns a Promise resolving with the result.\n */\n async execAsync(queries: Query[], readOnly: boolean): Promise<(ResultSetError | ResultSet)[]> {\n if (this._closed) {\n throw new Error(`The SQLite database is closed`);\n }\n\n const nativeResultSets = await ExpoSQLite.exec(\n this._name,\n queries.map(_serializeQuery),\n readOnly\n );\n return nativeResultSets.map(_deserializeResultSet);\n }\n\n /**\n * @deprecated Use `closeAsync()` instead.\n */\n close = this.closeAsync;\n\n /**\n * Close the database.\n */\n closeAsync(): Promise<void> {\n this._closed = true;\n return ExpoSQLite.close(this._name);\n }\n\n /**\n * Synchronously closes the database.\n */\n closeSync(): void {\n this._closed = true;\n return ExpoSQLite.closeSync(this._name);\n }\n\n /**\n * Delete the database file.\n * > The database has to be closed prior to deletion.\n */\n deleteAsync(): Promise<void> {\n if (!this._closed) {\n throw new Error(\n `Unable to delete '${this._name}' database that is currently open. Close it prior to deletion.`\n );\n }\n\n return ExpoSQLite.deleteAsync(this._name);\n }\n\n /**\n * Used to listen to changes in the database.\n * @param callback A function that receives the `tableName` and `rowId` of the modified data.\n */\n onDatabaseChange(cb: (result: { tableName: string; rowId: number }) => void) {\n return emitter.addListener('onDatabaseChange', cb);\n }\n\n /**\n * Creates a new transaction with Promise support.\n * @param asyncCallback A `SQLTransactionAsyncCallback` function that can perform SQL statements in a transaction.\n * @param readOnly true if all the SQL statements in the callback are read only.\n */\n async transactionAsync(\n asyncCallback: SQLTransactionAsyncCallback,\n readOnly: boolean = false\n ): Promise<void> {\n await this.execAsync([{ sql: 'BEGIN;', args: [] }], false);\n try {\n const transaction = new ExpoSQLTransactionAsync(this, readOnly);\n await asyncCallback(transaction);\n await this.execAsync([{ sql: 'END;', args: [] }], false);\n } catch (e: unknown) {\n await this.execAsync([{ sql: 'ROLLBACK;', args: [] }], false);\n throw e;\n }\n }\n\n // @ts-expect-error: properties that are added from websql\n version: string;\n\n /**\n * Execute a database transaction.\n * @param callback A function representing the transaction to perform. Takes a Transaction\n * (see below) as its only parameter, on which it can add SQL statements to execute.\n * @param errorCallback Called if an error occurred processing this transaction. Takes a single\n * parameter describing the error.\n * @param successCallback Called when the transaction has completed executing on the database.\n */\n // @ts-expect-error: properties that are added from websql\n transaction(\n callback: SQLTransactionCallback,\n errorCallback?: SQLTransactionErrorCallback,\n successCallback?: () => void\n ): void;\n\n // @ts-expect-error: properties that are added from websql\n readTransaction(\n callback: SQLTransactionCallback,\n errorCallback?: SQLTransactionErrorCallback,\n successCallback?: () => void\n ): void;\n}\n\nfunction _serializeQuery(query: Query): Query | [string, any[]] {\n return Platform.OS === 'android'\n ? {\n sql: query.sql,\n args: query.args.map(_escapeBlob),\n }\n : [query.sql, query.args];\n}\n\nfunction _deserializeResultSet(nativeResult): ResultSet | ResultSetError {\n const [errorMessage, insertId, rowsAffected, columns, rows] = nativeResult;\n // TODO: send more structured error information from the native module so we can better construct\n // a SQLException object\n if (errorMessage !== null) {\n return { error: new Error(errorMessage) } as ResultSetError;\n }\n\n return {\n insertId,\n rowsAffected,\n rows: rows.map((row) => zipObject(columns, row)),\n };\n}\n\nfunction _escapeBlob<T>(data: T): T {\n if (typeof data === 'string') {\n /* eslint-disable no-control-regex */\n return data\n .replace(/\\u0002/g, '\\u0002\\u0002')\n .replace(/\\u0001/g, '\\u0001\\u0002')\n .replace(/\\u0000/g, '\\u0001\\u0001') as any;\n /* eslint-enable no-control-regex */\n } else {\n return data;\n }\n}\n\nconst _openExpoSQLiteDatabase = customOpenDatabase(SQLiteDatabase);\n\n// @needsAudit @docsMissing\n/**\n * Open a database, creating it if it doesn't exist, and return a `Database` object. On disk,\n * the database will be created under the app's [documents directory](./filesystem), i.e.\n * `${FileSystem.documentDirectory}/SQLite/${name}`.\n * > The `version`, `description` and `size` arguments are ignored, but are accepted by the function\n * for compatibility with the WebSQL specification.\n * @param name Name of the database file to open.\n * @param version\n * @param description\n * @param size\n * @param callback\n * @return\n */\nexport function openDatabase(\n name: string,\n version: string = '1.0',\n description: string = name,\n size: number = 1,\n callback?: (db: SQLiteDatabase) => void\n): SQLiteDatabase {\n if (name === undefined) {\n throw new TypeError(`The database name must not be undefined`);\n }\n const db = _openExpoSQLiteDatabase(name, version, description, size, callback);\n db.exec = db._db.exec.bind(db._db);\n db.execRawQuery = db._db.execRawQuery.bind(db._db);\n db.execAsync = db._db.execAsync.bind(db._db);\n db.closeAsync = db._db.closeAsync.bind(db._db);\n db.closeSync = db._db.closeSync.bind(db._db);\n db.onDatabaseChange = db._db.onDatabaseChange.bind(db._db);\n db.deleteAsync = db._db.deleteAsync.bind(db._db);\n db.transactionAsync = db._db.transactionAsync.bind(db._db);\n return db;\n}\n\n/**\n * Internal data structure for the async transaction API.\n * @internal\n */\nexport class ExpoSQLTransactionAsync implements SQLTransactionAsync {\n constructor(\n private readonly db: SQLiteDatabase,\n private readonly readOnly: boolean\n ) {}\n\n async executeSqlAsync(sqlStatement: string, args?: SQLStatementArg[]): Promise<ResultSet> {\n const resultSets = await this.db.execAsync(\n [{ sql: sqlStatement, args: args ?? [] }],\n this.readOnly\n );\n const result = resultSets[0];\n if (isResultSetError(result)) {\n throw result.error;\n }\n return result;\n }\n}\n\nfunction isResultSetError(result: ResultSet | ResultSetError): result is ResultSetError {\n return 'error' in result;\n}\n"]}
|
package/build/SQLite.types.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export interface Database {
|
|
|
21
21
|
}
|
|
22
22
|
export type SQLTransactionCallback = (transaction: SQLTransaction) => void;
|
|
23
23
|
export type SQLTransactionErrorCallback = (error: SQLError) => void;
|
|
24
|
+
export type SQLStatementArg = string | number | null;
|
|
24
25
|
/**
|
|
25
26
|
* A `SQLTransaction` object is passed in as a parameter to the `callback` parameter for the
|
|
26
27
|
* `db.transaction()` method on a `Database` (see above). It allows enqueuing SQL statements to
|
|
@@ -41,7 +42,7 @@ export interface SQLTransaction {
|
|
|
41
42
|
* @param errorCallback Called if an error occurred executing this particular query in the
|
|
42
43
|
* transaction. Takes two parameters: the transaction itself, and the error object.
|
|
43
44
|
*/
|
|
44
|
-
executeSql(sqlStatement: string, args?:
|
|
45
|
+
executeSql(sqlStatement: string, args?: SQLStatementArg[], callback?: SQLStatementCallback, errorCallback?: SQLStatementErrorCallback): void;
|
|
45
46
|
}
|
|
46
47
|
export type SQLStatementCallback = (transaction: SQLTransaction, resultSet: SQLResultSet) => void;
|
|
47
48
|
export type SQLStatementErrorCallback = (transaction: SQLTransaction, error: SQLError) => boolean;
|
|
@@ -125,7 +126,7 @@ export type SQLiteCallback = (error?: Error | null, resultSet?: (ResultSetError
|
|
|
125
126
|
/** A transaction object to perform SQL statements in async mode. */
|
|
126
127
|
export interface SQLTransactionAsync {
|
|
127
128
|
/** Executes a SQL statement in async mode. */
|
|
128
|
-
executeSqlAsync(sqlStatement: string, args?:
|
|
129
|
+
executeSqlAsync(sqlStatement: string, args?: SQLStatementArg[]): Promise<ResultSet>;
|
|
129
130
|
}
|
|
130
131
|
/** A transaction callback with given `SQLTransactionAsync` object to perform SQL statements in async mode. */
|
|
131
132
|
export type SQLTransactionAsyncCallback = (transaction: SQLTransactionAsync) => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SQLite.types.d.ts","sourceRoot":"","sources":["../src/SQLite.types.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,MAAM;IACrB,YAAY,CAAC,EAAE,CACb,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,gBAAgB,CAAC,EAAE,gBAAgB,KAChC,QAAQ,CAAC;CACf;AAGD,MAAM,MAAM,gBAAgB,GAAG,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;AAG5D;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;;OAOG;IACH,WAAW,CACT,QAAQ,EAAE,sBAAsB,EAChC,aAAa,CAAC,EAAE,2BAA2B,EAC3C,eAAe,CAAC,EAAE,MAAM,IAAI,GAC3B,IAAI,CAAC;IAER,eAAe,CACb,QAAQ,EAAE,sBAAsB,EAChC,aAAa,CAAC,EAAE,2BAA2B,EAC3C,eAAe,CAAC,EAAE,MAAM,IAAI,GAC3B,IAAI,CAAC;CACT;AAGD,MAAM,MAAM,sBAAsB,GAAG,CAAC,WAAW,EAAE,cAAc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AE,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,GAAG,IAAI,CAAC;IAE1E;;OAEG;IACH,UAAU,IAAI,IAAI,CAAC;IAEnB;;;OAGG;IACH,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAGD,MAAM,MAAM,KAAK,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC;AAGrD,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,KAAK,CAAC;CACd;AAGD;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE;QAAE,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,EAAE,CAAC;CACnC;AAGD,MAAM,MAAM,cAAc,GAAG,CAC3B,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,EACpB,SAAS,CAAC,EAAE,CAAC,cAAc,GAAG,SAAS,CAAC,EAAE,KACvC,IAAI,CAAC;AAEV,oEAAoE;AACpE,MAAM,WAAW,mBAAmB;IAClC,8CAA8C;IAC9C,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CACrF;AAED,8GAA8G;AAC9G,MAAM,MAAM,2BAA2B,GAAG,CAAC,WAAW,EAAE,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SQLite.types.js","sourceRoot":"","sources":["../src/SQLite.types.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,8CAA8C;AAC9C,gDAAgD;AAChD,2DAA2D;AAC3D,EAAE;AACF,0EAA0E","sourcesContent":["// Definitions copied from `@types/websql` as we want\n// to expose a custom version of the API that:\n// - uses primitive `string` instead of `String`\n// - excludes some methods that are not exposed by our API.\n//\n// Original definitions by: TeamworkGuy2 <https://github.com/TeamworkGuy2>\n\n// @docsMissing\nexport interface Window {\n openDatabase?: (\n name: string,\n version: string,\n displayName: string,\n estimatedSize: number,\n creationCallback?: DatabaseCallback\n ) => Database;\n}\n\n// @docsMissing\nexport type DatabaseCallback = (database: Database) => void;\n\n// @needsAudit @docsMissing\n/**\n * `Database` objects are returned by calls to `SQLite.openDatabase()`. Such an object represents a\n * connection to a database on your device.\n */\nexport interface Database {\n version: string;\n\n /**\n * Execute a database transaction.\n * @param callback A function representing the transaction to perform. Takes a Transaction\n * (see below) as its only parameter, on which it can add SQL statements to execute.\n * @param errorCallback Called if an error occurred processing this transaction. Takes a single\n * parameter describing the error.\n * @param successCallback Called when the transaction has completed executing on the database.\n */\n transaction(\n callback: SQLTransactionCallback,\n errorCallback?: SQLTransactionErrorCallback,\n successCallback?: () => void\n ): void;\n\n readTransaction(\n callback: SQLTransactionCallback,\n errorCallback?: SQLTransactionErrorCallback,\n successCallback?: () => void\n ): void;\n}\n\n// @docsMissing\nexport type SQLTransactionCallback = (transaction: SQLTransaction) => void;\n\n// @docsMissing\nexport type SQLTransactionErrorCallback = (error: SQLError) => void;\n\n// @needsAudit\n/**\n * A `SQLTransaction` object is passed in as a parameter to the `callback` parameter for the\n * `db.transaction()` method on a `Database` (see above). It allows enqueuing SQL statements to\n * perform in a database transaction.\n */\nexport interface SQLTransaction {\n /**\n * Enqueue a SQL statement to execute in the transaction. Authors are strongly recommended to make\n * use of the `?` placeholder feature of the method to avoid against SQL injection attacks, and to\n * never construct SQL statements on the fly.\n * @param sqlStatement A string containing a database query to execute expressed as SQL. The string\n * may contain `?` placeholders, with values to be substituted listed in the `arguments` parameter.\n * @param args An array of values (numbers, strings or nulls) to substitute for `?` placeholders in the\n * SQL statement.\n * @param callback Called when the query is successfully completed during the transaction. Takes\n * two parameters: the transaction itself, and a `ResultSet` object (see below) with the results\n * of the query.\n * @param errorCallback Called if an error occurred executing this particular query in the\n * transaction. Takes two parameters: the transaction itself, and the error object.\n */\n executeSql(\n sqlStatement: string,\n args?:
|
|
1
|
+
{"version":3,"file":"SQLite.types.js","sourceRoot":"","sources":["../src/SQLite.types.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,8CAA8C;AAC9C,gDAAgD;AAChD,2DAA2D;AAC3D,EAAE;AACF,0EAA0E","sourcesContent":["// Definitions copied from `@types/websql` as we want\n// to expose a custom version of the API that:\n// - uses primitive `string` instead of `String`\n// - excludes some methods that are not exposed by our API.\n//\n// Original definitions by: TeamworkGuy2 <https://github.com/TeamworkGuy2>\n\n// @docsMissing\nexport interface Window {\n openDatabase?: (\n name: string,\n version: string,\n displayName: string,\n estimatedSize: number,\n creationCallback?: DatabaseCallback\n ) => Database;\n}\n\n// @docsMissing\nexport type DatabaseCallback = (database: Database) => void;\n\n// @needsAudit @docsMissing\n/**\n * `Database` objects are returned by calls to `SQLite.openDatabase()`. Such an object represents a\n * connection to a database on your device.\n */\nexport interface Database {\n version: string;\n\n /**\n * Execute a database transaction.\n * @param callback A function representing the transaction to perform. Takes a Transaction\n * (see below) as its only parameter, on which it can add SQL statements to execute.\n * @param errorCallback Called if an error occurred processing this transaction. Takes a single\n * parameter describing the error.\n * @param successCallback Called when the transaction has completed executing on the database.\n */\n transaction(\n callback: SQLTransactionCallback,\n errorCallback?: SQLTransactionErrorCallback,\n successCallback?: () => void\n ): void;\n\n readTransaction(\n callback: SQLTransactionCallback,\n errorCallback?: SQLTransactionErrorCallback,\n successCallback?: () => void\n ): void;\n}\n\n// @docsMissing\nexport type SQLTransactionCallback = (transaction: SQLTransaction) => void;\n\n// @docsMissing\nexport type SQLTransactionErrorCallback = (error: SQLError) => void;\n\n// @docsMissing\nexport type SQLStatementArg = string | number | null;\n\n// @needsAudit\n/**\n * A `SQLTransaction` object is passed in as a parameter to the `callback` parameter for the\n * `db.transaction()` method on a `Database` (see above). It allows enqueuing SQL statements to\n * perform in a database transaction.\n */\nexport interface SQLTransaction {\n /**\n * Enqueue a SQL statement to execute in the transaction. Authors are strongly recommended to make\n * use of the `?` placeholder feature of the method to avoid against SQL injection attacks, and to\n * never construct SQL statements on the fly.\n * @param sqlStatement A string containing a database query to execute expressed as SQL. The string\n * may contain `?` placeholders, with values to be substituted listed in the `arguments` parameter.\n * @param args An array of values (numbers, strings or nulls) to substitute for `?` placeholders in the\n * SQL statement.\n * @param callback Called when the query is successfully completed during the transaction. Takes\n * two parameters: the transaction itself, and a `ResultSet` object (see below) with the results\n * of the query.\n * @param errorCallback Called if an error occurred executing this particular query in the\n * transaction. Takes two parameters: the transaction itself, and the error object.\n */\n executeSql(\n sqlStatement: string,\n args?: SQLStatementArg[],\n callback?: SQLStatementCallback,\n errorCallback?: SQLStatementErrorCallback\n ): void;\n}\n\n// @docsMissing\nexport type SQLStatementCallback = (transaction: SQLTransaction, resultSet: SQLResultSet) => void;\n\n// @docsMissing\nexport type SQLStatementErrorCallback = (transaction: SQLTransaction, error: SQLError) => boolean;\n\n// @needsAudit\nexport type SQLResultSet = {\n /**\n * The row ID of the row that the SQL statement inserted into the database, if a row was inserted.\n */\n insertId?: number;\n /**\n * The number of rows that were changed by the SQL statement.\n */\n rowsAffected: number;\n rows: SQLResultSetRowList;\n};\n\n// @needsAudit\nexport interface SQLResultSetRowList {\n /**\n * The number of rows returned by the query.\n */\n length: number;\n /**\n * Returns the row with the given `index`. If there is no such row, returns `null`.\n * @param index Index of row to get.\n */\n item(index: number): any;\n /**\n * The actual array of rows returned by the query. Can be used directly instead of\n * getting rows through rows.item().\n */\n _array: any[];\n}\n\n// @docsMissing\nexport declare class SQLError {\n static UNKNOWN_ERR: number;\n static DATABASE_ERR: number;\n static VERSION_ERR: number;\n static TOO_LARGE_ERR: number;\n static QUOTA_ERR: number;\n static SYNTAX_ERR: number;\n static CONSTRAINT_ERR: number;\n static TIMEOUT_ERR: number;\n\n code: number;\n message: string;\n}\n\n/** @deprecated Use `SQLiteDatabase` instead. */\nexport interface WebSQLDatabase extends Database {\n exec(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void;\n\n /**\n * Close the database.\n */\n closeAsync(): void;\n\n /**\n * Delete the database file.\n * > The database has to be closed prior to deletion.\n */\n deleteAsync(): Promise<void>;\n}\n\n// @docsMissing\nexport type Query = { sql: string; args: unknown[] };\n\n// @docsMissing\nexport interface ResultSetError {\n error: Error;\n}\n\n// @needsAudit\n/**\n * `ResultSet` objects are returned through second parameter of the `success` callback for the\n * `tx.executeSql()` method on a `SQLTransaction` (see above).\n */\nexport interface ResultSet {\n /**\n * The row ID of the row that the SQL statement inserted into the database, if a row was inserted.\n */\n insertId?: number;\n /**\n * The number of rows that were changed by the SQL statement.\n */\n rowsAffected: number;\n rows: { [column: string]: any }[];\n}\n\n// @docsMissing\nexport type SQLiteCallback = (\n error?: Error | null,\n resultSet?: (ResultSetError | ResultSet)[]\n) => void;\n\n/** A transaction object to perform SQL statements in async mode. */\nexport interface SQLTransactionAsync {\n /** Executes a SQL statement in async mode. */\n executeSqlAsync(sqlStatement: string, args?: SQLStatementArg[]): Promise<ResultSet>;\n}\n\n/** A transaction callback with given `SQLTransactionAsync` object to perform SQL statements in async mode. */\nexport type SQLTransactionAsyncCallback = (transaction: SQLTransactionAsync) => Promise<void>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Database.d.ts","sourceRoot":"","sources":["../../src/next/Database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAG/D,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEnF,OAAO,EAAE,WAAW,EAAE,CAAC;AAIvB;;GAEG;AACH,qBAAa,QAAQ;aAED,MAAM,EAAE,MAA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,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,QAAQ,CAIhF;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAEvD;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,CAAC,KAAK,EAAE;IAChB,+HAA+H;IAC/H,MAAM,EAAE,MAAM,CAAC;IAEf,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAC;IAEnB,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC;IAElB,0BAA0B;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf,KAAK,IAAI,GACT,YAAY,CAEd;AAED;;GAEG;AACH,cAAM,WAAY,SAAQ,QAAQ;WACZ,WAAW,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC;CAKpE"}
|
package/build/next/Database.js
CHANGED
|
@@ -192,14 +192,12 @@ export class Database {
|
|
|
192
192
|
}
|
|
193
193
|
async *eachAsync(source, ...params) {
|
|
194
194
|
const statement = await this.prepareAsync(source);
|
|
195
|
-
let result;
|
|
196
195
|
try {
|
|
197
|
-
|
|
196
|
+
yield* await statement.eachAsync(...params);
|
|
198
197
|
}
|
|
199
198
|
finally {
|
|
200
199
|
await statement.finalizeAsync();
|
|
201
200
|
}
|
|
202
|
-
yield* result;
|
|
203
201
|
}
|
|
204
202
|
async allAsync(source, ...params) {
|
|
205
203
|
const statement = await this.prepareAsync(source);
|
|
@@ -236,14 +234,12 @@ export class Database {
|
|
|
236
234
|
}
|
|
237
235
|
*eachSync(source, ...params) {
|
|
238
236
|
const statement = this.prepareSync(source);
|
|
239
|
-
let result;
|
|
240
237
|
try {
|
|
241
|
-
|
|
238
|
+
yield* statement.eachSync(...params);
|
|
242
239
|
}
|
|
243
240
|
finally {
|
|
244
241
|
statement.finalizeSync();
|
|
245
242
|
}
|
|
246
|
-
yield* result;
|
|
247
243
|
}
|
|
248
244
|
allSync(source, ...params) {
|
|
249
245
|
const statement = this.prepareSync(source);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Database.js","sourceRoot":"","sources":["../../src/next/Database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,MAAM,mBAAmB,CAAC;AAE/D,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAyB,SAAS,EAAsB,MAAM,aAAa,CAAC;AAInF,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,UAAU,CAAC,CAAC;AAE7C;;GAEG;AACH,MAAM,OAAO,QAAQ;IAED;IACC;IAFnB,YACkB,MAAc,EACb,cAA8B;QAD/B,WAAM,GAAN,MAAM,CAAQ;QACb,mBAAc,GAAd,cAAc,CAAgB;IAC9C,CAAC;IAEJ;;OAEG;IACI,oBAAoB;QACzB,OAAO,IAAI,CAAC,cAAc,CAAC,oBAAoB,EAAE,CAAC;IACpD,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,MAAc;QAC7B,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,YAAY,CAAC,MAAc;QACtC,MAAM,eAAe,GAAG,IAAI,UAAU,CAAC,eAAe,EAAE,CAAC;QACzD,MAAM,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;QAChE,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OA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CAAC,MAAc;IACtD,OAAO,MAAM,UAAU,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAc;IAC/C,OAAO,UAAU,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CACvC,QAYU;IAEV,OAAO,OAAO,CAAC,WAAW,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;AAC3D,CAAC;AAED;;GAEG;AACH,MAAM,WAAY,SAAQ,QAAQ;IACzB,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,EAAY;QAC1C,MAAM,cAAc,GAAG,IAAI,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5F,MAAM,cAAc,CAAC,SAAS,EAAE,CAAC;QACjC,OAAO,IAAI,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["import { EventEmitter, Subscription } from 'expo-modules-core';\n\nimport ExpoSQLite from './ExpoSQLiteNext';\nimport { NativeDatabase, OpenOptions } from './NativeDatabase';\nimport { BindParams, RunResult, Statement, VariadicBindParams } from './Statement';\n\nexport { OpenOptions };\n\nconst emitter = new EventEmitter(ExpoSQLite);\n\n/**\n * A SQLite database.\n */\nexport class Database {\n constructor(\n public readonly dbName: string,\n private readonly nativeDatabase: NativeDatabase\n ) {}\n\n /**\n * Asynchronous call to return whether the database is currently in a transaction.\n */\n public isInTransactionAsync(): Promise<boolean> {\n return this.nativeDatabase.isInTransactionAsync();\n }\n\n /**\n * Close the database.\n */\n public closeAsync(): Promise<void> {\n return this.nativeDatabase.closeAsync();\n }\n\n /**\n * Execute all SQL queries in the supplied string.\n * > Note: The queries are not escaped for you! Be careful when constructing your queries.\n *\n * @param source A string containing all the SQL queries.\n */\n public execAsync(source: string): Promise<void> {\n return this.nativeDatabase.execAsync(source);\n }\n\n /**\n * Prepare a SQL statement.\n *\n * @param source A string containing the SQL query.\n * @returns A `Statement` object.\n */\n public async prepareAsync(source: string): Promise<Statement> {\n const nativeStatement = new ExpoSQLite.NativeStatement();\n await this.nativeDatabase.prepareAsync(nativeStatement, source);\n return new Statement(this.nativeDatabase, nativeStatement);\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * > **Note:** This transaction is not exclusive and can be interrupted by other async queries.\n * @example\n * ```ts\n * db.transactionAsync(async () => {\n * await db.execAsync('UPDATE test SET name = \"aaa\"');\n *\n * //\n * // We cannot control the order of async/await order, so order of execution is not guaranteed.\n * // The following UPDATE query out of transaction may be executed here and break the expectation.\n * //\n *\n * const result = await db.getAsync<{ name: string }>('SELECT name FROM Users');\n * expect(result?.name).toBe('aaa');\n * });\n * db.execAsync('UPDATE test SET name = \"bbb\"');\n * ```\n * If you worry about the order of execution, use `transactionExclusiveAsync` instead.\n *\n * @param task An async function to execute within a transaction.\n */\n public async transactionAsync(task: () => Promise<void>): Promise<void> {\n try {\n await this.execAsync('BEGIN');\n await task();\n await this.execAsync('COMMIT');\n } catch (e) {\n await this.execAsync('ROLLBACK');\n throw e;\n }\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * The transaction may be exclusive.\n * As long as the transaction is converted into a write transaction,\n * the other async write queries will abort with `database is locked` error.\n *\n * @param task An async function to execute within a transaction. Any queries inside the transaction must be executed on the `txn` object.\n * The `txn` object has the same interfaces as the `Database` object. You can use `txn` like a `Database` object.\n *\n * @example\n * ```ts\n * db.transactionExclusiveAsync(async (txn) => {\n * await txn.execAsync('UPDATE test SET name = \"aaa\"');\n * });\n * ```\n */\n public async transactionExclusiveAsync(task: (txn: Transaction) => Promise<void>): Promise<void> {\n const transaction = await Transaction.createAsync(this);\n let error;\n try {\n await transaction.execAsync('BEGIN');\n await task(transaction);\n await transaction.execAsync('COMMIT');\n } catch (e) {\n await transaction.execAsync('ROLLBACK');\n error = e;\n } finally {\n await transaction.closeAsync();\n }\n if (error) {\n throw error;\n }\n }\n\n /**\n * Synchronous call to return whether the database is currently in a transaction.\n */\n public isInTransactionSync(): boolean {\n return this.nativeDatabase.isInTransactionSync();\n }\n\n /**\n * Close the database.\n */\n public closeSync(): void {\n return this.nativeDatabase.closeSync();\n }\n\n /**\n * Execute all SQL queries in the supplied string.\n *\n * > **Note:** The queries are not escaped for you! Be careful when constructing your queries.\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing all the SQL queries.\n */\n public execSync(source: string): void {\n return this.nativeDatabase.execSync(source);\n }\n\n /**\n * Prepare a SQL statement.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @returns A `Statement` object.\n */\n public prepareSync(source: string): Statement {\n const nativeStatement = new ExpoSQLite.NativeStatement();\n this.nativeDatabase.prepareSync(nativeStatement, source);\n return new Statement(this.nativeDatabase, nativeStatement);\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param task An async function to execute within a transaction.\n */\n public transactionSync(task: () => void): void {\n try {\n this.execSync('BEGIN');\n task();\n this.execSync('COMMIT');\n } catch (e) {\n this.execSync('ROLLBACK');\n throw e;\n }\n }\n\n //#region Statement API shorthands\n\n /**\n * Shorthand for `prepareAsync` and `Statement.runAsync`.\n * Unlike `Statement.runAsync`, this method finalizes the statement after execution.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @param params Parameters to bind to the query.\n */\n public runAsync(source: string, ...params: VariadicBindParams): Promise<RunResult>;\n public runAsync(source: string, params: BindParams): Promise<RunResult>;\n public async runAsync(source: string, ...params: any[]): Promise<RunResult> {\n const statement = await this.prepareAsync(source);\n let result;\n try {\n result = await statement.runAsync(...params);\n } finally {\n await statement.finalizeAsync();\n }\n return result;\n }\n\n /**\n * Shorthand for `prepareAsync` and `Statement.getAsync`.\n * Unlike `Statement.getAsync`, this method finalizes the statement after execution.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @param params Parameters to bind to the query.\n */\n public getAsync<T>(source: string, ...params: VariadicBindParams): Promise<T | null>;\n public getAsync<T>(source: string, params: BindParams): Promise<T | null>;\n public async getAsync<T>(source: string, ...params: any[]): Promise<T | null> {\n const statement = await this.prepareAsync(source);\n let result;\n try {\n result = await statement.getAsync<T>(...params);\n } finally {\n await statement.finalizeAsync();\n }\n return result;\n }\n\n /**\n * Shorthand for `prepareAsync` and `Statement.eachAsync`.\n * Unlike `Statement.eachAsync`, this method finalizes the statement after execution.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @param params Parameters to bind to the query.\n */\n public eachAsync<T>(source: string, ...params: VariadicBindParams): AsyncIterableIterator<T>;\n public eachAsync<T>(source: string, params: BindParams): AsyncIterableIterator<T>;\n public async *eachAsync<T>(source: string, ...params: any[]): AsyncIterableIterator<T> {\n const statement = await this.prepareAsync(source);\n let result;\n try {\n result = await statement.eachAsync<T>(...params);\n } finally {\n await statement.finalizeAsync();\n }\n yield* result;\n }\n\n /**\n * Shorthand for `prepareAsync` and `Statement.allAsync`.\n * Unlike `Statement.allAsync`, this method finalizes the statement after execution.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @param params Parameters to bind to the query.\n */\n public allAsync<T>(source: string, ...params: VariadicBindParams): Promise<T[]>;\n public allAsync<T>(source: string, params: BindParams): Promise<T[]>;\n public async allAsync<T>(source: string, ...params: any[]): Promise<T[]> {\n const statement = await this.prepareAsync(source);\n let result;\n try {\n result = await statement.allAsync<T>(...params);\n } finally {\n await statement.finalizeAsync();\n }\n return result;\n }\n\n /**\n * Shorthand for `prepareSync` and `Statement.runSync`.\n * Unlike `Statement.runSync`, this method finalizes the statement after execution.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @param params Parameters to bind to the query.\n */\n public runSync(source: string, ...params: VariadicBindParams): RunResult;\n public runSync(source: string, params: BindParams): RunResult;\n public runSync(source: string, ...params: any[]): RunResult {\n const statement = this.prepareSync(source);\n let result;\n try {\n result = statement.runSync(...params);\n } finally {\n statement.finalizeSync();\n }\n return result;\n }\n\n /**\n * Shorthand for `prepareSync` and `Statement.getSync`.\n * Unlike `Statement.getSync`, this method finalizes the statement after execution.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @param params Parameters to bind to the query.\n */\n public getSync<T>(source: string, ...params: VariadicBindParams): T | null;\n public getSync<T>(source: string, params: BindParams): T | null;\n public getSync<T>(source: string, ...params: any[]): T | null {\n const statement = this.prepareSync(source);\n let result;\n try {\n result = statement.getSync<T>(...params);\n } finally {\n statement.finalizeSync();\n }\n return result;\n }\n\n /**\n * Shorthand for `prepareSync` and `Statement.eachSync`.\n * Unlike `Statement.eachSync`, this method finalizes the statement after execution.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @param params Parameters to bind to the query.\n */\n public eachSync<T>(source: string, ...params: VariadicBindParams): IterableIterator<T>;\n public eachSync<T>(source: string, params: BindParams): IterableIterator<T>;\n public *eachSync<T>(source: string, ...params: any[]): IterableIterator<T> {\n const statement = this.prepareSync(source);\n let result;\n try {\n result = statement.eachSync<T>(...params);\n } finally {\n statement.finalizeSync();\n }\n yield* result;\n }\n\n /**\n * Shorthand for `prepareSync` and `Statement.allSync`.\n * Unlike `Statement.allSync`, this method finalizes the statement after execution.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @param params Parameters to bind to the query.\n */\n public allSync<T>(source: string, ...params: VariadicBindParams): T[];\n public allSync<T>(source: string, params: BindParams): T[];\n public allSync<T>(source: string, ...params: any[]): T[] {\n const statement = this.prepareSync(source);\n let result;\n try {\n result = statement.allSync<T>(...params);\n } finally {\n statement.finalizeSync();\n }\n return result;\n }\n\n //#endregion\n}\n\n/**\n * Open a database.\n *\n * @param dbName The name of the database file to open.\n * @param options Open options.\n * @returns Database object.\n */\nexport async function openDatabaseAsync(dbName: string, options?: OpenOptions): Promise<Database> {\n const nativeDatabase = new ExpoSQLite.NativeDatabase(dbName, options ?? {});\n await nativeDatabase.initAsync();\n return new Database(dbName, nativeDatabase);\n}\n\n/**\n * Open a database.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param dbName The name of the database file to open.\n * @param options Open options.\n * @returns Database object.\n */\nexport function openDatabaseSync(dbName: string, options?: OpenOptions): Database {\n const nativeDatabase = new ExpoSQLite.NativeDatabase(dbName, options ?? {});\n nativeDatabase.initSync();\n return new Database(dbName, nativeDatabase);\n}\n\n/**\n * Delete a database file.\n *\n * @param dbName The name of the database file to delete.\n */\nexport async function deleteDatabaseAsync(dbName: string): Promise<void> {\n return await ExpoSQLite.deleteDatabaseAsync(dbName);\n}\n\n/**\n * Delete a database file.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param dbName The name of the database file to delete.\n */\nexport function deleteDatabaseSync(dbName: string): void {\n return ExpoSQLite.deleteDatabaseSync(dbName);\n}\n\n/**\n * Add a listener for database changes.\n * > Note: to enable this feature, you must set `enableChangeListener` to `true` when opening the database.\n *\n * @param listener A function that receives the `dbName`, `tableName` and `rowId` of the modified data.\n * @returns A `Subscription` object that you can call `remove()` on when you would like to unsubscribe the listener.\n */\nexport function addDatabaseChangeListener(\n listener: (event: {\n /** The database name. The value would be `main` by default and other database names if you use `ATTACH DATABASE` statement. */\n dbName: string;\n\n /** The absolute file path to the database. */\n dbFilePath: string;\n\n /** The table name. */\n tableName: string;\n\n /** The changed row ID. */\n rowId: number;\n }) => void\n): Subscription {\n return emitter.addListener('onDatabaseChange', listener);\n}\n\n/**\n * A new connection specific for `transactionExclusiveAsync`.\n */\nclass Transaction extends Database {\n public static async createAsync(db: Database): Promise<Transaction> {\n const nativeDatabase = new ExpoSQLite.NativeDatabase(db.dbName, { useNewConnection: true });\n await nativeDatabase.initAsync();\n return new Transaction(db.dbName, nativeDatabase);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Database.js","sourceRoot":"","sources":["../../src/next/Database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,MAAM,mBAAmB,CAAC;AAE/D,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAyB,SAAS,EAAsB,MAAM,aAAa,CAAC;AAInF,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,UAAU,CAAC,CAAC;AAE7C;;GAEG;AACH,MAAM,OAAO,QAAQ;IAED;IACC;IAFnB,YACkB,MAAc,EACb,cAA8B;QAD/B,WAAM,GAAN,MAAM,CAAQ;QACb,mBAAc,GAAd,cAAc,CAAgB;IAC9C,CAAC;IAEJ;;OAEG;IACI,oBAAoB;QACzB,OAAO,IAAI,CAAC,cAAc,CAAC,oBAAoB,EAAE,CAAC;IACpD,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,MAAc;QAC7B,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,YAAY,CAAC,MAAc;QACtC,MAAM,eAAe,GAAG,IAAI,UAAU,CAAC,eAAe,EAAE,CAAC;QACzD,MAAM,IAAI,CAAC,cAAc,CA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AAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,MAAc;IACtD,OAAO,MAAM,UAAU,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAc;IAC/C,OAAO,UAAU,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CACvC,QAYU;IAEV,OAAO,OAAO,CAAC,WAAW,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;AAC3D,CAAC;AAED;;GAEG;AACH,MAAM,WAAY,SAAQ,QAAQ;IACzB,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,EAAY;QAC1C,MAAM,cAAc,GAAG,IAAI,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5F,MAAM,cAAc,CAAC,SAAS,EAAE,CAAC;QACjC,OAAO,IAAI,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["import { EventEmitter, Subscription } from 'expo-modules-core';\n\nimport ExpoSQLite from './ExpoSQLiteNext';\nimport { NativeDatabase, OpenOptions } from './NativeDatabase';\nimport { BindParams, RunResult, Statement, VariadicBindParams } from './Statement';\n\nexport { OpenOptions };\n\nconst emitter = new EventEmitter(ExpoSQLite);\n\n/**\n * A SQLite database.\n */\nexport class Database {\n constructor(\n public readonly dbName: string,\n private readonly nativeDatabase: NativeDatabase\n ) {}\n\n /**\n * Asynchronous call to return whether the database is currently in a transaction.\n */\n public isInTransactionAsync(): Promise<boolean> {\n return this.nativeDatabase.isInTransactionAsync();\n }\n\n /**\n * Close the database.\n */\n public closeAsync(): Promise<void> {\n return this.nativeDatabase.closeAsync();\n }\n\n /**\n * Execute all SQL queries in the supplied string.\n * > Note: The queries are not escaped for you! Be careful when constructing your queries.\n *\n * @param source A string containing all the SQL queries.\n */\n public execAsync(source: string): Promise<void> {\n return this.nativeDatabase.execAsync(source);\n }\n\n /**\n * Prepare a SQL statement.\n *\n * @param source A string containing the SQL query.\n * @returns A `Statement` object.\n */\n public async prepareAsync(source: string): Promise<Statement> {\n const nativeStatement = new ExpoSQLite.NativeStatement();\n await this.nativeDatabase.prepareAsync(nativeStatement, source);\n return new Statement(this.nativeDatabase, nativeStatement);\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * > **Note:** This transaction is not exclusive and can be interrupted by other async queries.\n * @example\n * ```ts\n * db.transactionAsync(async () => {\n * await db.execAsync('UPDATE test SET name = \"aaa\"');\n *\n * //\n * // We cannot control the order of async/await order, so order of execution is not guaranteed.\n * // The following UPDATE query out of transaction may be executed here and break the expectation.\n * //\n *\n * const result = await db.getAsync<{ name: string }>('SELECT name FROM Users');\n * expect(result?.name).toBe('aaa');\n * });\n * db.execAsync('UPDATE test SET name = \"bbb\"');\n * ```\n * If you worry about the order of execution, use `transactionExclusiveAsync` instead.\n *\n * @param task An async function to execute within a transaction.\n */\n public async transactionAsync(task: () => Promise<void>): Promise<void> {\n try {\n await this.execAsync('BEGIN');\n await task();\n await this.execAsync('COMMIT');\n } catch (e) {\n await this.execAsync('ROLLBACK');\n throw e;\n }\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * The transaction may be exclusive.\n * As long as the transaction is converted into a write transaction,\n * the other async write queries will abort with `database is locked` error.\n *\n * @param task An async function to execute within a transaction. Any queries inside the transaction must be executed on the `txn` object.\n * The `txn` object has the same interfaces as the `Database` object. You can use `txn` like a `Database` object.\n *\n * @example\n * ```ts\n * db.transactionExclusiveAsync(async (txn) => {\n * await txn.execAsync('UPDATE test SET name = \"aaa\"');\n * });\n * ```\n */\n public async transactionExclusiveAsync(task: (txn: Transaction) => Promise<void>): Promise<void> {\n const transaction = await Transaction.createAsync(this);\n let error;\n try {\n await transaction.execAsync('BEGIN');\n await task(transaction);\n await transaction.execAsync('COMMIT');\n } catch (e) {\n await transaction.execAsync('ROLLBACK');\n error = e;\n } finally {\n await transaction.closeAsync();\n }\n if (error) {\n throw error;\n }\n }\n\n /**\n * Synchronous call to return whether the database is currently in a transaction.\n */\n public isInTransactionSync(): boolean {\n return this.nativeDatabase.isInTransactionSync();\n }\n\n /**\n * Close the database.\n */\n public closeSync(): void {\n return this.nativeDatabase.closeSync();\n }\n\n /**\n * Execute all SQL queries in the supplied string.\n *\n * > **Note:** The queries are not escaped for you! Be careful when constructing your queries.\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing all the SQL queries.\n */\n public execSync(source: string): void {\n return this.nativeDatabase.execSync(source);\n }\n\n /**\n * Prepare a SQL statement.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @returns A `Statement` object.\n */\n public prepareSync(source: string): Statement {\n const nativeStatement = new ExpoSQLite.NativeStatement();\n this.nativeDatabase.prepareSync(nativeStatement, source);\n return new Statement(this.nativeDatabase, nativeStatement);\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param task An async function to execute within a transaction.\n */\n public transactionSync(task: () => void): void {\n try {\n this.execSync('BEGIN');\n task();\n this.execSync('COMMIT');\n } catch (e) {\n this.execSync('ROLLBACK');\n throw e;\n }\n }\n\n //#region Statement API shorthands\n\n /**\n * Shorthand for `prepareAsync` and `Statement.runAsync`.\n * Unlike `Statement.runAsync`, this method finalizes the statement after execution.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @param params Parameters to bind to the query.\n */\n public runAsync(source: string, ...params: VariadicBindParams): Promise<RunResult>;\n public runAsync(source: string, params: BindParams): Promise<RunResult>;\n public async runAsync(source: string, ...params: any[]): Promise<RunResult> {\n const statement = await this.prepareAsync(source);\n let result;\n try {\n result = await statement.runAsync(...params);\n } finally {\n await statement.finalizeAsync();\n }\n return result;\n }\n\n /**\n * Shorthand for `prepareAsync` and `Statement.getAsync`.\n * Unlike `Statement.getAsync`, this method finalizes the statement after execution.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @param params Parameters to bind to the query.\n */\n public getAsync<T>(source: string, ...params: VariadicBindParams): Promise<T | null>;\n public getAsync<T>(source: string, params: BindParams): Promise<T | null>;\n public async getAsync<T>(source: string, ...params: any[]): Promise<T | null> {\n const statement = await this.prepareAsync(source);\n let result;\n try {\n result = await statement.getAsync<T>(...params);\n } finally {\n await statement.finalizeAsync();\n }\n return result;\n }\n\n /**\n * Shorthand for `prepareAsync` and `Statement.eachAsync`.\n * Unlike `Statement.eachAsync`, this method finalizes the statement after execution.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @param params Parameters to bind to the query.\n */\n public eachAsync<T>(source: string, ...params: VariadicBindParams): AsyncIterableIterator<T>;\n public eachAsync<T>(source: string, params: BindParams): AsyncIterableIterator<T>;\n public async *eachAsync<T>(source: string, ...params: any[]): AsyncIterableIterator<T> {\n const statement = await this.prepareAsync(source);\n try {\n yield* await statement.eachAsync<T>(...params);\n } finally {\n await statement.finalizeAsync();\n }\n }\n\n /**\n * Shorthand for `prepareAsync` and `Statement.allAsync`.\n * Unlike `Statement.allAsync`, this method finalizes the statement after execution.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @param params Parameters to bind to the query.\n */\n public allAsync<T>(source: string, ...params: VariadicBindParams): Promise<T[]>;\n public allAsync<T>(source: string, params: BindParams): Promise<T[]>;\n public async allAsync<T>(source: string, ...params: any[]): Promise<T[]> {\n const statement = await this.prepareAsync(source);\n let result;\n try {\n result = await statement.allAsync<T>(...params);\n } finally {\n await statement.finalizeAsync();\n }\n return result;\n }\n\n /**\n * Shorthand for `prepareSync` and `Statement.runSync`.\n * Unlike `Statement.runSync`, this method finalizes the statement after execution.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @param params Parameters to bind to the query.\n */\n public runSync(source: string, ...params: VariadicBindParams): RunResult;\n public runSync(source: string, params: BindParams): RunResult;\n public runSync(source: string, ...params: any[]): RunResult {\n const statement = this.prepareSync(source);\n let result;\n try {\n result = statement.runSync(...params);\n } finally {\n statement.finalizeSync();\n }\n return result;\n }\n\n /**\n * Shorthand for `prepareSync` and `Statement.getSync`.\n * Unlike `Statement.getSync`, this method finalizes the statement after execution.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @param params Parameters to bind to the query.\n */\n public getSync<T>(source: string, ...params: VariadicBindParams): T | null;\n public getSync<T>(source: string, params: BindParams): T | null;\n public getSync<T>(source: string, ...params: any[]): T | null {\n const statement = this.prepareSync(source);\n let result;\n try {\n result = statement.getSync<T>(...params);\n } finally {\n statement.finalizeSync();\n }\n return result;\n }\n\n /**\n * Shorthand for `prepareSync` and `Statement.eachSync`.\n * Unlike `Statement.eachSync`, this method finalizes the statement after execution.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @param params Parameters to bind to the query.\n */\n public eachSync<T>(source: string, ...params: VariadicBindParams): IterableIterator<T>;\n public eachSync<T>(source: string, params: BindParams): IterableIterator<T>;\n public *eachSync<T>(source: string, ...params: any[]): IterableIterator<T> {\n const statement = this.prepareSync(source);\n try {\n yield* statement.eachSync<T>(...params);\n } finally {\n statement.finalizeSync();\n }\n }\n\n /**\n * Shorthand for `prepareSync` and `Statement.allSync`.\n * Unlike `Statement.allSync`, this method finalizes the statement after execution.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param source A string containing the SQL query.\n * @param params Parameters to bind to the query.\n */\n public allSync<T>(source: string, ...params: VariadicBindParams): T[];\n public allSync<T>(source: string, params: BindParams): T[];\n public allSync<T>(source: string, ...params: any[]): T[] {\n const statement = this.prepareSync(source);\n let result;\n try {\n result = statement.allSync<T>(...params);\n } finally {\n statement.finalizeSync();\n }\n return result;\n }\n\n //#endregion\n}\n\n/**\n * Open a database.\n *\n * @param dbName The name of the database file to open.\n * @param options Open options.\n * @returns Database object.\n */\nexport async function openDatabaseAsync(dbName: string, options?: OpenOptions): Promise<Database> {\n const nativeDatabase = new ExpoSQLite.NativeDatabase(dbName, options ?? {});\n await nativeDatabase.initAsync();\n return new Database(dbName, nativeDatabase);\n}\n\n/**\n * Open a database.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param dbName The name of the database file to open.\n * @param options Open options.\n * @returns Database object.\n */\nexport function openDatabaseSync(dbName: string, options?: OpenOptions): Database {\n const nativeDatabase = new ExpoSQLite.NativeDatabase(dbName, options ?? {});\n nativeDatabase.initSync();\n return new Database(dbName, nativeDatabase);\n}\n\n/**\n * Delete a database file.\n *\n * @param dbName The name of the database file to delete.\n */\nexport async function deleteDatabaseAsync(dbName: string): Promise<void> {\n return await ExpoSQLite.deleteDatabaseAsync(dbName);\n}\n\n/**\n * Delete a database file.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread, affecting performance.\n *\n * @param dbName The name of the database file to delete.\n */\nexport function deleteDatabaseSync(dbName: string): void {\n return ExpoSQLite.deleteDatabaseSync(dbName);\n}\n\n/**\n * Add a listener for database changes.\n * > Note: to enable this feature, you must set `enableChangeListener` to `true` when opening the database.\n *\n * @param listener A function that receives the `dbName`, `tableName` and `rowId` of the modified data.\n * @returns A `Subscription` object that you can call `remove()` on when you would like to unsubscribe the listener.\n */\nexport function addDatabaseChangeListener(\n listener: (event: {\n /** The database name. The value would be `main` by default and other database names if you use `ATTACH DATABASE` statement. */\n dbName: string;\n\n /** The absolute file path to the database. */\n dbFilePath: string;\n\n /** The table name. */\n tableName: string;\n\n /** The changed row ID. */\n rowId: number;\n }) => void\n): Subscription {\n return emitter.addListener('onDatabaseChange', listener);\n}\n\n/**\n * A new connection specific for `transactionExclusiveAsync`.\n */\nclass Transaction extends Database {\n public static async createAsync(db: Database): Promise<Transaction> {\n const nativeDatabase = new ExpoSQLite.NativeDatabase(db.dbName, { useNewConnection: true });\n await nativeDatabase.initAsync();\n return new Transaction(db.dbName, nativeDatabase);\n }\n}\n"]}
|