expo-sqlite 58.0.10 → 58.0.12

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.
Files changed (88) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/android/build.gradle +6 -2
  3. package/android/src/main/cpp/NativeDatabaseBinding.cpp +11 -8
  4. package/android/src/main/cpp/NativeStatementBinding.cpp +43 -2
  5. package/android/src/main/cpp/NativeStatementBinding.h +3 -0
  6. package/android/src/main/cpp/SQLiteError.h +34 -0
  7. package/android/src/main/java/expo/modules/sqlite/DatabaseConnection.kt +68 -0
  8. package/android/src/main/java/expo/modules/sqlite/NativeDatabase.kt +135 -22
  9. package/android/src/main/java/expo/modules/sqlite/NativeSession.kt +126 -6
  10. package/android/src/main/java/expo/modules/sqlite/NativeStatement.kt +199 -14
  11. package/android/src/main/java/expo/modules/sqlite/NativeStatementBinding.kt +1 -0
  12. package/android/src/main/java/expo/modules/sqlite/SQLRecords.kt +19 -13
  13. package/android/src/main/java/expo/modules/sqlite/SQLiteModule.kt +176 -577
  14. package/android/src/main/java/expo/modules/sqlite/SQLiteOptions.kt +3 -10
  15. package/android/src/main/java/expo/modules/sqlite/SQLiteValues.kt +47 -0
  16. package/build/NativeDatabase.d.ts +2 -2
  17. package/build/SQLiteDatabase.js +9 -3
  18. package/build/SQLiteDatabase.js.map +1 -1
  19. package/build/WebConfiguration.d.ts +31 -0
  20. package/build/WebConfiguration.js +21 -0
  21. package/build/WebConfiguration.js.map +1 -0
  22. package/build/index.d.ts +1 -0
  23. package/build/index.js +1 -0
  24. package/build/index.js.map +1 -1
  25. package/dev-plugin-dist/+not-found.html +2 -4
  26. package/dev-plugin-dist/_expo/static/js/web/{__common-9b94dd2fbdbb825a662f42cf8d2077ee.js → __common-3e95e247f8ee6d975454b07047f39148.js} +52 -48
  27. package/dev-plugin-dist/_expo/static/js/web/{_layout-b2894030c1dfbd95b717a85901b6c271.js → _layout-0bc906c56b363d38baf86696db19957e.js} +23 -23
  28. package/dev-plugin-dist/_expo/static/js/web/{entry-04fdb7d857a65c0ed638ef2d774a4b6e.js → entry-293efbd088ab66af1b3334c3eeafa61f.js} +697 -696
  29. package/dev-plugin-dist/_expo/static/js/web/{index-4bf2da199f699eb47a42074d5e183c07.js → index-454a4f95007576080f4f47d70441d41a.js} +1740 -1740
  30. package/dev-plugin-dist/_expo/static/js/web/{worker-d51aa6be89e271e571111274ab8e7f5c.js → worker-172ab4a50823f055f5bd777d90d1a36a.js} +17 -17
  31. package/dev-plugin-dist/_sitemap.html +2 -4
  32. package/dev-plugin-dist/index.html +2 -4
  33. package/expo-module.config.json +0 -4
  34. package/ios/DatabaseFileUtils.swift +101 -5
  35. package/ios/NativeDatabase.swift +5 -8
  36. package/ios/NativeStatement.swift +20 -13
  37. package/ios/SQLiteModule.swift +8 -2
  38. package/ios/SQLiteResult.swift +31 -0
  39. package/ios/Tests/DatabaseFileUtilsTests.swift +119 -0
  40. package/ios/Tests/test_ErrorReporting.swift +25 -0
  41. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12-sources.jar +0 -0
  42. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12-sources.jar.md5 +1 -0
  43. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12-sources.jar.sha1 +1 -0
  44. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12-sources.jar.sha256 +1 -0
  45. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12-sources.jar.sha512 +1 -0
  46. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12.aar +0 -0
  47. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12.aar.md5 +1 -0
  48. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12.aar.sha1 +1 -0
  49. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12.aar.sha256 +1 -0
  50. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12.aar.sha512 +1 -0
  51. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{58.0.10/expo.modules.sqlite-58.0.10.module → 58.0.12/expo.modules.sqlite-58.0.12.module} +22 -22
  52. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12.module.md5 +1 -0
  53. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12.module.sha1 +1 -0
  54. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12.module.sha256 +1 -0
  55. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12.module.sha512 +1 -0
  56. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/{58.0.10/expo.modules.sqlite-58.0.10.pom → 58.0.12/expo.modules.sqlite-58.0.12.pom} +1 -1
  57. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12.pom.md5 +1 -0
  58. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12.pom.sha1 +1 -0
  59. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12.pom.sha256 +1 -0
  60. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.12/expo.modules.sqlite-58.0.12.pom.sha512 +1 -0
  61. package/package.json +4 -4
  62. package/src/NativeDatabase.ts +2 -2
  63. package/src/SQLiteDatabase.ts +11 -3
  64. package/src/WebConfiguration.ts +36 -0
  65. package/src/index.ts +1 -0
  66. package/web/SQLiteModule.ts +16 -0
  67. package/web/WorkerChannel.ts +17 -9
  68. package/web/wa-sqlite/sqlite-api.js +4 -1
  69. package/web/web.types.ts +6 -0
  70. package/web/worker.ts +50 -38
  71. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10-sources.jar +0 -0
  72. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10-sources.jar.md5 +0 -1
  73. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10-sources.jar.sha1 +0 -1
  74. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10-sources.jar.sha256 +0 -1
  75. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10-sources.jar.sha512 +0 -1
  76. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10.aar +0 -0
  77. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10.aar.md5 +0 -1
  78. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10.aar.sha1 +0 -1
  79. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10.aar.sha256 +0 -1
  80. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10.aar.sha512 +0 -1
  81. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10.module.md5 +0 -1
  82. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10.module.sha1 +0 -1
  83. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10.module.sha256 +0 -1
  84. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10.module.sha512 +0 -1
  85. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10.pom.md5 +0 -1
  86. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10.pom.sha1 +0 -1
  87. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10.pom.sha256 +0 -1
  88. package/local-maven-repo/host/exp/exponent/expo.modules.sqlite/58.0.10/expo.modules.sqlite-58.0.10.pom.sha512 +0 -1
@@ -2,11 +2,12 @@
2
2
 
3
3
  package expo.modules.sqlite
4
4
 
5
- import expo.modules.kotlin.jni.ArrayBuffer
6
- import expo.modules.kotlin.sharedobjects.SharedRef
7
- import java.nio.ByteBuffer
5
+ import io.github.expo.modules.v2.ExpoSharedObject
6
+ import io.github.expo.modules.v2.JS
7
+ import io.github.expo.modules.v2.SharedRef
8
8
 
9
- internal class NativeStatement : SharedRef<NativeStatementBinding>(NativeStatementBinding()) {
9
+ @ExpoSharedObject
10
+ internal class NativeStatement @JS constructor() : SharedRef<NativeStatementBinding>(NativeStatementBinding()) {
10
11
  var isFinalized = false
11
12
  var isPrepared = false
12
13
  var releasedByJavaScript = false
@@ -22,21 +23,205 @@ internal class NativeStatement : SharedRef<NativeStatementBinding>(NativeStateme
22
23
  }
23
24
  }
24
25
 
25
- override fun equals(other: Any?): Boolean {
26
- return other is NativeStatement && this.ref == other.ref
26
+ // region JavaScript members
27
+
28
+ @JS
29
+ suspend fun runAsync(
30
+ database: NativeDatabase,
31
+ bindParams: Map<String, Any?>,
32
+ bindBlobParams: Map<String, ByteArray>,
33
+ shouldPassAsArray: Boolean
34
+ ): RunResult = io { run(database.connection, bindParams, bindBlobParams, shouldPassAsArray) }
35
+
36
+ @JS
37
+ fun runSync(
38
+ database: NativeDatabase,
39
+ bindParams: Map<String, Any?>,
40
+ bindBlobParams: Map<String, ByteArray>,
41
+ shouldPassAsArray: Boolean
42
+ ): RunResult = run(database.connection, bindParams, bindBlobParams, shouldPassAsArray)
43
+
44
+ @JS
45
+ suspend fun stepAsync(database: NativeDatabase): List<Any?>? = io { step(database.connection) }
46
+
47
+ @JS
48
+ fun stepSync(database: NativeDatabase): List<Any?>? = step(database.connection)
49
+
50
+ @JS
51
+ suspend fun getAllAsync(database: NativeDatabase): List<List<Any?>> =
52
+ io { getAll(database.connection) }
53
+
54
+ @JS
55
+ fun getAllSync(database: NativeDatabase): List<List<Any?>> = getAll(database.connection)
56
+
57
+ @JS
58
+ suspend fun resetAsync(database: NativeDatabase): Unit = io { reset(database.connection) }
59
+
60
+ @JS
61
+ fun resetSync(database: NativeDatabase): Unit = reset(database.connection)
62
+
63
+ @JS
64
+ suspend fun getColumnNamesAsync(): List<String> = io { columnNames() }
65
+
66
+ @JS
67
+ fun getColumnNamesSync(): List<String> = columnNames()
68
+
69
+ @JS
70
+ suspend fun finalizeAsync(database: NativeDatabase): Unit = io { finalizeOn(database.connection) }
71
+
72
+ @JS
73
+ fun finalizeSync(database: NativeDatabase): Unit = finalizeOn(database.connection)
74
+
75
+ // endregion
76
+
77
+ fun getTransformedColumnValues(): List<Any?> = normalizeColumnValues(ref.getColumnValues())
78
+
79
+ @Throws(AccessClosedResourceException::class)
80
+ fun maybeThrowForFinalized() {
81
+ if (isFinalized) {
82
+ throw AccessClosedResourceException()
83
+ }
27
84
  }
28
85
 
29
- override fun hashCode(): Int {
30
- return ref.hashCode()
86
+ @Throws(AccessClosedResourceException::class, SQLiteErrorException::class)
87
+ private fun run(
88
+ connection: DatabaseConnection,
89
+ bindParams: Map<String, Any?>,
90
+ bindBlobParams: Map<String, ByteArray>,
91
+ shouldPassAsArray: Boolean
92
+ ): RunResult {
93
+ // The statement with parameter bindings is stateful,
94
+ // we have to guard with a critical section for thread safety.
95
+ synchronized(this) {
96
+ maybeThrowForFinalized()
97
+ connection.maybeThrowForClosed()
98
+
99
+ ref.sqlite3_reset()
100
+ ref.sqlite3_clear_bindings()
101
+ for ((key, param) in bindParams) {
102
+ val index = getBindParamIndex(key, shouldPassAsArray)
103
+ if (index > 0) {
104
+ ref.bindStatementParam(index, normalizeBindParam(param))
105
+ }
106
+ }
107
+ for ((key, param) in bindBlobParams) {
108
+ val index = getBindParamIndex(key, shouldPassAsArray)
109
+ if (index > 0) {
110
+ ref.bindStatementParam(index, param)
111
+ }
112
+ }
113
+
114
+ val ret = ref.sqlite3_step()
115
+ if (ret != NativeDatabaseBinding.SQLITE_ROW && ret != NativeDatabaseBinding.SQLITE_DONE) {
116
+ throw SQLiteErrorException(ref.getLastErrorMessage())
117
+ }
118
+ val firstRowValues: List<Any?> =
119
+ if (ret == NativeDatabaseBinding.SQLITE_ROW) {
120
+ getTransformedColumnValues()
121
+ } else {
122
+ emptyList()
123
+ }
124
+ return RunResult(
125
+ lastInsertRowId = connection.ref.sqlite3_last_insert_rowid(),
126
+ changes = connection.ref.sqlite3_changes(),
127
+ firstRowValues = firstRowValues
128
+ )
129
+ }
31
130
  }
32
131
 
33
- fun getTransformedColumnValues(): SQLiteColumnValues {
34
- val columnValueList = ref.getColumnValues().map {
35
- when (it) {
36
- is ByteBuffer -> ArrayBuffer(it)
37
- else -> it
132
+ @Throws(AccessClosedResourceException::class, InvalidConvertibleException::class, SQLiteErrorException::class)
133
+ private fun step(connection: DatabaseConnection): List<Any?>? {
134
+ // Guard the stateful statement, see `run` above.
135
+ synchronized(this) {
136
+ maybeThrowForFinalized()
137
+ connection.maybeThrowForClosed()
138
+
139
+ val ret = ref.sqlite3_step()
140
+ if (ret == NativeDatabaseBinding.SQLITE_ROW) {
141
+ return getTransformedColumnValues()
142
+ }
143
+ if (ret != NativeDatabaseBinding.SQLITE_DONE) {
144
+ throw SQLiteErrorException(ref.getLastErrorMessage())
145
+ }
146
+ return null
147
+ }
148
+ }
149
+
150
+ @Throws(AccessClosedResourceException::class, InvalidConvertibleException::class, SQLiteErrorException::class)
151
+ private fun getAll(connection: DatabaseConnection): List<List<Any?>> {
152
+ // Guard the stateful statement, see `run` above.
153
+ synchronized(this) {
154
+ maybeThrowForFinalized()
155
+ connection.maybeThrowForClosed()
156
+
157
+ val columnValuesList = mutableListOf<List<Any?>>()
158
+ while (true) {
159
+ val ret = ref.sqlite3_step()
160
+ if (ret == NativeDatabaseBinding.SQLITE_ROW) {
161
+ columnValuesList.add(getTransformedColumnValues())
162
+ continue
163
+ } else if (ret == NativeDatabaseBinding.SQLITE_DONE) {
164
+ break
165
+ }
166
+ throw SQLiteErrorException(ref.getLastErrorMessage())
167
+ }
168
+ return columnValuesList
169
+ }
170
+ }
171
+
172
+ @Throws(AccessClosedResourceException::class, SQLiteErrorException::class)
173
+ private fun reset(connection: DatabaseConnection) {
174
+ // Guard the stateful statement, see `run` above.
175
+ synchronized(this) {
176
+ maybeThrowForFinalized()
177
+ connection.maybeThrowForClosed()
178
+
179
+ if (ref.sqlite3_reset() != NativeDatabaseBinding.SQLITE_OK) {
180
+ throw SQLiteErrorException(ref.getLastErrorMessage())
181
+ }
182
+ }
183
+ }
184
+
185
+ @Throws(AccessClosedResourceException::class)
186
+ private fun columnNames(): List<String> {
187
+ synchronized(this) {
188
+ maybeThrowForFinalized()
189
+ return ref.getColumnNames()
190
+ }
191
+ }
192
+
193
+ @Throws(AccessClosedResourceException::class, SQLiteErrorException::class)
194
+ fun finalizeOn(connection: DatabaseConnection) {
195
+ synchronized(connection.statementLifecycleLock) {
196
+ // Guard the stateful statement, see `run` above.
197
+ synchronized(this) {
198
+ maybeThrowForFinalized()
199
+ connection.maybeThrowForClosed()
200
+
201
+ val ret = ref.sqlite3_finalize()
202
+ val error = if (ret != NativeDatabaseBinding.SQLITE_OK) {
203
+ ref.getLastErrorMessage()
204
+ } else {
205
+ null
206
+ }
207
+ // SQLite destroys the statement even when returning an earlier execution error.
208
+ isFinalized = true
209
+ connection.statements.removeAll { it === this }
210
+ if (releasedByJavaScript) {
211
+ ref.close()
212
+ }
213
+ if (error != null) {
214
+ throw SQLiteErrorException(error)
215
+ }
38
216
  }
39
217
  }
40
- return ArrayList(columnValueList)
41
218
  }
219
+
220
+ @Throws(InvalidBindParameterException::class)
221
+ private fun getBindParamIndex(key: String, shouldPassAsArray: Boolean): Int =
222
+ if (shouldPassAsArray) {
223
+ (key.toIntOrNull() ?: throw InvalidBindParameterException()) + 1
224
+ } else {
225
+ ref.sqlite3_bind_parameter_index(key)
226
+ }
42
227
  }
@@ -34,6 +34,7 @@ internal class NativeStatementBinding : Closeable {
34
34
  external fun sqlite3_step(): Int
35
35
 
36
36
  external fun bindStatementParam(index: Int, param: Any?): Int
37
+ external fun getLastErrorMessage(): String
37
38
  external fun getColumnNames(): SQLiteColumnNames
38
39
  external fun getColumnValues(): SQLiteColumnValues
39
40
 
@@ -2,20 +2,9 @@
2
2
 
3
3
  package expo.modules.sqlite
4
4
 
5
- import expo.modules.kotlin.records.Field
6
- import expo.modules.kotlin.records.Record
7
- import expo.modules.kotlin.types.Enumerable
8
- import expo.modules.kotlin.types.OptimizedRecord
5
+ import io.github.expo.modules.v2.Record
9
6
 
10
- @OptimizedRecord
11
- internal data class Query(
12
- @Field
13
- val sql: String,
14
- @Field
15
- val args: List<Any?>
16
- ) : Record
17
-
18
- internal enum class SQLAction(val value: String) : Enumerable {
7
+ internal enum class SQLAction(val value: String) {
19
8
  INSERT("insert"),
20
9
  UPDATE("update"),
21
10
  DELETE("delete"),
@@ -32,3 +21,20 @@ internal enum class SQLAction(val value: String) : Enumerable {
32
21
  }
33
22
  }
34
23
  }
24
+
25
+ @Record
26
+ internal data class DatabaseChangeEvent(
27
+ val databaseName: String,
28
+ val databaseFilePath: String,
29
+ val tableName: String,
30
+ val rowId: Long,
31
+ val typeId: SQLAction
32
+ )
33
+
34
+ /** What running a statement reports: its effect, and the first row it produced, if any. */
35
+ @Record(bufferSafe = false)
36
+ internal data class RunResult(
37
+ val lastInsertRowId: Long,
38
+ val changes: Int,
39
+ val firstRowValues: List<Any?>
40
+ )