expo-sqlite 11.5.0 → 11.7.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 +32 -0
- package/android/build.gradle +13 -8
- package/android/src/main/java/expo/modules/sqlite/SQLiteHelpers.kt +9 -1
- package/android/src/main/java/expo/modules/sqlite/SQLiteModule.kt +108 -23
- package/build/SQLite.d.ts +11 -1
- package/build/SQLite.d.ts.map +1 -1
- package/build/SQLite.js +28 -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/ios/CRSQLiteLoader.m +2 -1
- package/ios/ExpoSQLite.podspec +2 -3
- package/ios/SQLiteModule.swift +19 -16
- package/ios/crsqlite.xcframework/ios-arm64/crsqlite.framework/Info.plist +2 -0
- package/ios/crsqlite.xcframework/ios-arm64_x86_64-simulator/crsqlite.framework/Info.plist +2 -0
- package/package.json +2 -2
- package/src/SQLite.ts +39 -6
- package/src/SQLite.types.ts +1 -4
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,38 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 11.7.0 — 2023-09-15
|
|
14
|
+
|
|
15
|
+
### 🐛 Bug fixes
|
|
16
|
+
|
|
17
|
+
- [iOS] Fixed an issue with CRSQLite missing a minimum OS version on iOS, causing rejections on AppStore Connect submission. ([#24347](https://github.com/expo/expo/pull/24347) by [@derekstavis](https://github.com/derekstavis))
|
|
18
|
+
|
|
19
|
+
## 11.3.3 — 2023-09-08
|
|
20
|
+
|
|
21
|
+
### 🎉 New features
|
|
22
|
+
|
|
23
|
+
- Add support for running raw queries on Android. ([#24320](https://github.com/expo/expo/pull/24320) by [@alanjhughes](https://github.com/alanjhughes))
|
|
24
|
+
|
|
25
|
+
### 🐛 Bug fixes
|
|
26
|
+
|
|
27
|
+
- Fixed the return type from `executeSqlAsync` to only successful `ResultSet`. ([#24336](https://github.com/expo/expo/pull/24336) by [@kudo](https://github.com/kudo))
|
|
28
|
+
|
|
29
|
+
## 11.6.0 — 2023-09-04
|
|
30
|
+
|
|
31
|
+
### 🎉 New features
|
|
32
|
+
|
|
33
|
+
- Added support for React Native 0.73. ([#24018](https://github.com/expo/expo/pull/24018) by [@kudo](https://github.com/kudo))
|
|
34
|
+
|
|
35
|
+
### 🐛 Bug fixes
|
|
36
|
+
|
|
37
|
+
- [iOS] Fixed build error when mixing with iOS built-in SQLite3. ([#23885](https://github.com/expo/expo/pull/23885) by [@kudo](https://github.com/kudo))
|
|
38
|
+
- [Android] Fixed select queries with CTEs crashing on Android. ([#24132](https://github.com/expo/expo/pull/24132) by [@derekstavis](https://github.com/derekstavis))
|
|
39
|
+
|
|
40
|
+
### 💡 Others
|
|
41
|
+
|
|
42
|
+
- Remove unneeded resource bundle. ([#23813](https://github.com/expo/expo/pull/23813) by [@alanjhughes](https://github.com/alanjhughes))
|
|
43
|
+
- Update `SQLite` on `Android`. ([#23993](https://github.com/expo/expo/pull/23993) by [@alanjhughes](https://github.com/alanjhughes))
|
|
44
|
+
|
|
13
45
|
## 11.5.0 — 2023-08-02
|
|
14
46
|
|
|
15
47
|
_This version does not introduce any user-facing changes._
|
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.
|
|
6
|
+
version = '11.7.0'
|
|
7
7
|
|
|
8
8
|
buildscript {
|
|
9
9
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
@@ -53,13 +53,16 @@ afterEvaluate {
|
|
|
53
53
|
android {
|
|
54
54
|
compileSdkVersion safeExtGet("compileSdkVersion", 33)
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
|
|
57
|
+
if (agpVersion.tokenize('.')[0].toInteger() < 8) {
|
|
58
|
+
compileOptions {
|
|
59
|
+
sourceCompatibility JavaVersion.VERSION_11
|
|
60
|
+
targetCompatibility JavaVersion.VERSION_11
|
|
61
|
+
}
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
kotlinOptions {
|
|
64
|
+
jvmTarget = JavaVersion.VERSION_11.majorVersion
|
|
65
|
+
}
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
namespace "expo.modules.sqlite"
|
|
@@ -67,7 +70,7 @@ android {
|
|
|
67
70
|
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
68
71
|
targetSdkVersion safeExtGet("targetSdkVersion", 33)
|
|
69
72
|
versionCode 18
|
|
70
|
-
versionName "11.
|
|
73
|
+
versionName "11.7.0"
|
|
71
74
|
}
|
|
72
75
|
lintOptions {
|
|
73
76
|
abortOnError false
|
|
@@ -82,5 +85,7 @@ android {
|
|
|
82
85
|
dependencies {
|
|
83
86
|
implementation project(':expo-modules-core')
|
|
84
87
|
|
|
88
|
+
implementation 'com.github.requery:sqlite-android:3.39.2'
|
|
89
|
+
implementation "androidx.sqlite:sqlite-ktx:2.3.1"
|
|
85
90
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
|
|
86
91
|
}
|
|
@@ -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) {
|
|
@@ -3,7 +3,7 @@ package expo.modules.sqlite
|
|
|
3
3
|
|
|
4
4
|
import android.content.Context
|
|
5
5
|
import android.database.Cursor
|
|
6
|
-
import android.database.sqlite.SQLiteDatabase
|
|
6
|
+
import io.requery.android.database.sqlite.SQLiteDatabase
|
|
7
7
|
import expo.modules.kotlin.exception.Exceptions
|
|
8
8
|
import expo.modules.kotlin.modules.Module
|
|
9
9
|
import expo.modules.kotlin.modules.ModuleDefinition
|
|
@@ -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 ->
|
|
@@ -71,6 +57,32 @@ class SQLiteModule : Module() {
|
|
|
71
57
|
}
|
|
72
58
|
}
|
|
73
59
|
|
|
60
|
+
private fun execute(dbName: String, queries: List<Query>, readOnly: Boolean, raw: Boolean = false): List<Any> {
|
|
61
|
+
val db = getDatabase(dbName)
|
|
62
|
+
val results = queries.map { sqlQuery ->
|
|
63
|
+
val sql = sqlQuery.sql
|
|
64
|
+
val bindArgs = convertParamsToStringArray(sqlQuery.args)
|
|
65
|
+
try {
|
|
66
|
+
if (isSelect(sql)) {
|
|
67
|
+
doSelectInBackgroundAndPossiblyThrow(sql, bindArgs, db)
|
|
68
|
+
} else { // update/insert/delete
|
|
69
|
+
if (readOnly) {
|
|
70
|
+
SQLitePluginResult(EMPTY_ROWS, EMPTY_COLUMNS, 0, 0, ReadOnlyException())
|
|
71
|
+
} else {
|
|
72
|
+
if (raw) {
|
|
73
|
+
doRawUpdate(sql, bindArgs, db)
|
|
74
|
+
} else {
|
|
75
|
+
doUpdateInBackgroundAndPossiblyThrow(sql, bindArgs, db)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} catch (e: Throwable) {
|
|
80
|
+
SQLitePluginResult(EMPTY_ROWS, EMPTY_COLUMNS, 0, 0, e)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return pluginResultsToPrimitiveData(results)
|
|
84
|
+
}
|
|
85
|
+
|
|
74
86
|
// do a update/delete/insert operation
|
|
75
87
|
private fun doUpdateInBackgroundAndPossiblyThrow(
|
|
76
88
|
sql: String,
|
|
@@ -80,10 +92,11 @@ class SQLiteModule : Module() {
|
|
|
80
92
|
return db.compileStatement(sql).use { statement ->
|
|
81
93
|
if (bindArgs != null) {
|
|
82
94
|
for (i in bindArgs.size downTo 1) {
|
|
83
|
-
|
|
84
|
-
|
|
95
|
+
val args = bindArgs[i - 1]
|
|
96
|
+
if (args != null) {
|
|
97
|
+
statement.bindString(i, args)
|
|
85
98
|
} else {
|
|
86
|
-
statement.
|
|
99
|
+
statement.bindNull(i)
|
|
87
100
|
}
|
|
88
101
|
}
|
|
89
102
|
}
|
|
@@ -103,6 +116,78 @@ class SQLiteModule : Module() {
|
|
|
103
116
|
}
|
|
104
117
|
}
|
|
105
118
|
|
|
119
|
+
private fun doRawUpdate(
|
|
120
|
+
sql: String,
|
|
121
|
+
bindArgs: Array<String?>,
|
|
122
|
+
db: SQLiteDatabase
|
|
123
|
+
): SQLitePluginResult {
|
|
124
|
+
return db.rawQuery(sql, bindArgs).use { cursor ->
|
|
125
|
+
val numRows = cursor.count
|
|
126
|
+
if (numRows == 0) {
|
|
127
|
+
return EMPTY_RESULT
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
val numColumns = cursor.columnCount
|
|
131
|
+
val columnNames = cursor.columnNames
|
|
132
|
+
val rows: Array<Array<Any?>> = Array(numRows) { arrayOfNulls(numColumns) }
|
|
133
|
+
var i = 0
|
|
134
|
+
while (cursor.moveToNext()) {
|
|
135
|
+
val row = rows[i]
|
|
136
|
+
for (j in 0 until numColumns) {
|
|
137
|
+
row[j] = getValueFromCursor(cursor, j, cursor.getType(j))
|
|
138
|
+
}
|
|
139
|
+
rows[i] = row
|
|
140
|
+
i++
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (isInsert(sql)) {
|
|
144
|
+
val rowsAffected = getRowsAffected(db).let {
|
|
145
|
+
it.first.close()
|
|
146
|
+
it.second
|
|
147
|
+
}
|
|
148
|
+
val insertId = getInsertId(db).let {
|
|
149
|
+
it.first.close()
|
|
150
|
+
it.second
|
|
151
|
+
}
|
|
152
|
+
SQLitePluginResult(rows, columnNames, rowsAffected, insertId, null)
|
|
153
|
+
} else if (isDelete(sql) || isUpdate(sql)) {
|
|
154
|
+
val rowsAffected = getRowsAffected(db).let {
|
|
155
|
+
it.first.close()
|
|
156
|
+
it.second
|
|
157
|
+
}
|
|
158
|
+
SQLitePluginResult(rows, columnNames, rowsAffected, 0, null)
|
|
159
|
+
} else {
|
|
160
|
+
EMPTY_RESULT
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private fun getRowsAffected(
|
|
166
|
+
db: SQLiteDatabase,
|
|
167
|
+
): Pair<Cursor, Int> {
|
|
168
|
+
val cursor = db.rawQuery("SELECT changes() AS numRowsAffected", null)
|
|
169
|
+
val rowsAffected = if (cursor.moveToFirst()) {
|
|
170
|
+
val index = cursor.getColumnIndex("numRowsAffected")
|
|
171
|
+
cursor.getInt(index)
|
|
172
|
+
} else {
|
|
173
|
+
-1
|
|
174
|
+
}
|
|
175
|
+
return Pair(cursor, rowsAffected)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private fun getInsertId(
|
|
179
|
+
db: SQLiteDatabase,
|
|
180
|
+
): Pair<Cursor, Long> {
|
|
181
|
+
val cursor = db.rawQuery("SELECT last_insert_rowid() AS insertId", null)
|
|
182
|
+
val insertId = if (cursor.moveToFirst()) {
|
|
183
|
+
val index = cursor.getColumnIndex("insertId")
|
|
184
|
+
cursor.getLong(index)
|
|
185
|
+
} else {
|
|
186
|
+
-1
|
|
187
|
+
}
|
|
188
|
+
return Pair(cursor, insertId)
|
|
189
|
+
}
|
|
190
|
+
|
|
106
191
|
// do a select operation
|
|
107
192
|
private fun doSelectInBackgroundAndPossiblyThrow(
|
|
108
193
|
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
|
*/
|
|
@@ -30,6 +36,10 @@ export declare class SQLiteDatabase {
|
|
|
30
36
|
* > The database has to be closed prior to deletion.
|
|
31
37
|
*/
|
|
32
38
|
deleteAsync(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Used to listen to changes in the database.
|
|
41
|
+
* @param callback A function that receives the `tableName` and `rowId` of the modified data.
|
|
42
|
+
*/
|
|
33
43
|
onDatabaseChange(cb: (result: {
|
|
34
44
|
tableName: string;
|
|
35
45
|
rowId: number;
|
|
@@ -74,6 +84,6 @@ export declare class ExpoSQLTransactionAsync implements SQLTransactionAsync {
|
|
|
74
84
|
private readonly db;
|
|
75
85
|
private readonly readOnly;
|
|
76
86
|
constructor(db: SQLiteDatabase, readOnly: boolean);
|
|
77
|
-
executeSqlAsync(sqlStatement: string, args?: (number | string)[]): Promise<
|
|
87
|
+
executeSqlAsync(sqlStatement: string, args?: (number | string)[]): Promise<ResultSet>;
|
|
78
88
|
}
|
|
79
89
|
//# sourceMappingURL=SQLite.d.ts.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/build/SQLite.js
CHANGED
|
@@ -32,6 +32,21 @@ export class SQLiteDatabase {
|
|
|
32
32
|
callback(error instanceof Error ? error : new Error(error));
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Due to limitations on `Android` this function is provided to allow raw SQL queries to be
|
|
37
|
+
* executed on the database. This will be less efficient than using the `exec` function, please use
|
|
38
|
+
* only when necessary.
|
|
39
|
+
*/
|
|
40
|
+
execRawQuery(queries, readOnly, callback) {
|
|
41
|
+
if (Platform.OS === 'ios') {
|
|
42
|
+
return this.exec(queries, readOnly, callback);
|
|
43
|
+
}
|
|
44
|
+
ExpoSQLite.execRawQuery(this._name, queries.map(_serializeQuery), readOnly).then((nativeResultSets) => {
|
|
45
|
+
callback(null, nativeResultSets.map(_deserializeResultSet));
|
|
46
|
+
}, (error) => {
|
|
47
|
+
callback(error instanceof Error ? error : new Error(error));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
35
50
|
/**
|
|
36
51
|
* Executes the SQL statement and returns a Promise resolving with the result.
|
|
37
52
|
*/
|
|
@@ -70,6 +85,10 @@ export class SQLiteDatabase {
|
|
|
70
85
|
}
|
|
71
86
|
return ExpoSQLite.deleteAsync(this._name);
|
|
72
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Used to listen to changes in the database.
|
|
90
|
+
* @param callback A function that receives the `tableName` and `rowId` of the modified data.
|
|
91
|
+
*/
|
|
73
92
|
onDatabaseChange(cb) {
|
|
74
93
|
return emitter.addListener('onDatabaseChange', cb);
|
|
75
94
|
}
|
|
@@ -148,6 +167,7 @@ export function openDatabase(name, version = '1.0', description = name, size = 1
|
|
|
148
167
|
}
|
|
149
168
|
const db = _openExpoSQLiteDatabase(name, version, description, size, callback);
|
|
150
169
|
db.exec = db._db.exec.bind(db._db);
|
|
170
|
+
db.execRawQuery = db._db.execRawQuery.bind(db._db);
|
|
151
171
|
db.execAsync = db._db.execAsync.bind(db._db);
|
|
152
172
|
db.closeAsync = db._db.closeAsync.bind(db._db);
|
|
153
173
|
db.closeSync = db._db.closeSync.bind(db._db);
|
|
@@ -169,7 +189,14 @@ export class ExpoSQLTransactionAsync {
|
|
|
169
189
|
}
|
|
170
190
|
async executeSqlAsync(sqlStatement, args) {
|
|
171
191
|
const resultSets = await this.db.execAsync([{ sql: sqlStatement, args: args ?? [] }], this.readOnly);
|
|
172
|
-
|
|
192
|
+
const result = resultSets[0];
|
|
193
|
+
if (isResultSetError(result)) {
|
|
194
|
+
throw result.error;
|
|
195
|
+
}
|
|
196
|
+
return result;
|
|
173
197
|
}
|
|
174
198
|
}
|
|
199
|
+
function isResultSetError(result) {
|
|
200
|
+
return 'error' in result;
|
|
201
|
+
}
|
|
175
202
|
//# 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,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAaxC,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;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A0B;QAE1B,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,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;CACF","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 * 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 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.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(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,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAaxC,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;IAED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S,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,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"]}
|
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,CAA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AC9C,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/ios/CRSQLiteLoader.m
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Copyright 2015-present 650 Industries. All rights reserved.
|
|
2
2
|
|
|
3
|
-
#import
|
|
3
|
+
#import <ExpoSQLite/CRSQLiteLoader.h>
|
|
4
4
|
#import <sqlite3/sqlite3.h>
|
|
5
5
|
|
|
6
|
+
// This comes from the crsqlite.xcframework
|
|
6
7
|
int sqlite3_crsqlite_init(sqlite3 *db, char **pzErrMsg,
|
|
7
8
|
const sqlite3_api_routines *pApi);
|
|
8
9
|
|
package/ios/ExpoSQLite.podspec
CHANGED
|
@@ -13,10 +13,9 @@ Pod::Spec.new do |s|
|
|
|
13
13
|
s.platform = :ios, '13.0'
|
|
14
14
|
s.source = { git: 'https://github.com/expo/expo.git' }
|
|
15
15
|
s.static_framework = true
|
|
16
|
-
|
|
17
16
|
s.dependency 'ExpoModulesCore'
|
|
18
|
-
|
|
19
|
-
s.
|
|
17
|
+
# The builtin sqlite does not support extensions so we update it
|
|
18
|
+
s.dependency 'sqlite3', '3.39.2'
|
|
20
19
|
|
|
21
20
|
# Swift/Objective-C compatibility
|
|
22
21
|
s.pod_target_xcconfig = {
|
package/ios/SQLiteModule.swift
CHANGED
|
@@ -102,30 +102,33 @@ public final class SQLiteModule: Module {
|
|
|
102
102
|
db = cachedDatabases[dbName]
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
if db
|
|
106
|
-
|
|
105
|
+
if let db {
|
|
106
|
+
return db
|
|
107
|
+
}
|
|
107
108
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
cachedDatabases.removeValue(forKey: dbName)
|
|
110
|
+
|
|
111
|
+
if sqlite3_open(path.absoluteString, &db) != SQLITE_OK {
|
|
112
|
+
return nil
|
|
113
|
+
}
|
|
111
114
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
sqlite3_update_hook(
|
|
116
|
+
db, { (obj, action, _, tableName, rowId) in
|
|
117
|
+
if let obj, let tableName {
|
|
118
|
+
let selfObj = Unmanaged<SQLiteModule>.fromOpaque(obj).takeUnretainedValue()
|
|
119
|
+
if selfObj.hasListeners {
|
|
117
120
|
selfObj.sendEvent("onDatabaseChange", [
|
|
118
121
|
"tableName": String(cString: UnsafePointer(tableName)),
|
|
119
122
|
"rowId": rowId,
|
|
120
123
|
"typeId": SqlAction.fromCode(value: action)
|
|
121
124
|
])
|
|
122
125
|
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
selfPointer
|
|
129
|
+
)
|
|
126
130
|
|
|
127
|
-
|
|
128
|
-
}
|
|
131
|
+
cachedDatabases[dbName] = db
|
|
129
132
|
return db
|
|
130
133
|
}
|
|
131
134
|
|
|
@@ -247,7 +250,7 @@ public final class SQLiteModule: Module {
|
|
|
247
250
|
}
|
|
248
251
|
}
|
|
249
252
|
|
|
250
|
-
enum SqlAction:
|
|
253
|
+
enum SqlAction: String, Enumerable {
|
|
251
254
|
case insert
|
|
252
255
|
case delete
|
|
253
256
|
case update
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-sqlite",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.7.0",
|
|
4
4
|
"description": "Provides access to a database that can be queried through a WebSQL-like API (https://www.w3.org/TR/webdatabase/). The database is persisted across restarts of your app.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"expo": "*"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "ee2c866ba3c7fbc35ff2a3e896041cf15d3bd7c5"
|
|
48
48
|
}
|
package/src/SQLite.ts
CHANGED
|
@@ -54,6 +54,26 @@ export class SQLiteDatabase {
|
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Due to limitations on `Android` this function is provided to allow raw SQL queries to be
|
|
59
|
+
* executed on the database. This will be less efficient than using the `exec` function, please use
|
|
60
|
+
* only when necessary.
|
|
61
|
+
*/
|
|
62
|
+
execRawQuery(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void {
|
|
63
|
+
if (Platform.OS === 'ios') {
|
|
64
|
+
return this.exec(queries, readOnly, callback);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
ExpoSQLite.execRawQuery(this._name, queries.map(_serializeQuery), readOnly).then(
|
|
68
|
+
(nativeResultSets) => {
|
|
69
|
+
callback(null, nativeResultSets.map(_deserializeResultSet));
|
|
70
|
+
},
|
|
71
|
+
(error) => {
|
|
72
|
+
callback(error instanceof Error ? error : new Error(error));
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
57
77
|
/**
|
|
58
78
|
* Executes the SQL statement and returns a Promise resolving with the result.
|
|
59
79
|
*/
|
|
@@ -105,6 +125,10 @@ export class SQLiteDatabase {
|
|
|
105
125
|
return ExpoSQLite.deleteAsync(this._name);
|
|
106
126
|
}
|
|
107
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Used to listen to changes in the database.
|
|
130
|
+
* @param callback A function that receives the `tableName` and `rowId` of the modified data.
|
|
131
|
+
*/
|
|
108
132
|
onDatabaseChange(cb: (result: { tableName: string; rowId: number }) => void) {
|
|
109
133
|
return emitter.addListener('onDatabaseChange', cb);
|
|
110
134
|
}
|
|
@@ -220,6 +244,7 @@ export function openDatabase(
|
|
|
220
244
|
}
|
|
221
245
|
const db = _openExpoSQLiteDatabase(name, version, description, size, callback);
|
|
222
246
|
db.exec = db._db.exec.bind(db._db);
|
|
247
|
+
db.execRawQuery = db._db.execRawQuery.bind(db._db);
|
|
223
248
|
db.execAsync = db._db.execAsync.bind(db._db);
|
|
224
249
|
db.closeAsync = db._db.closeAsync.bind(db._db);
|
|
225
250
|
db.closeSync = db._db.closeSync.bind(db._db);
|
|
@@ -234,16 +259,24 @@ export function openDatabase(
|
|
|
234
259
|
* @internal
|
|
235
260
|
*/
|
|
236
261
|
export class ExpoSQLTransactionAsync implements SQLTransactionAsync {
|
|
237
|
-
constructor(
|
|
262
|
+
constructor(
|
|
263
|
+
private readonly db: SQLiteDatabase,
|
|
264
|
+
private readonly readOnly: boolean
|
|
265
|
+
) {}
|
|
238
266
|
|
|
239
|
-
async executeSqlAsync(
|
|
240
|
-
sqlStatement: string,
|
|
241
|
-
args?: (number | string)[]
|
|
242
|
-
): Promise<ResultSetError | ResultSet> {
|
|
267
|
+
async executeSqlAsync(sqlStatement: string, args?: (number | string)[]): Promise<ResultSet> {
|
|
243
268
|
const resultSets = await this.db.execAsync(
|
|
244
269
|
[{ sql: sqlStatement, args: args ?? [] }],
|
|
245
270
|
this.readOnly
|
|
246
271
|
);
|
|
247
|
-
|
|
272
|
+
const result = resultSets[0];
|
|
273
|
+
if (isResultSetError(result)) {
|
|
274
|
+
throw result.error;
|
|
275
|
+
}
|
|
276
|
+
return result;
|
|
248
277
|
}
|
|
249
278
|
}
|
|
279
|
+
|
|
280
|
+
function isResultSetError(result: ResultSet | ResultSetError): result is ResultSetError {
|
|
281
|
+
return 'error' in result;
|
|
282
|
+
}
|
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. */
|