expo-sqlite 11.3.2 → 11.3.3
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 +11 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/expo/modules/sqlite/SQLiteHelpers.kt +9 -1
- package/android/src/main/java/expo/modules/sqlite/SQLiteModule.kt +103 -19
- package/build/SQLite.d.ts +7 -1
- package/build/SQLite.d.ts.map +1 -1
- package/build/SQLite.js +24 -1
- package/build/SQLite.js.map +1 -1
- package/build/SQLite.types.d.ts +1 -1
- package/build/SQLite.types.d.ts.map +1 -1
- package/build/SQLite.types.js.map +1 -1
- package/package.json +2 -2
- package/src/SQLite.ts +31 -5
- package/src/SQLite.types.ts +1 -4
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,17 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 11.3.3 — 2023-09-08
|
|
14
|
+
|
|
15
|
+
### 🎉 New features
|
|
16
|
+
|
|
17
|
+
- Add support for running raw queries on Android. ([#24320](https://github.com/expo/expo/pull/24320) by [@alanjhughes](https://github.com/alanjhughes))
|
|
18
|
+
|
|
19
|
+
### 🐛 Bug fixes
|
|
20
|
+
|
|
21
|
+
- [Android] Fixed select queries with CTEs crashing on Android. ([#24132](https://github.com/expo/expo/pull/24132) by [@derekstavis](https://github.com/derekstavis))
|
|
22
|
+
- Fixed the return type from `executeSqlAsync` to only successful `ResultSet`. ([#24336](https://github.com/expo/expo/pull/24336) by [@kudo](https://github.com/kudo))
|
|
23
|
+
|
|
13
24
|
## 11.3.2 — 2023-07-29
|
|
14
25
|
|
|
15
26
|
### 🐛 Bug fixes
|
package/android/build.gradle
CHANGED
|
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
|
|
|
3
3
|
apply plugin: 'maven-publish'
|
|
4
4
|
|
|
5
5
|
group = 'host.exp.exponent'
|
|
6
|
-
version = '11.3.
|
|
6
|
+
version = '11.3.3'
|
|
7
7
|
|
|
8
8
|
buildscript {
|
|
9
9
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
@@ -67,7 +67,7 @@ android {
|
|
|
67
67
|
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
68
68
|
targetSdkVersion safeExtGet("targetSdkVersion", 33)
|
|
69
69
|
versionCode 18
|
|
70
|
-
versionName "11.3.
|
|
70
|
+
versionName "11.3.3"
|
|
71
71
|
}
|
|
72
72
|
lintOptions {
|
|
73
73
|
abortOnError false
|
|
@@ -52,12 +52,16 @@ private fun isPragma(str: String): Boolean {
|
|
|
52
52
|
return startsWithCaseInsensitive(str, "pragma")
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
private fun isSelectCTE(str: String): Boolean {
|
|
56
|
+
return startsWithCaseInsensitive(str, "with") && containsCaseInsensitive(str, "select")
|
|
57
|
+
}
|
|
58
|
+
|
|
55
59
|
private fun isPragmaReadOnly(str: String): Boolean {
|
|
56
60
|
return isPragma(str) && !str.contains('=')
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
internal fun isSelect(str: String): Boolean {
|
|
60
|
-
return startsWithCaseInsensitive(str, "select") || isPragmaReadOnly(str)
|
|
64
|
+
return startsWithCaseInsensitive(str, "select") || isSelectCTE(str) || isPragmaReadOnly(str)
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
internal fun isInsert(str: String): Boolean {
|
|
@@ -76,6 +80,10 @@ private fun startsWithCaseInsensitive(str: String, substr: String): Boolean {
|
|
|
76
80
|
return str.trimStart().startsWith(substr, true)
|
|
77
81
|
}
|
|
78
82
|
|
|
83
|
+
private fun containsCaseInsensitive(str: String, substr: String): Boolean {
|
|
84
|
+
return str.trimStart().contains(substr, true)
|
|
85
|
+
}
|
|
86
|
+
|
|
79
87
|
internal fun convertParamsToStringArray(paramArrayArg: List<Any?>): Array<String?> {
|
|
80
88
|
return paramArrayArg.map { param ->
|
|
81
89
|
when (param) {
|
|
@@ -24,25 +24,11 @@ class SQLiteModule : Module() {
|
|
|
24
24
|
Name("ExpoSQLite")
|
|
25
25
|
|
|
26
26
|
AsyncFunction("exec") { dbName: String, queries: List<Query>, readOnly: Boolean ->
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (isSelect(sql)) {
|
|
33
|
-
doSelectInBackgroundAndPossiblyThrow(sql, bindArgs, db)
|
|
34
|
-
} else { // update/insert/delete
|
|
35
|
-
if (readOnly) {
|
|
36
|
-
SQLitePluginResult(EMPTY_ROWS, EMPTY_COLUMNS, 0, 0, ReadOnlyException())
|
|
37
|
-
} else {
|
|
38
|
-
doUpdateInBackgroundAndPossiblyThrow(sql, bindArgs, db)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
} catch (e: Throwable) {
|
|
42
|
-
SQLitePluginResult(EMPTY_ROWS, EMPTY_COLUMNS, 0, 0, e)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return@AsyncFunction pluginResultsToPrimitiveData(results)
|
|
27
|
+
return@AsyncFunction execute(dbName, queries, readOnly)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
AsyncFunction("execRawQuery") { dbName: String, queries: List<Query>, readOnly: Boolean ->
|
|
31
|
+
return@AsyncFunction execute(dbName, queries, readOnly, raw = true)
|
|
46
32
|
}
|
|
47
33
|
|
|
48
34
|
AsyncFunction("close") { dbName: String ->
|
|
@@ -65,6 +51,32 @@ class SQLiteModule : Module() {
|
|
|
65
51
|
}
|
|
66
52
|
}
|
|
67
53
|
|
|
54
|
+
private fun execute(dbName: String, queries: List<Query>, readOnly: Boolean, raw: Boolean = false): List<Any> {
|
|
55
|
+
val db = getDatabase(dbName)
|
|
56
|
+
val results = queries.map { sqlQuery ->
|
|
57
|
+
val sql = sqlQuery.sql
|
|
58
|
+
val bindArgs = convertParamsToStringArray(sqlQuery.args)
|
|
59
|
+
try {
|
|
60
|
+
if (isSelect(sql)) {
|
|
61
|
+
doSelectInBackgroundAndPossiblyThrow(sql, bindArgs, db)
|
|
62
|
+
} else { // update/insert/delete
|
|
63
|
+
if (readOnly) {
|
|
64
|
+
SQLitePluginResult(EMPTY_ROWS, EMPTY_COLUMNS, 0, 0, ReadOnlyException())
|
|
65
|
+
} else {
|
|
66
|
+
if (raw) {
|
|
67
|
+
doRawUpdate(sql, bindArgs, db)
|
|
68
|
+
} else {
|
|
69
|
+
doUpdateInBackgroundAndPossiblyThrow(sql, bindArgs, db)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} catch (e: Throwable) {
|
|
74
|
+
SQLitePluginResult(EMPTY_ROWS, EMPTY_COLUMNS, 0, 0, e)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return pluginResultsToPrimitiveData(results)
|
|
78
|
+
}
|
|
79
|
+
|
|
68
80
|
// do a update/delete/insert operation
|
|
69
81
|
private fun doUpdateInBackgroundAndPossiblyThrow(
|
|
70
82
|
sql: String,
|
|
@@ -97,6 +109,78 @@ class SQLiteModule : Module() {
|
|
|
97
109
|
}
|
|
98
110
|
}
|
|
99
111
|
|
|
112
|
+
private fun doRawUpdate(
|
|
113
|
+
sql: String,
|
|
114
|
+
bindArgs: Array<String?>,
|
|
115
|
+
db: SQLiteDatabase
|
|
116
|
+
): SQLitePluginResult {
|
|
117
|
+
return db.rawQuery(sql, bindArgs).use { cursor ->
|
|
118
|
+
val numRows = cursor.count
|
|
119
|
+
if (numRows == 0) {
|
|
120
|
+
return EMPTY_RESULT
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
val numColumns = cursor.columnCount
|
|
124
|
+
val columnNames = cursor.columnNames
|
|
125
|
+
val rows: Array<Array<Any?>> = Array(numRows) { arrayOfNulls(numColumns) }
|
|
126
|
+
var i = 0
|
|
127
|
+
while (cursor.moveToNext()) {
|
|
128
|
+
val row = rows[i]
|
|
129
|
+
for (j in 0 until numColumns) {
|
|
130
|
+
row[j] = getValueFromCursor(cursor, j, cursor.getType(j))
|
|
131
|
+
}
|
|
132
|
+
rows[i] = row
|
|
133
|
+
i++
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (isInsert(sql)) {
|
|
137
|
+
val rowsAffected = getRowsAffected(db).let {
|
|
138
|
+
it.first.close()
|
|
139
|
+
it.second
|
|
140
|
+
}
|
|
141
|
+
val insertId = getInsertId(db).let {
|
|
142
|
+
it.first.close()
|
|
143
|
+
it.second
|
|
144
|
+
}
|
|
145
|
+
SQLitePluginResult(rows, columnNames, rowsAffected, insertId, null)
|
|
146
|
+
} else if (isDelete(sql) || isUpdate(sql)) {
|
|
147
|
+
val rowsAffected = getRowsAffected(db).let {
|
|
148
|
+
it.first.close()
|
|
149
|
+
it.second
|
|
150
|
+
}
|
|
151
|
+
SQLitePluginResult(rows, columnNames, rowsAffected, 0, null)
|
|
152
|
+
} else {
|
|
153
|
+
EMPTY_RESULT
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private fun getRowsAffected(
|
|
159
|
+
db: SQLiteDatabase,
|
|
160
|
+
): Pair<Cursor, Int> {
|
|
161
|
+
val cursor = db.rawQuery("SELECT changes() AS numRowsAffected", null)
|
|
162
|
+
val rowsAffected = if (cursor.moveToFirst()) {
|
|
163
|
+
val index = cursor.getColumnIndex("numRowsAffected")
|
|
164
|
+
cursor.getInt(index)
|
|
165
|
+
} else {
|
|
166
|
+
-1
|
|
167
|
+
}
|
|
168
|
+
return Pair(cursor, rowsAffected)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private fun getInsertId(
|
|
172
|
+
db: SQLiteDatabase,
|
|
173
|
+
): Pair<Cursor, Long> {
|
|
174
|
+
val cursor = db.rawQuery("SELECT last_insert_rowid() AS insertId", null)
|
|
175
|
+
val insertId = if (cursor.moveToFirst()) {
|
|
176
|
+
val index = cursor.getColumnIndex("insertId")
|
|
177
|
+
cursor.getLong(index)
|
|
178
|
+
} else {
|
|
179
|
+
-1
|
|
180
|
+
}
|
|
181
|
+
return Pair(cursor, insertId)
|
|
182
|
+
}
|
|
183
|
+
|
|
100
184
|
// do a select operation
|
|
101
185
|
private fun doSelectInBackgroundAndPossiblyThrow(
|
|
102
186
|
sql: String,
|
package/build/SQLite.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ export declare class SQLiteDatabase {
|
|
|
9
9
|
* Executes the SQL statement and returns a callback resolving with the result.
|
|
10
10
|
*/
|
|
11
11
|
exec(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void;
|
|
12
|
+
/**
|
|
13
|
+
* Due to limitations on `Android` this function is provided to allow raw SQL queries to be
|
|
14
|
+
* executed on the database. This will be less efficient than using the `exec` function, please use
|
|
15
|
+
* only when necessary.
|
|
16
|
+
*/
|
|
17
|
+
execRawQuery(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void;
|
|
12
18
|
/**
|
|
13
19
|
* Executes the SQL statement and returns a Promise resolving with the result.
|
|
14
20
|
*/
|
|
@@ -66,6 +72,6 @@ export declare class ExpoSQLTransactionAsync implements SQLTransactionAsync {
|
|
|
66
72
|
private readonly db;
|
|
67
73
|
private readonly readOnly;
|
|
68
74
|
constructor(db: SQLiteDatabase, readOnly: boolean);
|
|
69
|
-
executeSqlAsync(sqlStatement: string, args?: (number | string)[]): Promise<
|
|
75
|
+
executeSqlAsync(sqlStatement: string, args?: (number | string)[]): Promise<ResultSet>;
|
|
70
76
|
}
|
|
71
77
|
//# 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,OAAO,oBAAoB,CAAC;AAM5B,OAAO,KAAK,EACV,KAAK,EACL,SAAS,EACT,cAAc,EACd,cAAc,EACd,2BAA2B,EAC3B,mBAAmB,E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AE,MAAM,IAAI,GAC3B,IAAI;CACR;AA0CD;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAc,EACvB,WAAW,GAAE,MAAa,EAC1B,IAAI,GAAE,MAAU,EAChB,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,cAAc,KAAK,IAAI,GACtC,cAAc,CAYhB;AAED;;;GAGG;AACH,qBAAa,uBAAwB,YAAW,mBAAmB;IACrD,OAAO,CAAC,QAAQ,CAAC,EAAE;IAAkB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAA7C,EAAE,EAAE,cAAc,EAAmB,QAAQ,EAAE,OAAO;IAE7E,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC;CAW5F"}
|
package/build/SQLite.js
CHANGED
|
@@ -31,6 +31,21 @@ export class SQLiteDatabase {
|
|
|
31
31
|
callback(error instanceof Error ? error : new Error(error));
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Due to limitations on `Android` this function is provided to allow raw SQL queries to be
|
|
36
|
+
* executed on the database. This will be less efficient than using the `exec` function, please use
|
|
37
|
+
* only when necessary.
|
|
38
|
+
*/
|
|
39
|
+
execRawQuery(queries, readOnly, callback) {
|
|
40
|
+
if (Platform.OS === 'ios') {
|
|
41
|
+
return this.exec(queries, readOnly, callback);
|
|
42
|
+
}
|
|
43
|
+
ExpoSQLite.execRawQuery(this._name, queries.map(_serializeQuery), readOnly).then((nativeResultSets) => {
|
|
44
|
+
callback(null, nativeResultSets.map(_deserializeResultSet));
|
|
45
|
+
}, (error) => {
|
|
46
|
+
callback(error instanceof Error ? error : new Error(error));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
34
49
|
/**
|
|
35
50
|
* Executes the SQL statement and returns a Promise resolving with the result.
|
|
36
51
|
*/
|
|
@@ -137,6 +152,7 @@ export function openDatabase(name, version = '1.0', description = name, size = 1
|
|
|
137
152
|
}
|
|
138
153
|
const db = _openExpoSQLiteDatabase(name, version, description, size, callback);
|
|
139
154
|
db.exec = db._db.exec.bind(db._db);
|
|
155
|
+
db.execRawQuery = db._db.execRawQuery.bind(db._db);
|
|
140
156
|
db.execAsync = db._db.execAsync.bind(db._db);
|
|
141
157
|
db.closeAsync = db._db.closeAsync.bind(db._db);
|
|
142
158
|
db.deleteAsync = db._db.deleteAsync.bind(db._db);
|
|
@@ -156,7 +172,14 @@ export class ExpoSQLTransactionAsync {
|
|
|
156
172
|
}
|
|
157
173
|
async executeSqlAsync(sqlStatement, args) {
|
|
158
174
|
const resultSets = await this.db.execAsync([{ sql: sqlStatement, args: args ?? [] }], this.readOnly);
|
|
159
|
-
|
|
175
|
+
const result = resultSets[0];
|
|
176
|
+
if (isResultSetError(result)) {
|
|
177
|
+
throw result.error;
|
|
178
|
+
}
|
|
179
|
+
return result;
|
|
160
180
|
}
|
|
161
181
|
}
|
|
182
|
+
function isResultSetError(result) {
|
|
183
|
+
return 'error' in result;
|
|
184
|
+
}
|
|
162
185
|
//# sourceMappingURL=SQLite.js.map
|
package/build/SQLite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAaxC,MAAM,UAAU,GAAG,mBAAmB,CAAC,YAAY,CAAC,CAAC;AAErD,SAAS,SAAS,CAAC,IAAc,EAAE,MAAa;IAC9C,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,G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Tick';\n\nimport customOpenDatabase from '@expo/websql/custom';\nimport { requireNativeModule } 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');\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 * 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(): void {\n this._closed = true;\n return ExpoSQLite.close(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 * 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.execAsync = db._db.execAsync.bind(db._db);\n db.closeAsync = db._db.closeAsync.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(private readonly db: SQLiteDatabase, private readonly readOnly: boolean) {}\n\n async executeSqlAsync(\n sqlStatement: string,\n args?: (number | string)[]\n ): Promise<ResultSetError | ResultSet> {\n const resultSets = await this.db.execAsync(\n [{ sql: sqlStatement, args: args ?? [] }],\n this.readOnly\n );\n return resultSets[0];\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SQLite.js","sourceRoot":"","sources":["../src/SQLite.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAE5B,OAAO,kBAAkB,MAAM,qBAAqB,CA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ent":["import './polyfillNextTick';\n\nimport customOpenDatabase from '@expo/websql/custom';\nimport { requireNativeModule } 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');\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(): void {\n this._closed = true;\n return ExpoSQLite.close(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 * 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.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(private readonly db: SQLiteDatabase, private readonly readOnly: boolean) {}\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"]}
|
package/build/SQLite.types.d.ts
CHANGED
|
@@ -125,7 +125,7 @@ export type SQLiteCallback = (error?: Error | null, resultSet?: (ResultSetError
|
|
|
125
125
|
/** A transaction object to perform SQL statements in async mode. */
|
|
126
126
|
export interface SQLTransactionAsync {
|
|
127
127
|
/** Executes a SQL statement in async mode. */
|
|
128
|
-
executeSqlAsync(sqlStatement: string, args?: (number | string)[]): Promise<
|
|
128
|
+
executeSqlAsync(sqlStatement: string, args?: (number | string)[]): Promise<ResultSet>;
|
|
129
129
|
}
|
|
130
130
|
/** A transaction callback with given `SQLTransactionAsync` object to perform SQL statements in async mode. */
|
|
131
131
|
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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AGG;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,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CACvF;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?: (number | string | null)[],\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(
|
|
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?: (number | string | null)[],\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?: (number | string)[]): 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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-sqlite",
|
|
3
|
-
"version": "11.3.
|
|
3
|
+
"version": "11.3.3",
|
|
4
4
|
"description": "Provides access to a database that can be queried through a WebSQL-like API (https://www.w3.org/TR/webdatabase/). The database is persisted across restarts of your app.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"expo": "*"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "2a09888e5878f3669e0bdf0ade195a8dca3333e2"
|
|
48
48
|
}
|
package/src/SQLite.ts
CHANGED
|
@@ -53,6 +53,26 @@ export class SQLiteDatabase {
|
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Due to limitations on `Android` this function is provided to allow raw SQL queries to be
|
|
58
|
+
* executed on the database. This will be less efficient than using the `exec` function, please use
|
|
59
|
+
* only when necessary.
|
|
60
|
+
*/
|
|
61
|
+
execRawQuery(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void {
|
|
62
|
+
if (Platform.OS === 'ios') {
|
|
63
|
+
return this.exec(queries, readOnly, callback);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
ExpoSQLite.execRawQuery(this._name, queries.map(_serializeQuery), readOnly).then(
|
|
67
|
+
(nativeResultSets) => {
|
|
68
|
+
callback(null, nativeResultSets.map(_deserializeResultSet));
|
|
69
|
+
},
|
|
70
|
+
(error) => {
|
|
71
|
+
callback(error instanceof Error ? error : new Error(error));
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
56
76
|
/**
|
|
57
77
|
* Executes the SQL statement and returns a Promise resolving with the result.
|
|
58
78
|
*/
|
|
@@ -207,6 +227,7 @@ export function openDatabase(
|
|
|
207
227
|
}
|
|
208
228
|
const db = _openExpoSQLiteDatabase(name, version, description, size, callback);
|
|
209
229
|
db.exec = db._db.exec.bind(db._db);
|
|
230
|
+
db.execRawQuery = db._db.execRawQuery.bind(db._db);
|
|
210
231
|
db.execAsync = db._db.execAsync.bind(db._db);
|
|
211
232
|
db.closeAsync = db._db.closeAsync.bind(db._db);
|
|
212
233
|
db.deleteAsync = db._db.deleteAsync.bind(db._db);
|
|
@@ -221,14 +242,19 @@ export function openDatabase(
|
|
|
221
242
|
export class ExpoSQLTransactionAsync implements SQLTransactionAsync {
|
|
222
243
|
constructor(private readonly db: SQLiteDatabase, private readonly readOnly: boolean) {}
|
|
223
244
|
|
|
224
|
-
async executeSqlAsync(
|
|
225
|
-
sqlStatement: string,
|
|
226
|
-
args?: (number | string)[]
|
|
227
|
-
): Promise<ResultSetError | ResultSet> {
|
|
245
|
+
async executeSqlAsync(sqlStatement: string, args?: (number | string)[]): Promise<ResultSet> {
|
|
228
246
|
const resultSets = await this.db.execAsync(
|
|
229
247
|
[{ sql: sqlStatement, args: args ?? [] }],
|
|
230
248
|
this.readOnly
|
|
231
249
|
);
|
|
232
|
-
|
|
250
|
+
const result = resultSets[0];
|
|
251
|
+
if (isResultSetError(result)) {
|
|
252
|
+
throw result.error;
|
|
253
|
+
}
|
|
254
|
+
return result;
|
|
233
255
|
}
|
|
234
256
|
}
|
|
257
|
+
|
|
258
|
+
function isResultSetError(result: ResultSet | ResultSetError): result is ResultSetError {
|
|
259
|
+
return 'error' in result;
|
|
260
|
+
}
|
package/src/SQLite.types.ts
CHANGED
|
@@ -185,10 +185,7 @@ export type SQLiteCallback = (
|
|
|
185
185
|
/** A transaction object to perform SQL statements in async mode. */
|
|
186
186
|
export interface SQLTransactionAsync {
|
|
187
187
|
/** Executes a SQL statement in async mode. */
|
|
188
|
-
executeSqlAsync(
|
|
189
|
-
sqlStatement: string,
|
|
190
|
-
args?: (number | string)[]
|
|
191
|
-
): Promise<ResultSetError | ResultSet>;
|
|
188
|
+
executeSqlAsync(sqlStatement: string, args?: (number | string)[]): Promise<ResultSet>;
|
|
192
189
|
}
|
|
193
190
|
|
|
194
191
|
/** A transaction callback with given `SQLTransactionAsync` object to perform SQL statements in async mode. */
|