expo-sqlite 13.0.0 → 13.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/android/build.gradle +2 -2
- package/android/src/main/cpp/NativeDatabaseBinding.cpp +4 -4
- package/android/src/main/cpp/NativeDatabaseBinding.h +2 -2
- package/android/src/main/cpp/NativeStatementBinding.cpp +6 -0
- package/android/src/main/cpp/NativeStatementBinding.h +1 -0
- package/android/src/main/java/expo/modules/sqlite/NativeDatabase.kt +1 -1
- package/android/src/main/java/expo/modules/sqlite/NativeDatabaseBinding.kt +4 -4
- package/android/src/main/java/expo/modules/sqlite/NativeStatementBinding.kt +5 -4
- package/android/src/main/java/expo/modules/sqlite/SQLiteModule.kt +21 -21
- package/android/src/main/java/expo/modules/sqlite/SQLiteModuleNext.kt +55 -68
- package/build/next/ExpoSQLiteNext.d.ts +4 -4
- package/build/next/ExpoSQLiteNext.d.ts.map +1 -1
- package/build/next/ExpoSQLiteNext.js +3 -3
- package/build/next/ExpoSQLiteNext.js.map +1 -1
- package/build/next/NativeDatabase.d.ts +3 -3
- package/build/next/NativeDatabase.d.ts.map +1 -1
- package/build/next/NativeDatabase.js.map +1 -1
- package/build/next/NativeStatement.d.ts +37 -31
- package/build/next/NativeStatement.d.ts.map +1 -1
- package/build/next/NativeStatement.js.map +1 -1
- package/build/next/SQLiteDatabase.d.ts +266 -0
- package/build/next/SQLiteDatabase.d.ts.map +1 -0
- package/build/next/{Database.js → SQLiteDatabase.js} +69 -59
- package/build/next/SQLiteDatabase.js.map +1 -0
- package/build/next/SQLiteStatement.d.ts +190 -0
- package/build/next/SQLiteStatement.d.ts.map +1 -0
- package/build/next/SQLiteStatement.js +275 -0
- package/build/next/SQLiteStatement.js.map +1 -0
- package/build/next/hooks.d.ts +26 -14
- package/build/next/hooks.d.ts.map +1 -1
- package/build/next/hooks.js +121 -33
- package/build/next/hooks.js.map +1 -1
- package/build/next/index.d.ts +2 -2
- package/build/next/index.d.ts.map +1 -1
- package/build/next/index.js +2 -2
- package/build/next/index.js.map +1 -1
- package/build/next/paramUtils.d.ts +18 -0
- package/build/next/paramUtils.d.ts.map +1 -0
- package/build/next/paramUtils.js +72 -0
- package/build/next/paramUtils.js.map +1 -0
- package/ios/NativeDatabase.swift +3 -3
- package/ios/SQLiteModule.swift +17 -17
- package/ios/SQLiteModuleNext.swift +56 -77
- package/package.json +4 -3
- package/src/next/ExpoSQLiteNext.ts +4 -4
- package/src/next/NativeDatabase.ts +3 -3
- package/src/next/NativeStatement.ts +39 -58
- package/src/next/{Database.ts → SQLiteDatabase.ts} +134 -112
- package/src/next/SQLiteStatement.ts +528 -0
- package/src/next/hooks.tsx +202 -51
- package/src/next/index.ts +2 -2
- package/src/next/paramUtils.ts +94 -0
- package/build/next/Database.d.ts +0 -272
- package/build/next/Database.d.ts.map +0 -1
- package/build/next/Database.js.map +0 -1
- package/build/next/Statement.d.ts +0 -140
- package/build/next/Statement.d.ts.map +0 -1
- package/build/next/Statement.js +0 -173
- package/build/next/Statement.js.map +0 -1
- package/src/next/Statement.ts +0 -315
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 13.1.0 — 2023-12-13
|
|
14
|
+
|
|
15
|
+
### 🛠 Breaking changes
|
|
16
|
+
|
|
17
|
+
- Refactor `expo-sqlite/next` API to be more React idiomatic. ([#25657](https://github.com/expo/expo/pull/25657) by [@kudo](https://github.com/kudo))
|
|
18
|
+
|
|
13
19
|
## 13.0.0 — 2023-12-12
|
|
14
20
|
|
|
15
21
|
### 🎉 New features
|
package/android/build.gradle
CHANGED
|
@@ -4,7 +4,7 @@ apply plugin: 'maven-publish'
|
|
|
4
4
|
apply plugin: 'de.undercouch.download'
|
|
5
5
|
|
|
6
6
|
group = 'host.exp.exponent'
|
|
7
|
-
version = '13.
|
|
7
|
+
version = '13.1.0'
|
|
8
8
|
|
|
9
9
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
10
10
|
if (expoModulesCorePlugin.exists()) {
|
|
@@ -106,7 +106,7 @@ android {
|
|
|
106
106
|
namespace "expo.modules.sqlite"
|
|
107
107
|
defaultConfig {
|
|
108
108
|
versionCode 18
|
|
109
|
-
versionName "13.
|
|
109
|
+
versionName "13.1.0"
|
|
110
110
|
|
|
111
111
|
externalNativeBuild {
|
|
112
112
|
cmake {
|
|
@@ -49,8 +49,8 @@ int NativeDatabaseBinding::sqlite3_close() {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
std::string
|
|
52
|
-
NativeDatabaseBinding::sqlite3_db_filename(const std::string &
|
|
53
|
-
return ::sqlite3_db_filename(db,
|
|
52
|
+
NativeDatabaseBinding::sqlite3_db_filename(const std::string &databaseName) {
|
|
53
|
+
return ::sqlite3_db_filename(db, databaseName.c_str());
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
int NativeDatabaseBinding::sqlite3_enable_load_extension(int onoff) {
|
|
@@ -128,14 +128,14 @@ NativeDatabaseBinding::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
|
128
128
|
|
|
129
129
|
// static
|
|
130
130
|
void NativeDatabaseBinding::OnUpdateHook(void *arg, int action,
|
|
131
|
-
char const *
|
|
131
|
+
char const *databaseName,
|
|
132
132
|
char const *tableName,
|
|
133
133
|
sqlite3_int64 rowId) {
|
|
134
134
|
NativeDatabaseBinding *pThis = reinterpret_cast<NativeDatabaseBinding *>(arg);
|
|
135
135
|
static const auto method =
|
|
136
136
|
jni::findClassStatic("expo/modules/sqlite/NativeDatabaseBinding")
|
|
137
137
|
->getMethod<void(jint, jstring, jstring, jlong)>("onUpdate");
|
|
138
|
-
method(pThis->javaPart_, action, jni::make_jstring(
|
|
138
|
+
method(pThis->javaPart_, action, jni::make_jstring(databaseName).get(),
|
|
139
139
|
jni::make_jstring(tableName).get(), rowId);
|
|
140
140
|
}
|
|
141
141
|
|
|
@@ -22,7 +22,7 @@ public:
|
|
|
22
22
|
// sqlite3 bindings
|
|
23
23
|
int sqlite3_changes();
|
|
24
24
|
int sqlite3_close();
|
|
25
|
-
std::string sqlite3_db_filename(const std::string &
|
|
25
|
+
std::string sqlite3_db_filename(const std::string &databaseName);
|
|
26
26
|
int sqlite3_enable_load_extension(int onoff);
|
|
27
27
|
int sqlite3_exec(const std::string &source);
|
|
28
28
|
int sqlite3_get_autocommit();
|
|
@@ -47,7 +47,7 @@ private:
|
|
|
47
47
|
static jni::local_ref<jhybriddata>
|
|
48
48
|
initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
49
49
|
|
|
50
|
-
static void OnUpdateHook(void *arg, int action, char const *
|
|
50
|
+
static void OnUpdateHook(void *arg, int action, char const *databaseName,
|
|
51
51
|
char const *tableName, sqlite3_int64 rowId);
|
|
52
52
|
|
|
53
53
|
private:
|
|
@@ -20,6 +20,8 @@ void NativeStatementBinding::registerNatives() {
|
|
|
20
20
|
makeNativeMethod("initHybrid", NativeStatementBinding::initHybrid),
|
|
21
21
|
makeNativeMethod("sqlite3_bind_parameter_index",
|
|
22
22
|
NativeStatementBinding::sqlite3_bind_parameter_index),
|
|
23
|
+
makeNativeMethod("sqlite3_clear_bindings",
|
|
24
|
+
NativeStatementBinding::sqlite3_clear_bindings),
|
|
23
25
|
makeNativeMethod("sqlite3_column_count",
|
|
24
26
|
NativeStatementBinding::sqlite3_column_count),
|
|
25
27
|
makeNativeMethod("sqlite3_column_name",
|
|
@@ -42,6 +44,10 @@ int NativeStatementBinding::sqlite3_bind_parameter_index(
|
|
|
42
44
|
return ::sqlite3_bind_parameter_index(stmt, name.c_str());
|
|
43
45
|
}
|
|
44
46
|
|
|
47
|
+
int NativeStatementBinding::sqlite3_clear_bindings() {
|
|
48
|
+
return ::sqlite3_clear_bindings(stmt);
|
|
49
|
+
}
|
|
50
|
+
|
|
45
51
|
int NativeStatementBinding::sqlite3_column_count() {
|
|
46
52
|
return ::sqlite3_column_count(stmt);
|
|
47
53
|
}
|
|
@@ -4,7 +4,7 @@ package expo.modules.sqlite
|
|
|
4
4
|
|
|
5
5
|
import expo.modules.kotlin.sharedobjects.SharedRef
|
|
6
6
|
|
|
7
|
-
internal class NativeDatabase(val
|
|
7
|
+
internal class NativeDatabase(val databaseName: String, val openOptions: OpenDatabaseOptions) : SharedRef<NativeDatabaseBinding>(NativeDatabaseBinding()) {
|
|
8
8
|
var isClosed = false
|
|
9
9
|
|
|
10
10
|
override fun equals(other: Any?): Boolean {
|
|
@@ -5,7 +5,7 @@ package expo.modules.sqlite
|
|
|
5
5
|
import com.facebook.jni.HybridData
|
|
6
6
|
import expo.modules.core.interfaces.DoNotStrip
|
|
7
7
|
|
|
8
|
-
private typealias UpdateListener = (
|
|
8
|
+
private typealias UpdateListener = (databaseName: String, tableName: String, operationType: Int, rowID: Long) -> Unit
|
|
9
9
|
|
|
10
10
|
@Suppress("KotlinJniMissingFunction")
|
|
11
11
|
@DoNotStrip
|
|
@@ -39,7 +39,7 @@ internal class NativeDatabaseBinding {
|
|
|
39
39
|
|
|
40
40
|
external fun sqlite3_changes(): Int
|
|
41
41
|
external fun sqlite3_close(): Int
|
|
42
|
-
external fun sqlite3_db_filename(
|
|
42
|
+
external fun sqlite3_db_filename(databaseName: String): String
|
|
43
43
|
external fun sqlite3_enable_load_extension(onoff: Int): Int
|
|
44
44
|
external fun sqlite3_exec(source: String): Int
|
|
45
45
|
external fun sqlite3_get_autocommit(): Int
|
|
@@ -59,8 +59,8 @@ internal class NativeDatabaseBinding {
|
|
|
59
59
|
|
|
60
60
|
@Suppress("unused")
|
|
61
61
|
@DoNotStrip
|
|
62
|
-
private fun onUpdate(action: Int,
|
|
63
|
-
mUpdateListener?.invoke(
|
|
62
|
+
private fun onUpdate(action: Int, databaseName: String, tableName: String, rowId: Long) {
|
|
63
|
+
mUpdateListener?.invoke(databaseName, tableName, action, rowId)
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
// endregion
|
|
@@ -5,8 +5,8 @@ package expo.modules.sqlite
|
|
|
5
5
|
import com.facebook.jni.HybridData
|
|
6
6
|
import expo.modules.core.interfaces.DoNotStrip
|
|
7
7
|
|
|
8
|
-
internal typealias
|
|
9
|
-
internal typealias
|
|
8
|
+
internal typealias SQLiteColumnNames = ArrayList<String>
|
|
9
|
+
internal typealias SQLiteColumnValues = ArrayList<Any>
|
|
10
10
|
|
|
11
11
|
@Suppress("KotlinJniMissingFunction")
|
|
12
12
|
@DoNotStrip
|
|
@@ -21,6 +21,7 @@ internal class NativeStatementBinding {
|
|
|
21
21
|
// region sqlite3 bindings
|
|
22
22
|
|
|
23
23
|
external fun sqlite3_bind_parameter_index(name: String): Int
|
|
24
|
+
external fun sqlite3_clear_bindings(): Int
|
|
24
25
|
external fun sqlite3_column_count(): Int
|
|
25
26
|
external fun sqlite3_column_name(index: Int): String
|
|
26
27
|
external fun sqlite3_finalize(): Int
|
|
@@ -28,8 +29,8 @@ internal class NativeStatementBinding {
|
|
|
28
29
|
external fun sqlite3_step(): Int
|
|
29
30
|
|
|
30
31
|
external fun bindStatementParam(index: Int, param: Any): Int
|
|
31
|
-
external fun getColumnNames():
|
|
32
|
-
external fun getColumnValues():
|
|
32
|
+
external fun getColumnNames(): SQLiteColumnNames
|
|
33
|
+
external fun getColumnValues(): SQLiteColumnValues
|
|
33
34
|
|
|
34
35
|
// endregion
|
|
35
36
|
|
|
@@ -19,36 +19,36 @@ class SQLiteModule : Module() {
|
|
|
19
19
|
override fun definition() = ModuleDefinition {
|
|
20
20
|
Name("ExpoSQLite")
|
|
21
21
|
|
|
22
|
-
AsyncFunction("exec") {
|
|
23
|
-
return@AsyncFunction execute(
|
|
22
|
+
AsyncFunction("exec") { databaseName: String, queries: List<Query>, readOnly: Boolean ->
|
|
23
|
+
return@AsyncFunction execute(databaseName, queries, readOnly)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
AsyncFunction("execRawQuery") {
|
|
27
|
-
return@AsyncFunction execute(
|
|
26
|
+
AsyncFunction("execRawQuery") { databaseName: String, queries: List<Query>, readOnly: Boolean ->
|
|
27
|
+
return@AsyncFunction execute(databaseName, queries, readOnly)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
AsyncFunction("close") {
|
|
30
|
+
AsyncFunction("close") { databaseName: String ->
|
|
31
31
|
cachedDatabase
|
|
32
|
-
.remove(
|
|
32
|
+
.remove(databaseName)
|
|
33
33
|
?.sqlite3_close()
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
Function("closeSync") {
|
|
36
|
+
Function("closeSync") { databaseName: String ->
|
|
37
37
|
cachedDatabase
|
|
38
|
-
.remove(
|
|
38
|
+
.remove(databaseName)
|
|
39
39
|
?.sqlite3_close()
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
AsyncFunction("deleteAsync") {
|
|
43
|
-
if (cachedDatabase[
|
|
44
|
-
throw DeleteDatabaseException(
|
|
42
|
+
AsyncFunction("deleteAsync") { databaseName: String ->
|
|
43
|
+
if (cachedDatabase[databaseName] != null) {
|
|
44
|
+
throw DeleteDatabaseException(databaseName)
|
|
45
45
|
}
|
|
46
|
-
val dbFile = File(pathForDatabaseName(
|
|
46
|
+
val dbFile = File(pathForDatabaseName(databaseName))
|
|
47
47
|
if (!dbFile.exists()) {
|
|
48
|
-
throw DatabaseNotFoundException(
|
|
48
|
+
throw DatabaseNotFoundException(databaseName)
|
|
49
49
|
}
|
|
50
50
|
if (!dbFile.delete()) {
|
|
51
|
-
throw DeleteDatabaseFileException(
|
|
51
|
+
throw DeleteDatabaseFileException(databaseName)
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -66,28 +66,28 @@ class SQLiteModule : Module() {
|
|
|
66
66
|
return "$directory${File.separator}$name"
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
private fun openDatabase(
|
|
69
|
+
private fun openDatabase(databaseName: String): SQLite3Wrapper? {
|
|
70
70
|
val path: String
|
|
71
71
|
try {
|
|
72
|
-
path = pathForDatabaseName(
|
|
72
|
+
path = pathForDatabaseName(databaseName)
|
|
73
73
|
} catch (_: IOException) {
|
|
74
74
|
return null
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
if (File(path).exists()) {
|
|
78
|
-
cachedDatabase[
|
|
78
|
+
cachedDatabase[databaseName]?.let {
|
|
79
79
|
return it
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
cachedDatabase.remove(
|
|
83
|
+
cachedDatabase.remove(databaseName)
|
|
84
84
|
val db = SQLite3Wrapper.open(path) ?: return null
|
|
85
|
-
cachedDatabase[
|
|
85
|
+
cachedDatabase[databaseName] = db
|
|
86
86
|
return db
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
private fun execute(
|
|
90
|
-
val db = openDatabase(
|
|
89
|
+
private fun execute(databaseName: String, queries: List<Query>, readOnly: Boolean): List<Any> {
|
|
90
|
+
val db = openDatabase(databaseName) ?: throw OpenDatabaseException(databaseName)
|
|
91
91
|
return queries.map { db.executeSql(it.sql, it.args, readOnly) }
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -43,25 +43,25 @@ class SQLiteModuleNext : Module() {
|
|
|
43
43
|
} catch (_: Throwable) {}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
AsyncFunction("deleteDatabaseAsync") {
|
|
47
|
-
deleteDatabase(
|
|
46
|
+
AsyncFunction("deleteDatabaseAsync") { databaseName: String ->
|
|
47
|
+
deleteDatabase(databaseName)
|
|
48
48
|
}
|
|
49
|
-
Function("deleteDatabaseSync") {
|
|
50
|
-
deleteDatabase(
|
|
49
|
+
Function("deleteDatabaseSync") { databaseName: String ->
|
|
50
|
+
deleteDatabase(databaseName)
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
Class(NativeDatabase::class) {
|
|
54
|
-
Constructor {
|
|
55
|
-
val dbPath = pathForDatabaseName(
|
|
54
|
+
Constructor { databaseName: String, options: OpenDatabaseOptions ->
|
|
55
|
+
val dbPath = pathForDatabaseName(databaseName)
|
|
56
56
|
|
|
57
57
|
// Try to find opened database for fast refresh
|
|
58
|
-
findCachedDatabase { it.
|
|
58
|
+
findCachedDatabase { it.databaseName == databaseName && it.openOptions == options && !options.useNewConnection }?.let {
|
|
59
59
|
return@Constructor it
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
val database = NativeDatabase(
|
|
62
|
+
val database = NativeDatabase(databaseName, options)
|
|
63
63
|
if (database.ref.sqlite3_open(dbPath) != NativeDatabaseBinding.SQLITE_OK) {
|
|
64
|
-
throw OpenDatabaseException(
|
|
64
|
+
throw OpenDatabaseException(databaseName)
|
|
65
65
|
}
|
|
66
66
|
addCachedDatabase(database)
|
|
67
67
|
return@Constructor database
|
|
@@ -119,18 +119,25 @@ class SQLiteModuleNext : Module() {
|
|
|
119
119
|
return@Function run(statement, database, bindParams, bindBlobParams, shouldPassAsArray)
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
AsyncFunction("
|
|
123
|
-
return@AsyncFunction
|
|
122
|
+
AsyncFunction("stepAsync") { statement: NativeStatement, database: NativeDatabase ->
|
|
123
|
+
return@AsyncFunction step(statement, database)
|
|
124
124
|
}
|
|
125
|
-
Function("
|
|
126
|
-
return@Function
|
|
125
|
+
Function("stepSync") { statement: NativeStatement, database: NativeDatabase ->
|
|
126
|
+
return@Function step(statement, database)
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
AsyncFunction("getAllAsync") { statement: NativeStatement, database: NativeDatabase
|
|
130
|
-
return@AsyncFunction getAll(statement, database
|
|
129
|
+
AsyncFunction("getAllAsync") { statement: NativeStatement, database: NativeDatabase ->
|
|
130
|
+
return@AsyncFunction getAll(statement, database)
|
|
131
131
|
}
|
|
132
|
-
Function("getAllSync") { statement: NativeStatement, database: NativeDatabase
|
|
133
|
-
return@Function getAll(statement, database
|
|
132
|
+
Function("getAllSync") { statement: NativeStatement, database: NativeDatabase ->
|
|
133
|
+
return@Function getAll(statement, database)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
AsyncFunction("resetAsync") { statement: NativeStatement, database: NativeDatabase ->
|
|
137
|
+
return@AsyncFunction reset(statement, database)
|
|
138
|
+
}
|
|
139
|
+
Function("resetSync") { statement: NativeStatement, database: NativeDatabase ->
|
|
140
|
+
return@Function reset(statement, database)
|
|
134
141
|
}
|
|
135
142
|
|
|
136
143
|
AsyncFunction("getColumnNamesAsync") { statement: NativeStatement ->
|
|
@@ -142,13 +149,6 @@ class SQLiteModuleNext : Module() {
|
|
|
142
149
|
return@Function statement.ref.getColumnNames()
|
|
143
150
|
}
|
|
144
151
|
|
|
145
|
-
AsyncFunction("resetAsync") { statement: NativeStatement, database: NativeDatabase ->
|
|
146
|
-
return@AsyncFunction reset(statement, database)
|
|
147
|
-
}
|
|
148
|
-
Function("resetSync") { statement: NativeStatement, database: NativeDatabase ->
|
|
149
|
-
return@Function reset(statement, database)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
152
|
AsyncFunction("finalizeAsync") { statement: NativeStatement, database: NativeDatabase ->
|
|
153
153
|
return@AsyncFunction finalize(statement, database)
|
|
154
154
|
}
|
|
@@ -193,18 +193,27 @@ class SQLiteModuleNext : Module() {
|
|
|
193
193
|
private fun prepareStatement(database: NativeDatabase, statement: NativeStatement, source: String) {
|
|
194
194
|
maybeThrowForClosedDatabase(database)
|
|
195
195
|
maybeThrowForFinalizedStatement(statement)
|
|
196
|
-
database.ref.sqlite3_prepare_v2(source, statement.ref)
|
|
196
|
+
if (database.ref.sqlite3_prepare_v2(source, statement.ref) != NativeDatabaseBinding.SQLITE_OK) {
|
|
197
|
+
throw SQLiteErrorException(database.ref.convertSqlLiteErrorToString())
|
|
198
|
+
}
|
|
197
199
|
maybeAddCachedStatement(database, statement)
|
|
198
200
|
}
|
|
199
201
|
|
|
200
202
|
@Throws(AccessClosedResourceException::class, SQLiteErrorException::class)
|
|
201
|
-
private fun run(statement: NativeStatement, database: NativeDatabase, bindParams: Map<String, Any>, bindBlobParams: Map<String, ByteArray>, shouldPassAsArray: Boolean): Map<String,
|
|
203
|
+
private fun run(statement: NativeStatement, database: NativeDatabase, bindParams: Map<String, Any>, bindBlobParams: Map<String, ByteArray>, shouldPassAsArray: Boolean): Map<String, Any> {
|
|
202
204
|
maybeThrowForClosedDatabase(database)
|
|
203
205
|
maybeThrowForFinalizedStatement(statement)
|
|
206
|
+
statement.ref.sqlite3_reset()
|
|
207
|
+
statement.ref.sqlite3_clear_bindings()
|
|
204
208
|
for ((key, param) in bindParams) {
|
|
205
209
|
val index = getBindParamIndex(statement, key, shouldPassAsArray)
|
|
206
210
|
if (index > 0) {
|
|
207
|
-
|
|
211
|
+
// expo-modules-core AnyTypeConverter casts JavaScript Number to Kotlin Double,
|
|
212
|
+
// here to cast as Long if the value is an integer.
|
|
213
|
+
val normalizedParam =
|
|
214
|
+
if (param is Double && param.toDouble() % 1.0 == 0.0) param.toLong()
|
|
215
|
+
else param
|
|
216
|
+
statement.ref.bindStatementParam(index, normalizedParam)
|
|
208
217
|
}
|
|
209
218
|
}
|
|
210
219
|
for ((key, param) in bindBlobParams) {
|
|
@@ -218,29 +227,20 @@ class SQLiteModuleNext : Module() {
|
|
|
218
227
|
if (ret != NativeDatabaseBinding.SQLITE_ROW && ret != NativeDatabaseBinding.SQLITE_DONE) {
|
|
219
228
|
throw SQLiteErrorException(database.ref.convertSqlLiteErrorToString())
|
|
220
229
|
}
|
|
230
|
+
val firstRowValues: SQLiteColumnValues =
|
|
231
|
+
if (ret == NativeDatabaseBinding.SQLITE_ROW) statement.ref.getColumnValues()
|
|
232
|
+
else arrayListOf()
|
|
221
233
|
return mapOf(
|
|
222
|
-
"
|
|
234
|
+
"lastInsertRowId" to database.ref.sqlite3_last_insert_rowid().toInt(),
|
|
223
235
|
"changes" to database.ref.sqlite3_changes(),
|
|
236
|
+
"firstRowValues" to firstRowValues,
|
|
224
237
|
)
|
|
225
238
|
}
|
|
226
239
|
|
|
227
240
|
@Throws(AccessClosedResourceException::class, InvalidConvertibleException::class, SQLiteErrorException::class)
|
|
228
|
-
private fun
|
|
241
|
+
private fun step(statement: NativeStatement, database: NativeDatabase): SQLiteColumnValues? {
|
|
229
242
|
maybeThrowForClosedDatabase(database)
|
|
230
243
|
maybeThrowForFinalizedStatement(statement)
|
|
231
|
-
for ((key, param) in bindParams) {
|
|
232
|
-
val index = getBindParamIndex(statement, key, shouldPassAsArray)
|
|
233
|
-
if (index > 0) {
|
|
234
|
-
statement.ref.bindStatementParam(index, param)
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
for ((key, param) in bindBlobParams) {
|
|
238
|
-
val index = getBindParamIndex(statement, key, shouldPassAsArray)
|
|
239
|
-
if (index > 0) {
|
|
240
|
-
statement.ref.bindStatementParam(index, param)
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
244
|
val ret = statement.ref.sqlite3_step()
|
|
245
245
|
if (ret == NativeDatabaseBinding.SQLITE_ROW) {
|
|
246
246
|
return statement.ref.getColumnValues()
|
|
@@ -252,23 +252,10 @@ class SQLiteModuleNext : Module() {
|
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
@Throws(AccessClosedResourceException::class, InvalidConvertibleException::class, SQLiteErrorException::class)
|
|
255
|
-
private fun getAll(statement: NativeStatement, database: NativeDatabase
|
|
255
|
+
private fun getAll(statement: NativeStatement, database: NativeDatabase): List<SQLiteColumnValues> {
|
|
256
256
|
maybeThrowForClosedDatabase(database)
|
|
257
257
|
maybeThrowForFinalizedStatement(statement)
|
|
258
|
-
|
|
259
|
-
val index = getBindParamIndex(statement, key, shouldPassAsArray)
|
|
260
|
-
if (index > 0) {
|
|
261
|
-
statement.ref.bindStatementParam(index, param)
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
for ((key, param) in bindBlobParams) {
|
|
265
|
-
val index = getBindParamIndex(statement, key, shouldPassAsArray)
|
|
266
|
-
if (index > 0) {
|
|
267
|
-
statement.ref.bindStatementParam(index, param)
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
val columnValuesList = mutableListOf<ColumnValues>()
|
|
258
|
+
val columnValuesList = mutableListOf<SQLiteColumnValues>()
|
|
272
259
|
while (true) {
|
|
273
260
|
val ret = statement.ref.sqlite3_step()
|
|
274
261
|
if (ret == NativeDatabaseBinding.SQLITE_ROW) {
|
|
@@ -315,16 +302,16 @@ class SQLiteModuleNext : Module() {
|
|
|
315
302
|
}
|
|
316
303
|
|
|
317
304
|
private fun addUpdateHook(database: NativeDatabase) {
|
|
318
|
-
database.ref.enableUpdateHook {
|
|
305
|
+
database.ref.enableUpdateHook { databaseName, tableName, operationType, rowID ->
|
|
319
306
|
if (!hasListeners) {
|
|
320
307
|
return@enableUpdateHook
|
|
321
308
|
}
|
|
322
|
-
val
|
|
309
|
+
val databaseFilePath = database.ref.sqlite3_db_filename(databaseName)
|
|
323
310
|
sendEvent(
|
|
324
311
|
"onDatabaseChange",
|
|
325
312
|
bundleOf(
|
|
326
|
-
"
|
|
327
|
-
"
|
|
313
|
+
"databaseName" to databaseName,
|
|
314
|
+
"databaseFilePath" to databaseFilePath,
|
|
328
315
|
"tableName" to tableName,
|
|
329
316
|
"rowId" to rowID,
|
|
330
317
|
"typeId" to SQLAction.fromCode(operationType).value,
|
|
@@ -349,20 +336,20 @@ class SQLiteModuleNext : Module() {
|
|
|
349
336
|
database.isClosed = true
|
|
350
337
|
}
|
|
351
338
|
|
|
352
|
-
private fun deleteDatabase(
|
|
353
|
-
findCachedDatabase { it.
|
|
354
|
-
throw DeleteDatabaseException(
|
|
339
|
+
private fun deleteDatabase(databaseName: String) {
|
|
340
|
+
findCachedDatabase { it.databaseName == databaseName }?.let {
|
|
341
|
+
throw DeleteDatabaseException(databaseName)
|
|
355
342
|
}
|
|
356
343
|
|
|
357
|
-
if (
|
|
344
|
+
if (databaseName == MEMORY_DB_NAME) {
|
|
358
345
|
return
|
|
359
346
|
}
|
|
360
|
-
val dbFile = File(pathForDatabaseName(
|
|
347
|
+
val dbFile = File(pathForDatabaseName(databaseName))
|
|
361
348
|
if (!dbFile.exists()) {
|
|
362
|
-
throw DatabaseNotFoundException(
|
|
349
|
+
throw DatabaseNotFoundException(databaseName)
|
|
363
350
|
}
|
|
364
351
|
if (!dbFile.delete()) {
|
|
365
|
-
throw DeleteDatabaseFileException(
|
|
352
|
+
throw DeleteDatabaseFileException(databaseName)
|
|
366
353
|
}
|
|
367
354
|
}
|
|
368
355
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SQLiteOpenOptions } from './NativeDatabase';
|
|
2
2
|
declare const _default: {
|
|
3
3
|
readonly name: string;
|
|
4
|
-
NativeDatabase(
|
|
4
|
+
NativeDatabase(databaseName: string, options?: SQLiteOpenOptions): void;
|
|
5
5
|
NativeStatement(): void;
|
|
6
|
-
deleteDatabaseAsync(
|
|
7
|
-
deleteDatabaseSync(
|
|
6
|
+
deleteDatabaseAsync(databaseName: string): Promise<void>;
|
|
7
|
+
deleteDatabaseSync(databaseName: string): void;
|
|
8
8
|
addListener(): never;
|
|
9
9
|
removeListeners(): never;
|
|
10
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoSQLiteNext.d.ts","sourceRoot":"","sources":["../../src/next/ExpoSQLiteNext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ExpoSQLiteNext.d.ts","sourceRoot":"","sources":["../../src/next/ExpoSQLiteNext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;;;iCAOtB,MAAM,YAAY,iBAAiB,GAAG,IAAI;uBAIpD,IAAI;sCAIiB,MAAM,GAAG,QAAQ,IAAI,CAAC;qCAI7B,MAAM,GAAG,IAAI;;;;AAjBhD,wBA+BE"}
|
|
@@ -2,16 +2,16 @@ export default {
|
|
|
2
2
|
get name() {
|
|
3
3
|
return 'ExpoSQLiteNext';
|
|
4
4
|
},
|
|
5
|
-
NativeDatabase(
|
|
5
|
+
NativeDatabase(databaseName, options) {
|
|
6
6
|
throw new Error('Unimplemented');
|
|
7
7
|
},
|
|
8
8
|
NativeStatement() {
|
|
9
9
|
throw new Error('Unimplemented');
|
|
10
10
|
},
|
|
11
|
-
async deleteDatabaseAsync(
|
|
11
|
+
async deleteDatabaseAsync(databaseName) {
|
|
12
12
|
throw new Error('Unimplemented');
|
|
13
13
|
},
|
|
14
|
-
deleteDatabaseSync(
|
|
14
|
+
deleteDatabaseSync(databaseName) {
|
|
15
15
|
throw new Error('Unimplemented');
|
|
16
16
|
},
|
|
17
17
|
//#region EventEmitter implementations
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoSQLiteNext.js","sourceRoot":"","sources":["../../src/next/ExpoSQLiteNext.ts"],"names":[],"mappings":"AAEA,eAAe;IACb,IAAI,IAAI;QACN,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"ExpoSQLiteNext.js","sourceRoot":"","sources":["../../src/next/ExpoSQLiteNext.ts"],"names":[],"mappings":"AAEA,eAAe;IACb,IAAI,IAAI;QACN,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED,cAAc,CAAC,YAAoB,EAAE,OAA2B;QAC9D,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED,eAAe;QACb,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,YAAoB;QAC5C,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED,kBAAkB,CAAC,YAAoB;QACrC,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED,sCAAsC;IAEtC,WAAW;QACT,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IACD,eAAe;QACb,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED,YAAY;CACb,CAAC","sourcesContent":["import { SQLiteOpenOptions } from './NativeDatabase';\n\nexport default {\n get name(): string {\n return 'ExpoSQLiteNext';\n },\n\n NativeDatabase(databaseName: string, options?: SQLiteOpenOptions): void {\n throw new Error('Unimplemented');\n },\n\n NativeStatement(): void {\n throw new Error('Unimplemented');\n },\n\n async deleteDatabaseAsync(databaseName: string): Promise<void> {\n throw new Error('Unimplemented');\n },\n\n deleteDatabaseSync(databaseName: string): void {\n throw new Error('Unimplemented');\n },\n\n //#region EventEmitter implementations\n\n addListener() {\n throw new Error('Unimplemented');\n },\n removeListeners() {\n throw new Error('Unimplemented');\n },\n\n //#endregion\n};\n"]}
|
|
@@ -3,7 +3,7 @@ import { NativeStatement } from './NativeStatement';
|
|
|
3
3
|
* A class that represents an instance of the SQLite database.
|
|
4
4
|
*/
|
|
5
5
|
export declare class NativeDatabase {
|
|
6
|
-
constructor(
|
|
6
|
+
constructor(databaseName: string, options?: SQLiteOpenOptions);
|
|
7
7
|
initAsync(): Promise<void>;
|
|
8
8
|
isInTransactionAsync(): Promise<boolean>;
|
|
9
9
|
closeAsync(): Promise<void>;
|
|
@@ -18,14 +18,14 @@ export declare class NativeDatabase {
|
|
|
18
18
|
/**
|
|
19
19
|
* Options for opening a database.
|
|
20
20
|
*/
|
|
21
|
-
export interface
|
|
21
|
+
export interface SQLiteOpenOptions {
|
|
22
22
|
/**
|
|
23
23
|
* Whether to enable the CR-SQLite extension.
|
|
24
24
|
* @default false
|
|
25
25
|
*/
|
|
26
26
|
enableCRSQLite?: boolean;
|
|
27
27
|
/**
|
|
28
|
-
* Whether to call the [`sqlite3_update_hook`](https://www.sqlite.org/c3ref/update_hook.html) function and enable the `onDatabaseChange` events. You can later subscribe to the change events by [`addDatabaseChangeListener`](#sqliteadddatabasechangelistenerlistener).
|
|
28
|
+
* Whether to call the [`sqlite3_update_hook()`](https://www.sqlite.org/c3ref/update_hook.html) function and enable the `onDatabaseChange` events. You can later subscribe to the change events by [`addDatabaseChangeListener`](#sqliteadddatabasechangelistenerlistener).
|
|
29
29
|
* @default false
|
|
30
30
|
*/
|
|
31
31
|
enableChangeListener?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeDatabase.d.ts","sourceRoot":"","sources":["../../src/next/NativeDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,cAAc;gBACrB,
|
|
1
|
+
{"version":3,"file":"NativeDatabase.d.ts","sourceRoot":"","sources":["../../src/next/NativeDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,cAAc;gBACrB,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB;IAItD,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAC1B,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC;IACxC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAC3B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IACxC,YAAY,CAAC,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAMxF,QAAQ,IAAI,IAAI;IAChB,mBAAmB,IAAI,OAAO;IAC9B,SAAS,IAAI,IAAI;IACjB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAC9B,WAAW,CAAC,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe;CAGtF;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;;OAIG;IACH,qCAAqC,CAAC,EAAE,OAAO,CAAC;CACjD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeDatabase.js","sourceRoot":"","sources":["../../src/next/NativeDatabase.ts"],"names":[],"mappings":"","sourcesContent":["import { NativeStatement } from './NativeStatement';\n\n/**\n * A class that represents an instance of the SQLite database.\n */\nexport declare class NativeDatabase {\n constructor(
|
|
1
|
+
{"version":3,"file":"NativeDatabase.js","sourceRoot":"","sources":["../../src/next/NativeDatabase.ts"],"names":[],"mappings":"","sourcesContent":["import { NativeStatement } from './NativeStatement';\n\n/**\n * A class that represents an instance of the SQLite database.\n */\nexport declare class NativeDatabase {\n constructor(databaseName: string, options?: SQLiteOpenOptions);\n\n //#region Asynchronous API\n\n public initAsync(): Promise<void>;\n public isInTransactionAsync(): Promise<boolean>;\n public closeAsync(): Promise<void>;\n public execAsync(source: string): Promise<void>;\n public prepareAsync(nativeStatement: NativeStatement, source: string): Promise<NativeStatement>;\n\n //#endregion\n\n //#region Synchronous API\n\n public initSync(): void;\n public isInTransactionSync(): boolean;\n public closeSync(): void;\n public execSync(source: string): void;\n public prepareSync(nativeStatement: NativeStatement, source: string): NativeStatement;\n\n //#endregion\n}\n\n/**\n * Options for opening a database.\n */\nexport interface SQLiteOpenOptions {\n /**\n * Whether to enable the CR-SQLite extension.\n * @default false\n */\n enableCRSQLite?: boolean;\n\n /**\n * Whether to call the [`sqlite3_update_hook()`](https://www.sqlite.org/c3ref/update_hook.html) function and enable the `onDatabaseChange` events. You can later subscribe to the change events by [`addDatabaseChangeListener`](#sqliteadddatabasechangelistenerlistener).\n * @default false\n */\n enableChangeListener?: boolean;\n\n /**\n * Whether to create new connection even if connection with the same database name exists in cache.\n * @default false\n */\n useNewConnection?: boolean;\n\n /**\n * Finalized unclosed statements automatically when the database is closed.\n * @default true\n * @hidden\n */\n finalizeUnusedStatementsBeforeClosing?: boolean;\n}\n"]}
|