expo-sqlite 13.2.2 → 13.4.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 CHANGED
@@ -10,6 +10,24 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 13.4.0 — 2024-03-20
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - Enabled [FTS](https://www.sqlite.org/fts3.html) and [FTS5](https://www.sqlite.org/fts5.html) for SQLite. ([#27738](https://github.com/expo/expo/pull/27738) by [@kudo](https://github.com/kudo))
18
+ - Fixed `NullPointerException` on Android when opening the same database multiple times. ([#27748](https://github.com/expo/expo/pull/27748) by [@kudo](https://github.com/kudo))
19
+
20
+ ## 13.3.0 — 2024-03-05
21
+
22
+ ### 🎉 New features
23
+
24
+ - [Android] Added `expo.sqlite.customBuildFlags` gradle property to support custom sqlite3 building flags. ([#27385](https://github.com/expo/expo/pull/27385) by [@kudo](https://github.com/kudo))
25
+ - Added `serializeAsync()` and `deserializeDatabaseAsync()` to serialze and deserialize databases. ([#27422](https://github.com/expo/expo/pull/27422) by [@kudo](https://github.com/kudo))
26
+
27
+ ### 🐛 Bug fixes
28
+
29
+ - Fixed `expo-sqlite/next` cannot be imported from an ESM project. ([#27423](https://github.com/expo/expo/pull/27423) by [@kudo](https://github.com/kudo))
30
+
13
31
  ## 13.2.2 — 2024-01-25
14
32
 
15
33
  ### 💡 Others
@@ -10,6 +10,11 @@ set(BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
10
10
  set(SRC_DIR "${CMAKE_SOURCE_DIR}/src/main/cpp")
11
11
  file(GLOB SOURCES "${SRC_DIR}/*.cpp")
12
12
 
13
+ separate_arguments(SQLITE_BUILDFLAGS)
14
+ add_compile_options(
15
+ ${SQLITE_BUILDFLAGS}
16
+ )
17
+
13
18
  add_library(
14
19
  ${PACKAGE_NAME}
15
20
  SHARED
@@ -6,7 +6,7 @@ apply plugin: 'maven-publish'
6
6
  apply plugin: 'de.undercouch.download'
7
7
 
8
8
  group = 'host.exp.exponent'
9
- version = '13.2.2'
9
+ version = '13.4.0'
10
10
 
11
11
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
12
12
  if (expoModulesCorePlugin.exists()) {
@@ -32,6 +32,20 @@ def customDownloadsDir = System.getenv("REACT_NATIVE_DOWNLOADS_DIR")
32
32
  def downloadsDir = customDownloadsDir ? new File(customDownloadsDir) : new File("$buildDir/downloads")
33
33
  def SQLITE3_SRC_DIR = new File("$buildDir/sqlite3_src")
34
34
 
35
+ def getSQLiteBuildFlags() {
36
+ def buildFlags = ''
37
+ if (findProperty('expo.sqlite.enableFTS') !== 'false') {
38
+ buildFlags <<= '-DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_FTS3_PARENTHESIS=1 -DSQLITE_ENABLE_FTS5=1'
39
+ } else {
40
+ }
41
+ def customBuildFlags = findProperty('expo.sqlite.customBuildFlags') ?: ''
42
+ if (customBuildFlags != '') {
43
+ buildFlags <<= " ${customBuildFlags}"
44
+ }
45
+ logger.info("SQLite build flags: ${buildFlags}")
46
+ return buildFlags
47
+ }
48
+
35
49
  def reactNativeArchitectures() {
36
50
  def value = project.getProperties().get("reactNativeArchitectures")
37
51
  return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
@@ -116,13 +130,14 @@ android {
116
130
  namespace "expo.modules.sqlite"
117
131
  defaultConfig {
118
132
  versionCode 18
119
- versionName "13.2.2"
133
+ versionName "13.4.0"
120
134
 
121
135
  externalNativeBuild {
122
136
  cmake {
123
137
  abiFilters (*reactNativeArchitectures())
124
138
  arguments "-DANDROID_STL=c++_shared",
125
- "-DSQLITE3_SRC_DIR=${toPlatformIndependentPath(SQLITE3_SRC_DIR)}"
139
+ "-DSQLITE3_SRC_DIR=${toPlatformIndependentPath(SQLITE3_SRC_DIR)}",
140
+ "-DSQLITE_BUILDFLAGS=${getSQLiteBuildFlags()}"
126
141
  }
127
142
  }
128
143
  }
@@ -33,6 +33,10 @@ void NativeDatabaseBinding::registerNatives() {
33
33
  makeNativeMethod("sqlite3_open", NativeDatabaseBinding::sqlite3_open),
34
34
  makeNativeMethod("sqlite3_prepare_v2",
35
35
  NativeDatabaseBinding::sqlite3_prepare_v2),
36
+ makeNativeMethod("sqlite3_serialize",
37
+ NativeDatabaseBinding::sqlite3_serialize),
38
+ makeNativeMethod("sqlite3_deserialize",
39
+ NativeDatabaseBinding::sqlite3_deserialize),
36
40
  makeNativeMethod("sqlite3_update_hook",
37
41
  NativeDatabaseBinding::sqlite3_update_hook),
38
42
  makeNativeMethod("convertSqlLiteErrorToString",
@@ -101,6 +105,38 @@ int NativeDatabaseBinding::sqlite3_prepare_v2(
101
105
  &cStatement->stmt, nullptr);
102
106
  }
103
107
 
108
+ jni::local_ref<jni::JArrayByte>
109
+ NativeDatabaseBinding::sqlite3_serialize(const std::string &databaseName) {
110
+ ::sqlite3_int64 size = 0;
111
+ unsigned char *bytes =
112
+ ::sqlite3_serialize(db, databaseName.c_str(), &size, 0);
113
+ if (!bytes) {
114
+ jni::throwNewJavaException(
115
+ SQLiteErrorException::create(convertSqlLiteErrorToString()).get());
116
+ }
117
+ auto byteArray = jni::JArrayByte::newArray(size);
118
+ byteArray->setRegion(0, size, reinterpret_cast<const signed char *>(bytes));
119
+ ::sqlite3_free(bytes);
120
+ return byteArray;
121
+ }
122
+
123
+ int NativeDatabaseBinding::sqlite3_deserialize(
124
+ const std::string &databaseName,
125
+ jni::alias_ref<jni::JArrayByte> serializedData) {
126
+ ::sqlite3_int64 size = serializedData->size();
127
+ void *buffer = ::sqlite3_malloc64(size);
128
+ if (!buffer) {
129
+ std::string message("Unable to allocate memory with size: ");
130
+ message += size;
131
+ jni::throwNewJavaException(SQLiteErrorException::create(message).get());
132
+ }
133
+ serializedData->getRegion(0, size, reinterpret_cast<signed char *>(buffer));
134
+ int flags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
135
+ return ::sqlite3_deserialize(db, databaseName.c_str(),
136
+ reinterpret_cast<unsigned char *>(buffer), size,
137
+ size, flags);
138
+ }
139
+
104
140
  void NativeDatabaseBinding::sqlite3_update_hook(bool enabled) {
105
141
  if (enabled) {
106
142
  ::sqlite3_update_hook(db, NativeDatabaseBinding::OnUpdateHook, this);
@@ -33,6 +33,10 @@ public:
33
33
  int sqlite3_prepare_v2(
34
34
  const std::string &source,
35
35
  jni::alias_ref<NativeStatementBinding::javaobject> statement);
36
+ jni::local_ref<jni::JArrayByte>
37
+ sqlite3_serialize(const std::string &databaseName);
38
+ int sqlite3_deserialize(const std::string &databaseName,
39
+ jni::alias_ref<jni::JArrayByte> serializedData);
36
40
  void sqlite3_update_hook(bool enabled);
37
41
 
38
42
  // helpers
@@ -70,6 +74,11 @@ public:
70
74
  create(const std::string &message) {
71
75
  return SQLiteErrorException::newInstance(jni::make_jstring(message));
72
76
  }
77
+
78
+ static jni::local_ref<SQLiteErrorException>
79
+ create(jni::alias_ref<jni::JString> message) {
80
+ return SQLiteErrorException::newInstance(message);
81
+ }
73
82
  };
74
83
 
75
84
  } // namespace expo
@@ -3,9 +3,15 @@
3
3
  package expo.modules.sqlite
4
4
 
5
5
  import expo.modules.kotlin.sharedobjects.SharedRef
6
+ import java.util.concurrent.atomic.AtomicInteger
6
7
 
7
8
  internal class NativeDatabase(val databaseName: String, val openOptions: OpenDatabaseOptions) : SharedRef<NativeDatabaseBinding>(NativeDatabaseBinding()) {
8
9
  var isClosed = false
10
+ private val refCount = AtomicInteger(1)
11
+
12
+ internal fun addRef() {
13
+ refCount.incrementAndGet()
14
+ }
9
15
 
10
16
  override fun equals(other: Any?): Boolean {
11
17
  return other is NativeDatabase && this.ref == other.ref
@@ -13,6 +19,9 @@ internal class NativeDatabase(val databaseName: String, val openOptions: OpenDat
13
19
 
14
20
  override fun deallocate() {
15
21
  super.deallocate()
16
- this.ref.close()
22
+ val shouldClose = refCount.decrementAndGet() <= 0
23
+ if (shouldClose) {
24
+ this.ref.close()
25
+ }
17
26
  }
18
27
  }
@@ -52,6 +52,8 @@ internal class NativeDatabaseBinding : Closeable {
52
52
  external fun sqlite3_load_extension(libPath: String, entryProc: String): Int
53
53
  external fun sqlite3_open(dbPath: String): Int
54
54
  external fun sqlite3_prepare_v2(source: String, statement: NativeStatementBinding): Int
55
+ external fun sqlite3_serialize(databaseName: String): ByteArray
56
+ external fun sqlite3_deserialize(databaseName: String, serializedData: ByteArray): Int
55
57
  private external fun sqlite3_update_hook(enabled: Boolean) // Keeps it private internally and uses `enableUpdateHook` publicly
56
58
 
57
59
  external fun convertSqlLiteErrorToString(): String
@@ -51,18 +51,25 @@ class SQLiteModuleNext : Module() {
51
51
  }
52
52
 
53
53
  Class(NativeDatabase::class) {
54
- Constructor { databaseName: String, options: OpenDatabaseOptions ->
55
- val dbPath = pathForDatabaseName(databaseName)
54
+ Constructor { databaseName: String, options: OpenDatabaseOptions, serializedData: ByteArray? ->
55
+ val database: NativeDatabase
56
+ if (serializedData != null) {
57
+ database = deserializeDatabase(serializedData, options)
58
+ } else {
59
+ val dbPath = pathForDatabaseName(databaseName)
60
+
61
+ // Try to find opened database for fast refresh
62
+ findCachedDatabase { it.databaseName == databaseName && it.openOptions == options && !options.useNewConnection }?.let {
63
+ it.addRef()
64
+ return@Constructor it
65
+ }
56
66
 
57
- // Try to find opened database for fast refresh
58
- findCachedDatabase { it.databaseName == databaseName && it.openOptions == options && !options.useNewConnection }?.let {
59
- return@Constructor it
67
+ database = NativeDatabase(databaseName, options)
68
+ if (database.ref.sqlite3_open(dbPath) != NativeDatabaseBinding.SQLITE_OK) {
69
+ throw OpenDatabaseException(databaseName)
70
+ }
60
71
  }
61
72
 
62
- val database = NativeDatabase(databaseName, options)
63
- if (database.ref.sqlite3_open(dbPath) != NativeDatabaseBinding.SQLITE_OK) {
64
- throw OpenDatabaseException(databaseName)
65
- }
66
73
  addCachedDatabase(database)
67
74
  return@Constructor database
68
75
  }
@@ -99,6 +106,13 @@ class SQLiteModuleNext : Module() {
99
106
  exec(database, source)
100
107
  }
101
108
 
109
+ AsyncFunction("serializeAsync") { database: NativeDatabase, databaseName: String ->
110
+ return@AsyncFunction serialize(database, databaseName)
111
+ }
112
+ Function("serializeSync") { database: NativeDatabase, databaseName: String ->
113
+ return@Function serialize(database, databaseName)
114
+ }
115
+
102
116
  AsyncFunction("prepareAsync") { database: NativeDatabase, statement: NativeStatement, source: String ->
103
117
  prepareStatement(database, statement, source)
104
118
  }
@@ -172,6 +186,17 @@ class SQLiteModuleNext : Module() {
172
186
  }
173
187
  }
174
188
 
189
+ private fun deserializeDatabase(serializedData: ByteArray, options: OpenDatabaseOptions): NativeDatabase {
190
+ val database = NativeDatabase(MEMORY_DB_NAME, options)
191
+ if (database.ref.sqlite3_open(MEMORY_DB_NAME) != NativeDatabaseBinding.SQLITE_OK) {
192
+ throw OpenDatabaseException(MEMORY_DB_NAME)
193
+ }
194
+ if (database.ref.sqlite3_deserialize("main", serializedData) != NativeDatabaseBinding.SQLITE_OK) {
195
+ throw SQLiteErrorException(database.ref.convertSqlLiteErrorToString())
196
+ }
197
+ return database
198
+ }
199
+
175
200
  @Throws(AccessClosedResourceException::class)
176
201
  private fun initDb(database: NativeDatabase) {
177
202
  maybeThrowForClosedDatabase(database)
@@ -189,6 +214,12 @@ class SQLiteModuleNext : Module() {
189
214
  database.ref.sqlite3_exec(source)
190
215
  }
191
216
 
217
+ @Throws(AccessClosedResourceException::class, SQLiteErrorException::class)
218
+ private fun serialize(database: NativeDatabase, databaseName: String): ByteArray {
219
+ maybeThrowForClosedDatabase(database)
220
+ return database.ref.sqlite3_serialize(databaseName)
221
+ }
222
+
192
223
  @Throws(AccessClosedResourceException::class, SQLiteErrorException::class)
193
224
  private fun prepareStatement(database: NativeDatabase, statement: NativeStatement, source: String) {
194
225
  maybeThrowForClosedDatabase(database)
@@ -1,7 +1,7 @@
1
1
  import { SQLiteOpenOptions } from './NativeDatabase';
2
2
  declare const _default: {
3
3
  readonly name: string;
4
- NativeDatabase(databaseName: string, options?: SQLiteOpenOptions): void;
4
+ NativeDatabase(databaseName: string, options?: SQLiteOpenOptions, serializedData?: Uint8Array): void;
5
5
  NativeStatement(): void;
6
6
  deleteDatabaseAsync(databaseName: string): Promise<void>;
7
7
  deleteDatabaseSync(databaseName: string): void;
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"ExpoSQLiteNext.d.ts","sourceRoot":"","sources":["../../src/next/ExpoSQLiteNext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;;;iCAQnC,MAAM,YACV,iBAAiB,mBACV,UAAU,GAC1B,IAAI;uBAIY,IAAI;sCAIiB,MAAM,GAAG,QAAQ,IAAI,CAAC;qCAI7B,MAAM,GAAG,IAAI;;;;AArBhD,wBAmCE"}
@@ -2,7 +2,7 @@ export default {
2
2
  get name() {
3
3
  return 'ExpoSQLiteNext';
4
4
  },
5
- NativeDatabase(databaseName, options) {
5
+ NativeDatabase(databaseName, options, serializedData) {
6
6
  throw new Error('Unimplemented');
7
7
  },
8
8
  NativeStatement() {
@@ -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,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"]}
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,CACZ,YAAoB,EACpB,OAA2B,EAC3B,cAA2B;QAE3B,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(\n databaseName: string,\n options?: SQLiteOpenOptions,\n serializedData?: Uint8Array\n ): 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,16 +3,18 @@ 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(databaseName: string, options?: SQLiteOpenOptions);
6
+ constructor(databaseName: string, options?: SQLiteOpenOptions, serializedData?: Uint8Array);
7
7
  initAsync(): Promise<void>;
8
8
  isInTransactionAsync(): Promise<boolean>;
9
9
  closeAsync(): Promise<void>;
10
10
  execAsync(source: string): Promise<void>;
11
+ serializeAsync(databaseName: string): Promise<Uint8Array>;
11
12
  prepareAsync(nativeStatement: NativeStatement, source: string): Promise<NativeStatement>;
12
13
  initSync(): void;
13
14
  isInTransactionSync(): boolean;
14
15
  closeSync(): void;
15
16
  execSync(source: string): void;
17
+ serializeSync(databaseName: string): Uint8Array;
16
18
  prepareSync(nativeStatement: NativeStatement, source: string): NativeStatement;
17
19
  }
18
20
  /**
@@ -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,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
+ {"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,EAAE,cAAc,CAAC,EAAE,UAAU;IAInF,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,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IACzD,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,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,UAAU;IAC/C,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(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"]}
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, serializedData?: Uint8Array);\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 serializeAsync(databaseName: string): Promise<Uint8Array>;\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 serializeSync(databaseName: string): Uint8Array;\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"]}
@@ -25,6 +25,12 @@ export declare class SQLiteDatabase {
25
25
  * @param source A string containing all the SQL queries.
26
26
  */
27
27
  execAsync(source: string): Promise<void>;
28
+ /**
29
+ * [Serialize the database](https://sqlite.org/c3ref/serialize.html) as `Uint8Array`.
30
+ *
31
+ * @param databaseName The name of the current attached databases. The default value is `main` which is the default database name.
32
+ */
33
+ serializeAsync(databaseName?: string): Promise<Uint8Array>;
28
34
  /**
29
35
  * Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).
30
36
  *
@@ -91,6 +97,14 @@ export declare class SQLiteDatabase {
91
97
  * @param source A string containing all the SQL queries.
92
98
  */
93
99
  execSync(source: string): void;
100
+ /**
101
+ * [Serialize the database](https://sqlite.org/c3ref/serialize.html) as `Uint8Array`.
102
+ *
103
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
104
+ *
105
+ * @param databaseName The name of the current attached databases. The default value is `main` which is the default database name.
106
+ */
107
+ serializeSync(databaseName?: string): Uint8Array;
94
108
  /**
95
109
  * Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).
96
110
  *
@@ -221,6 +235,22 @@ export declare function openDatabaseAsync(databaseName: string, options?: SQLite
221
235
  * @param options Open options.
222
236
  */
223
237
  export declare function openDatabaseSync(databaseName: string, options?: SQLiteOpenOptions): SQLiteDatabase;
238
+ /**
239
+ * Given a `Uint8Array` data and [deserialize to memory database](https://sqlite.org/c3ref/deserialize.html).
240
+ *
241
+ * @param serializedData The binary array to deserialize from [`SQLiteDatabase.serializeAsync()`](#serializeasyncdatabasename).
242
+ * @param options Open options.
243
+ */
244
+ export declare function deserializeDatabaseAsync(serializedData: Uint8Array, options?: SQLiteOpenOptions): Promise<SQLiteDatabase>;
245
+ /**
246
+ * Given a `Uint8Array` data and [deserialize to memory database](https://sqlite.org/c3ref/deserialize.html).
247
+ *
248
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
249
+ *
250
+ * @param serializedData The binary array to deserialize from [`SQLiteDatabase.serializeSync()`](#serializesyncdatabasename)
251
+ * @param options Open options.
252
+ */
253
+ export declare function deserializeDatabaseSync(serializedData: Uint8Array, options?: SQLiteOpenOptions): SQLiteDatabase;
224
254
  /**
225
255
  * Delete a database file.
226
256
  *
@@ -1 +1 @@
1
- {"version":3,"file":"SQLiteDatabase.d.ts","sourceRoot":"","sources":["../../src/next/SQLiteDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAG/D,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EACL,gBAAgB,EAGhB,eAAe,EACf,eAAe,EACf,wBAAwB,EACzB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAI7B;;GAEG;AACH,qBAAa,cAAc;aAEP,YAAY,EAAE,MAAM;aACpB,OAAO,EAAE,iBAAiB;IAC1C,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAFf,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,iBAAiB,EACzB,cAAc,EAAE,cAAc;IAGjD;;OAE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CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,cAAc,CAAC,CAKzB;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,UAAU,EAC1B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,cAAc,CAKhB;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7E;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAE7D;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,+HAA+H;IAC/H,YAAY,EAAE,MAAM,CAAC;IAErB,8CAA8C;IAC9C,gBAAgB,EAAE,MAAM,CAAC;IAEzB,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC;IAElB,0BAA0B;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,GAC7C,YAAY,CAEd;AAED;;;GAGG;AACH,cAAM,WAAY,SAAQ,cAAc;WAClB,WAAW,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC;CAM1E"}
@@ -35,6 +35,14 @@ export class SQLiteDatabase {
35
35
  execAsync(source) {
36
36
  return this.nativeDatabase.execAsync(source);
37
37
  }
38
+ /**
39
+ * [Serialize the database](https://sqlite.org/c3ref/serialize.html) as `Uint8Array`.
40
+ *
41
+ * @param databaseName The name of the current attached databases. The default value is `main` which is the default database name.
42
+ */
43
+ serializeAsync(databaseName = 'main') {
44
+ return this.nativeDatabase.serializeAsync(databaseName);
45
+ }
38
46
  /**
39
47
  * Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).
40
48
  *
@@ -139,6 +147,16 @@ export class SQLiteDatabase {
139
147
  execSync(source) {
140
148
  return this.nativeDatabase.execSync(source);
141
149
  }
150
+ /**
151
+ * [Serialize the database](https://sqlite.org/c3ref/serialize.html) as `Uint8Array`.
152
+ *
153
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
154
+ *
155
+ * @param databaseName The name of the current attached databases. The default value is `main` which is the default database name.
156
+ */
157
+ serializeSync(databaseName = 'main') {
158
+ return this.nativeDatabase.serializeSync(databaseName);
159
+ }
142
160
  /**
143
161
  * Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).
144
162
  *
@@ -290,6 +308,32 @@ export function openDatabaseSync(databaseName, options) {
290
308
  nativeDatabase.initSync();
291
309
  return new SQLiteDatabase(databaseName, openOptions, nativeDatabase);
292
310
  }
311
+ /**
312
+ * Given a `Uint8Array` data and [deserialize to memory database](https://sqlite.org/c3ref/deserialize.html).
313
+ *
314
+ * @param serializedData The binary array to deserialize from [`SQLiteDatabase.serializeAsync()`](#serializeasyncdatabasename).
315
+ * @param options Open options.
316
+ */
317
+ export async function deserializeDatabaseAsync(serializedData, options) {
318
+ const openOptions = options ?? {};
319
+ const nativeDatabase = new ExpoSQLite.NativeDatabase(':memory:', openOptions, serializedData);
320
+ await nativeDatabase.initAsync();
321
+ return new SQLiteDatabase(':memory:', openOptions, nativeDatabase);
322
+ }
323
+ /**
324
+ * Given a `Uint8Array` data and [deserialize to memory database](https://sqlite.org/c3ref/deserialize.html).
325
+ *
326
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
327
+ *
328
+ * @param serializedData The binary array to deserialize from [`SQLiteDatabase.serializeSync()`](#serializesyncdatabasename)
329
+ * @param options Open options.
330
+ */
331
+ export function deserializeDatabaseSync(serializedData, options) {
332
+ const openOptions = options ?? {};
333
+ const nativeDatabase = new ExpoSQLite.NativeDatabase(':memory:', openOptions, serializedData);
334
+ nativeDatabase.initSync();
335
+ return new SQLiteDatabase(':memory:', openOptions, nativeDatabase);
336
+ }
293
337
  /**
294
338
  * Delete a database file.
295
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AG,OAAO,IAAI,EAAE,CAAC;IAClC,MAAM,cAAc,GAAG,IAAI,UAAU,CAAC,cAAc,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IAChF,cAAc,CAAC,QAAQ,EAAE,CAAC;IAC1B,OAAO,IAAI,cAAc,CAAC,YAAY,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;AACvE,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,YAAoB;IAC5D,OAAO,MAAM,UAAU,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,YAAoB;IACrD,OAAO,UAAU,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;AACrD,CAAC;AAmBD;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CACvC,QAA8C;IAE9C,OAAO,OAAO,CAAC,WAAW,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC;AAC3D,CAAC;AAED;;;GAGG;AACH,MAAM,WAAY,SAAQ,cAAc;IAC/B,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,EAAkB;QAChD,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC;QAC1D,MAAM,cAAc,GAAG,IAAI,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAC/E,MAAM,cAAc,CAAC,SAAS,EAAE,CAAC;QACjC,OAAO,IAAI,WAAW,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;IACnE,CAAC;CACF","sourcesContent":["import { EventEmitter, Subscription } from 'expo-modules-core';\n\nimport ExpoSQLite from './ExpoSQLiteNext';\nimport { NativeDatabase, SQLiteOpenOptions } from './NativeDatabase';\nimport {\n SQLiteBindParams,\n SQLiteExecuteAsyncResult,\n SQLiteExecuteSyncResult,\n SQLiteRunResult,\n SQLiteStatement,\n SQLiteVariadicBindParams,\n} from './SQLiteStatement';\n\nexport { SQLiteOpenOptions };\n\nconst emitter = new EventEmitter(ExpoSQLite);\n\n/**\n * A SQLite database.\n */\nexport class SQLiteDatabase {\n constructor(\n public readonly databaseName: string,\n public readonly options: SQLiteOpenOptions,\n private readonly nativeDatabase: NativeDatabase\n ) {}\n\n /**\n * Asynchronous call to return whether the database is currently in a transaction.\n */\n public isInTransactionAsync(): Promise<boolean> {\n return this.nativeDatabase.isInTransactionAsync();\n }\n\n /**\n * Close the database.\n */\n public closeAsync(): Promise<void> {\n return this.nativeDatabase.closeAsync();\n }\n\n /**\n * Execute all SQL queries in the supplied string.\n * > Note: The queries are not escaped for you! Be careful when constructing your queries.\n *\n * @param source A string containing all the SQL queries.\n */\n public execAsync(source: string): Promise<void> {\n return this.nativeDatabase.execAsync(source);\n }\n\n /**\n * Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).\n *\n * @param source A string containing the SQL query.\n */\n public async prepareAsync(source: string): Promise<SQLiteStatement> {\n const nativeStatement = new ExpoSQLite.NativeStatement();\n await this.nativeDatabase.prepareAsync(nativeStatement, source);\n return new SQLiteStatement(this.nativeDatabase, nativeStatement);\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * > **Note:** This transaction is not exclusive and can be interrupted by other async queries.\n * @example\n * ```ts\n * db.withTransactionAsync(async () => {\n * await db.execAsync('UPDATE test SET name = \"aaa\"');\n *\n * //\n * // We cannot control the order of async/await order, so order of execution is not guaranteed.\n * // The following UPDATE query out of transaction may be executed here and break the expectation.\n * //\n *\n * const result = await db.getAsync<{ name: string }>('SELECT name FROM Users');\n * expect(result?.name).toBe('aaa');\n * });\n * db.execAsync('UPDATE test SET name = \"bbb\"');\n * ```\n * If you worry about the order of execution, use `withExclusiveTransactionAsync` instead.\n *\n * @param task An async function to execute within a transaction.\n */\n public async withTransactionAsync(task: () => Promise<void>): Promise<void> {\n try {\n await this.execAsync('BEGIN');\n await task();\n await this.execAsync('COMMIT');\n } catch (e) {\n await this.execAsync('ROLLBACK');\n throw e;\n }\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * The transaction may be exclusive.\n * As long as the transaction is converted into a write transaction,\n * the other async write queries will abort with `database is locked` error.\n *\n * @param task An async function to execute within a transaction. Any queries inside the transaction must be executed on the `txn` object.\n * The `txn` object has the same interfaces as the [`SQLiteDatabase`](#sqlitedatabase) object. You can use `txn` like a [`SQLiteDatabase`](#sqlitedatabase) object.\n *\n * @example\n * ```ts\n * db.withExclusiveTransactionAsync(async (txn) => {\n * await txn.execAsync('UPDATE test SET name = \"aaa\"');\n * });\n * ```\n */\n public async withExclusiveTransactionAsync(\n task: (txn: Transaction) => Promise<void>\n ): Promise<void> {\n const transaction = await Transaction.createAsync(this);\n let error;\n try {\n await transaction.execAsync('BEGIN');\n await task(transaction);\n await transaction.execAsync('COMMIT');\n } catch (e) {\n await transaction.execAsync('ROLLBACK');\n error = e;\n } finally {\n await transaction.closeAsync();\n }\n if (error) {\n throw error;\n }\n }\n\n /**\n * Synchronous call to return whether the database is currently in a transaction.\n */\n public isInTransactionSync(): boolean {\n return this.nativeDatabase.isInTransactionSync();\n }\n\n /**\n * Close the database.\n */\n public closeSync(): void {\n return this.nativeDatabase.closeSync();\n }\n\n /**\n * Execute all SQL queries in the supplied string.\n *\n * > **Note:** The queries are not escaped for you! Be careful when constructing your queries.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param source A string containing all the SQL queries.\n */\n public execSync(source: string): void {\n return this.nativeDatabase.execSync(source);\n }\n\n /**\n * Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param source A string containing the SQL query.\n */\n public prepareSync(source: string): SQLiteStatement {\n const nativeStatement = new ExpoSQLite.NativeStatement();\n this.nativeDatabase.prepareSync(nativeStatement, source);\n return new SQLiteStatement(this.nativeDatabase, nativeStatement);\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param task An async function to execute within a transaction.\n */\n public withTransactionSync(task: () => void): void {\n try {\n this.execSync('BEGIN');\n task();\n this.execSync('COMMIT');\n } catch (e) {\n this.execSync('ROLLBACK');\n throw e;\n }\n }\n\n //#region Statement API shorthands\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public runAsync(source: string, params: SQLiteBindParams): Promise<SQLiteRunResult>;\n\n /**\n * @hidden\n */\n public runAsync(source: string, ...params: SQLiteVariadicBindParams): Promise<SQLiteRunResult>;\n public async runAsync(source: string, ...params: any[]): Promise<SQLiteRunResult> {\n const statement = await this.prepareAsync(source);\n let result: SQLiteExecuteAsyncResult<unknown>;\n try {\n result = await statement.executeAsync(...params);\n } finally {\n await statement.finalizeAsync();\n }\n return result;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), [`SQLiteExecuteAsyncResult.getFirstAsync()`](#getfirstasync), and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public getFirstAsync<T>(source: string, params: SQLiteBindParams): Promise<T | null>;\n /**\n * @hidden\n */\n public getFirstAsync<T>(source: string, ...params: SQLiteVariadicBindParams): Promise<T | null>;\n public async getFirstAsync<T>(source: string, ...params: any[]): Promise<T | null> {\n const statement = await this.prepareAsync(source);\n let firstRow: T | null;\n try {\n const result = await statement.executeAsync<T>(...params);\n firstRow = await result.getFirstAsync();\n } finally {\n await statement.finalizeAsync();\n }\n return firstRow;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), [`SQLiteExecuteAsyncResult`](#sqliteexecuteasyncresult) `AsyncIterator`, and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n * @returns Rather than returning Promise, this function returns an [`AsyncIterableIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncIterator). You can use `for await...of` to iterate over the rows from the SQLite query result.\n */\n public getEachAsync<T>(source: string, params: SQLiteBindParams): AsyncIterableIterator<T>;\n /**\n * @hidden\n */\n public getEachAsync<T>(\n source: string,\n ...params: SQLiteVariadicBindParams\n ): AsyncIterableIterator<T>;\n public async *getEachAsync<T>(source: string, ...params: any[]): AsyncIterableIterator<T> {\n const statement = await this.prepareAsync(source);\n try {\n const result = await statement.executeAsync<T>(...params);\n for await (const row of result) {\n yield row;\n }\n } finally {\n await statement.finalizeAsync();\n }\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), [`SQLiteExecuteAsyncResult.getAllAsync()`](#getallasync), and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n * @example\n * ```ts\n * // For unnamed parameters, you pass values in an array.\n * db.getAllAsync('SELECT * FROM test WHERE intValue = ? AND name = ?', [1, 'Hello']);\n *\n * // For unnamed parameters, you pass values in variadic arguments.\n * db.getAllAsync('SELECT * FROM test WHERE intValue = ? AND name = ?', 1, 'Hello');\n *\n * // For named parameters, you should pass values in object.\n * db.getAllAsync('SELECT * FROM test WHERE intValue = $intValue AND name = $name', { $intValue: 1, $name: 'Hello' });\n * ```\n */\n public getAllAsync<T>(source: string, params: SQLiteBindParams): Promise<T[]>;\n /**\n * @hidden\n */\n public getAllAsync<T>(source: string, ...params: SQLiteVariadicBindParams): Promise<T[]>;\n public async getAllAsync<T>(source: string, ...params: any[]): Promise<T[]> {\n const statement = await this.prepareAsync(source);\n let allRows;\n try {\n const result = await statement.executeAsync<T>(...params);\n allRows = await result.getAllAsync();\n } finally {\n await statement.finalizeAsync();\n }\n return allRows;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), and [`SQLiteStatement.finalizeSync()`](#finalizesync).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public runSync(source: string, params: SQLiteBindParams): SQLiteRunResult;\n /**\n * @hidden\n */\n public runSync(source: string, ...params: SQLiteVariadicBindParams): SQLiteRunResult;\n public runSync(source: string, ...params: any[]): SQLiteRunResult {\n const statement = this.prepareSync(source);\n let result: SQLiteExecuteSyncResult<unknown>;\n try {\n result = statement.executeSync(...params);\n } finally {\n statement.finalizeSync();\n }\n return result;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), [`SQLiteExecuteSyncResult.getFirstSync()`](#getfirstsync), and [`SQLiteStatement.finalizeSync()`](#finalizesync).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public getFirstSync<T>(source: string, params: SQLiteBindParams): T | null;\n /**\n * @hidden\n */\n public getFirstSync<T>(source: string, ...params: SQLiteVariadicBindParams): T | null;\n public getFirstSync<T>(source: string, ...params: any[]): T | null {\n const statement = this.prepareSync(source);\n let firstRow: T | null;\n try {\n const result = statement.executeSync<T>(...params);\n firstRow = result.getFirstSync();\n } finally {\n statement.finalizeSync();\n }\n return firstRow;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), [`SQLiteExecuteSyncResult`](#sqliteexecutesyncresult) `Iterator`, and [`SQLiteStatement.finalizeSync()`](#finalizesync).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n * @returns This function returns an [`IterableIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator). You can use `for...of` to iterate over the rows from the SQLite query result.\n */\n public getEachSync<T>(source: string, params: SQLiteBindParams): IterableIterator<T>;\n /**\n * @hidden\n */\n public getEachSync<T>(source: string, ...params: SQLiteVariadicBindParams): IterableIterator<T>;\n public *getEachSync<T>(source: string, ...params: any[]): IterableIterator<T> {\n const statement = this.prepareSync(source);\n try {\n const result = statement.executeSync<T>(...params);\n for (const row of result) {\n yield row;\n }\n } finally {\n statement.finalizeSync();\n }\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), [`SQLiteExecuteSyncResult.getAllSync()`](#getallsync), and [`SQLiteStatement.finalizeSync()`](#finalizesync).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public getAllSync<T>(source: string, params: SQLiteBindParams): T[];\n /**\n * @hidden\n */\n public getAllSync<T>(source: string, ...params: SQLiteVariadicBindParams): T[];\n public getAllSync<T>(source: string, ...params: any[]): T[] {\n const statement = this.prepareSync(source);\n let allRows;\n try {\n const result = statement.executeSync<T>(...params);\n allRows = result.getAllSync();\n } finally {\n statement.finalizeSync();\n }\n return allRows;\n }\n\n //#endregion\n}\n\n/**\n * Open a database.\n *\n * @param databaseName The name of the database file to open.\n * @param options Open options.\n */\nexport async function openDatabaseAsync(\n databaseName: string,\n options?: SQLiteOpenOptions\n): Promise<SQLiteDatabase> {\n const openOptions = options ?? {};\n const nativeDatabase = new ExpoSQLite.NativeDatabase(databaseName, openOptions);\n await nativeDatabase.initAsync();\n return new SQLiteDatabase(databaseName, openOptions, nativeDatabase);\n}\n\n/**\n * Open a database.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param databaseName The name of the database file to open.\n * @param options Open options.\n */\nexport function openDatabaseSync(\n databaseName: string,\n options?: SQLiteOpenOptions\n): SQLiteDatabase {\n const openOptions = options ?? {};\n const nativeDatabase = new ExpoSQLite.NativeDatabase(databaseName, openOptions);\n nativeDatabase.initSync();\n return new SQLiteDatabase(databaseName, openOptions, nativeDatabase);\n}\n\n/**\n * Delete a database file.\n *\n * @param databaseName The name of the database file to delete.\n */\nexport async function deleteDatabaseAsync(databaseName: string): Promise<void> {\n return await ExpoSQLite.deleteDatabaseAsync(databaseName);\n}\n\n/**\n * Delete a database file.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param databaseName The name of the database file to delete.\n */\nexport function deleteDatabaseSync(databaseName: string): void {\n return ExpoSQLite.deleteDatabaseSync(databaseName);\n}\n\n/**\n * The event payload for the listener of [`addDatabaseChangeListener`](#sqliteadddatabasechangelistenerlistener)\n */\nexport type DatabaseChangeEvent = {\n /** The database name. The value would be `main` by default and other database names if you use `ATTACH DATABASE` statement. */\n databaseName: string;\n\n /** The absolute file path to the database. */\n databaseFilePath: string;\n\n /** The table name. */\n tableName: string;\n\n /** The changed row ID. */\n rowId: number;\n};\n\n/**\n * Add a listener for database changes.\n * > Note: to enable this feature, you must set [`enableChangeListener` to `true`](#sqliteopenoptions) when opening the database.\n *\n * @param listener A function that receives the `databaseName`, `databaseFilePath`, `tableName` and `rowId` of the modified data.\n * @returns A `Subscription` object that you can call `remove()` on when you would like to unsubscribe the listener.\n */\nexport function addDatabaseChangeListener(\n listener: (event: DatabaseChangeEvent) => void\n): Subscription {\n return emitter.addListener('onDatabaseChange', listener);\n}\n\n/**\n * A new connection specific used for [`withExclusiveTransactionAsync`](#withexclusivetransactionasynctask).\n * @hidden not going to pull all the database methods to the document.\n */\nclass Transaction extends SQLiteDatabase {\n public static async createAsync(db: SQLiteDatabase): Promise<Transaction> {\n const options = { ...db.options, useNewConnection: true };\n const nativeDatabase = new ExpoSQLite.NativeDatabase(db.databaseName, options);\n await nativeDatabase.initAsync();\n return new Transaction(db.databaseName, options, nativeDatabase);\n }\n}\n"]}
1
+ {"version":3,"file":"SQLiteDatabase.js","sourceRoot":"","sources":["../../src/next/SQLiteDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,MAAM,mBAAmB,CAAC;AAE/D,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAKL,eAAe,GAEhB,MAAM,mBAAmB,CAAC;AAI3B,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,UAAU,CAAC,CAAC;AAE7C;;GAEG;AACH,MAAM,OAAO,cAAc;IAEP;IACA;IACC;IAHnB,YACkB,YAAoB,EACpB,OAA0B,EACzB,cAA8B;QAF/B,iBAAY,GAAZ,YAAY,CAAQ;QACpB,YAAO,GAAP,OA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O,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC;QAC1D,MAAM,cAAc,GAAG,IAAI,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAC/E,MAAM,cAAc,CAAC,SAAS,EAAE,CAAC;QACjC,OAAO,IAAI,WAAW,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;IACnE,CAAC;CACF","sourcesContent":["import { EventEmitter, Subscription } from 'expo-modules-core';\n\nimport ExpoSQLite from './ExpoSQLiteNext';\nimport { NativeDatabase, SQLiteOpenOptions } from './NativeDatabase';\nimport {\n SQLiteBindParams,\n SQLiteExecuteAsyncResult,\n SQLiteExecuteSyncResult,\n SQLiteRunResult,\n SQLiteStatement,\n SQLiteVariadicBindParams,\n} from './SQLiteStatement';\n\nexport { SQLiteOpenOptions };\n\nconst emitter = new EventEmitter(ExpoSQLite);\n\n/**\n * A SQLite database.\n */\nexport class SQLiteDatabase {\n constructor(\n public readonly databaseName: string,\n public readonly options: SQLiteOpenOptions,\n private readonly nativeDatabase: NativeDatabase\n ) {}\n\n /**\n * Asynchronous call to return whether the database is currently in a transaction.\n */\n public isInTransactionAsync(): Promise<boolean> {\n return this.nativeDatabase.isInTransactionAsync();\n }\n\n /**\n * Close the database.\n */\n public closeAsync(): Promise<void> {\n return this.nativeDatabase.closeAsync();\n }\n\n /**\n * Execute all SQL queries in the supplied string.\n * > Note: The queries are not escaped for you! Be careful when constructing your queries.\n *\n * @param source A string containing all the SQL queries.\n */\n public execAsync(source: string): Promise<void> {\n return this.nativeDatabase.execAsync(source);\n }\n\n /**\n * [Serialize the database](https://sqlite.org/c3ref/serialize.html) as `Uint8Array`.\n *\n * @param databaseName The name of the current attached databases. The default value is `main` which is the default database name.\n */\n public serializeAsync(databaseName: string = 'main'): Promise<Uint8Array> {\n return this.nativeDatabase.serializeAsync(databaseName);\n }\n\n /**\n * Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).\n *\n * @param source A string containing the SQL query.\n */\n public async prepareAsync(source: string): Promise<SQLiteStatement> {\n const nativeStatement = new ExpoSQLite.NativeStatement();\n await this.nativeDatabase.prepareAsync(nativeStatement, source);\n return new SQLiteStatement(this.nativeDatabase, nativeStatement);\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * > **Note:** This transaction is not exclusive and can be interrupted by other async queries.\n * @example\n * ```ts\n * db.withTransactionAsync(async () => {\n * await db.execAsync('UPDATE test SET name = \"aaa\"');\n *\n * //\n * // We cannot control the order of async/await order, so order of execution is not guaranteed.\n * // The following UPDATE query out of transaction may be executed here and break the expectation.\n * //\n *\n * const result = await db.getAsync<{ name: string }>('SELECT name FROM Users');\n * expect(result?.name).toBe('aaa');\n * });\n * db.execAsync('UPDATE test SET name = \"bbb\"');\n * ```\n * If you worry about the order of execution, use `withExclusiveTransactionAsync` instead.\n *\n * @param task An async function to execute within a transaction.\n */\n public async withTransactionAsync(task: () => Promise<void>): Promise<void> {\n try {\n await this.execAsync('BEGIN');\n await task();\n await this.execAsync('COMMIT');\n } catch (e) {\n await this.execAsync('ROLLBACK');\n throw e;\n }\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * The transaction may be exclusive.\n * As long as the transaction is converted into a write transaction,\n * the other async write queries will abort with `database is locked` error.\n *\n * @param task An async function to execute within a transaction. Any queries inside the transaction must be executed on the `txn` object.\n * The `txn` object has the same interfaces as the [`SQLiteDatabase`](#sqlitedatabase) object. You can use `txn` like a [`SQLiteDatabase`](#sqlitedatabase) object.\n *\n * @example\n * ```ts\n * db.withExclusiveTransactionAsync(async (txn) => {\n * await txn.execAsync('UPDATE test SET name = \"aaa\"');\n * });\n * ```\n */\n public async withExclusiveTransactionAsync(\n task: (txn: Transaction) => Promise<void>\n ): Promise<void> {\n const transaction = await Transaction.createAsync(this);\n let error;\n try {\n await transaction.execAsync('BEGIN');\n await task(transaction);\n await transaction.execAsync('COMMIT');\n } catch (e) {\n await transaction.execAsync('ROLLBACK');\n error = e;\n } finally {\n await transaction.closeAsync();\n }\n if (error) {\n throw error;\n }\n }\n\n /**\n * Synchronous call to return whether the database is currently in a transaction.\n */\n public isInTransactionSync(): boolean {\n return this.nativeDatabase.isInTransactionSync();\n }\n\n /**\n * Close the database.\n */\n public closeSync(): void {\n return this.nativeDatabase.closeSync();\n }\n\n /**\n * Execute all SQL queries in the supplied string.\n *\n * > **Note:** The queries are not escaped for you! Be careful when constructing your queries.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param source A string containing all the SQL queries.\n */\n public execSync(source: string): void {\n return this.nativeDatabase.execSync(source);\n }\n\n /**\n * [Serialize the database](https://sqlite.org/c3ref/serialize.html) as `Uint8Array`.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param databaseName The name of the current attached databases. The default value is `main` which is the default database name.\n */\n public serializeSync(databaseName: string = 'main'): Uint8Array {\n return this.nativeDatabase.serializeSync(databaseName);\n }\n\n /**\n * Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param source A string containing the SQL query.\n */\n public prepareSync(source: string): SQLiteStatement {\n const nativeStatement = new ExpoSQLite.NativeStatement();\n this.nativeDatabase.prepareSync(nativeStatement, source);\n return new SQLiteStatement(this.nativeDatabase, nativeStatement);\n }\n\n /**\n * Execute a transaction and automatically commit/rollback based on the `task` result.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param task An async function to execute within a transaction.\n */\n public withTransactionSync(task: () => void): void {\n try {\n this.execSync('BEGIN');\n task();\n this.execSync('COMMIT');\n } catch (e) {\n this.execSync('ROLLBACK');\n throw e;\n }\n }\n\n //#region Statement API shorthands\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public runAsync(source: string, params: SQLiteBindParams): Promise<SQLiteRunResult>;\n\n /**\n * @hidden\n */\n public runAsync(source: string, ...params: SQLiteVariadicBindParams): Promise<SQLiteRunResult>;\n public async runAsync(source: string, ...params: any[]): Promise<SQLiteRunResult> {\n const statement = await this.prepareAsync(source);\n let result: SQLiteExecuteAsyncResult<unknown>;\n try {\n result = await statement.executeAsync(...params);\n } finally {\n await statement.finalizeAsync();\n }\n return result;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), [`SQLiteExecuteAsyncResult.getFirstAsync()`](#getfirstasync), and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public getFirstAsync<T>(source: string, params: SQLiteBindParams): Promise<T | null>;\n /**\n * @hidden\n */\n public getFirstAsync<T>(source: string, ...params: SQLiteVariadicBindParams): Promise<T | null>;\n public async getFirstAsync<T>(source: string, ...params: any[]): Promise<T | null> {\n const statement = await this.prepareAsync(source);\n let firstRow: T | null;\n try {\n const result = await statement.executeAsync<T>(...params);\n firstRow = await result.getFirstAsync();\n } finally {\n await statement.finalizeAsync();\n }\n return firstRow;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), [`SQLiteExecuteAsyncResult`](#sqliteexecuteasyncresult) `AsyncIterator`, and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n * @returns Rather than returning Promise, this function returns an [`AsyncIterableIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncIterator). You can use `for await...of` to iterate over the rows from the SQLite query result.\n */\n public getEachAsync<T>(source: string, params: SQLiteBindParams): AsyncIterableIterator<T>;\n /**\n * @hidden\n */\n public getEachAsync<T>(\n source: string,\n ...params: SQLiteVariadicBindParams\n ): AsyncIterableIterator<T>;\n public async *getEachAsync<T>(source: string, ...params: any[]): AsyncIterableIterator<T> {\n const statement = await this.prepareAsync(source);\n try {\n const result = await statement.executeAsync<T>(...params);\n for await (const row of result) {\n yield row;\n }\n } finally {\n await statement.finalizeAsync();\n }\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource), [`SQLiteStatement.executeAsync()`](#executeasyncparams), [`SQLiteExecuteAsyncResult.getAllAsync()`](#getallasync), and [`SQLiteStatement.finalizeAsync()`](#finalizeasync).\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n * @example\n * ```ts\n * // For unnamed parameters, you pass values in an array.\n * db.getAllAsync('SELECT * FROM test WHERE intValue = ? AND name = ?', [1, 'Hello']);\n *\n * // For unnamed parameters, you pass values in variadic arguments.\n * db.getAllAsync('SELECT * FROM test WHERE intValue = ? AND name = ?', 1, 'Hello');\n *\n * // For named parameters, you should pass values in object.\n * db.getAllAsync('SELECT * FROM test WHERE intValue = $intValue AND name = $name', { $intValue: 1, $name: 'Hello' });\n * ```\n */\n public getAllAsync<T>(source: string, params: SQLiteBindParams): Promise<T[]>;\n /**\n * @hidden\n */\n public getAllAsync<T>(source: string, ...params: SQLiteVariadicBindParams): Promise<T[]>;\n public async getAllAsync<T>(source: string, ...params: any[]): Promise<T[]> {\n const statement = await this.prepareAsync(source);\n let allRows;\n try {\n const result = await statement.executeAsync<T>(...params);\n allRows = await result.getAllAsync();\n } finally {\n await statement.finalizeAsync();\n }\n return allRows;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), and [`SQLiteStatement.finalizeSync()`](#finalizesync).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public runSync(source: string, params: SQLiteBindParams): SQLiteRunResult;\n /**\n * @hidden\n */\n public runSync(source: string, ...params: SQLiteVariadicBindParams): SQLiteRunResult;\n public runSync(source: string, ...params: any[]): SQLiteRunResult {\n const statement = this.prepareSync(source);\n let result: SQLiteExecuteSyncResult<unknown>;\n try {\n result = statement.executeSync(...params);\n } finally {\n statement.finalizeSync();\n }\n return result;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), [`SQLiteExecuteSyncResult.getFirstSync()`](#getfirstsync), and [`SQLiteStatement.finalizeSync()`](#finalizesync).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public getFirstSync<T>(source: string, params: SQLiteBindParams): T | null;\n /**\n * @hidden\n */\n public getFirstSync<T>(source: string, ...params: SQLiteVariadicBindParams): T | null;\n public getFirstSync<T>(source: string, ...params: any[]): T | null {\n const statement = this.prepareSync(source);\n let firstRow: T | null;\n try {\n const result = statement.executeSync<T>(...params);\n firstRow = result.getFirstSync();\n } finally {\n statement.finalizeSync();\n }\n return firstRow;\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), [`SQLiteExecuteSyncResult`](#sqliteexecutesyncresult) `Iterator`, and [`SQLiteStatement.finalizeSync()`](#finalizesync).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n * @returns This function returns an [`IterableIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator). You can use `for...of` to iterate over the rows from the SQLite query result.\n */\n public getEachSync<T>(source: string, params: SQLiteBindParams): IterableIterator<T>;\n /**\n * @hidden\n */\n public getEachSync<T>(source: string, ...params: SQLiteVariadicBindParams): IterableIterator<T>;\n public *getEachSync<T>(source: string, ...params: any[]): IterableIterator<T> {\n const statement = this.prepareSync(source);\n try {\n const result = statement.executeSync<T>(...params);\n for (const row of result) {\n yield row;\n }\n } finally {\n statement.finalizeSync();\n }\n }\n\n /**\n * A convenience wrapper around [`SQLiteDatabase.prepareSync()`](#preparesyncsource), [`SQLiteStatement.executeSync()`](#executesyncparams), [`SQLiteExecuteSyncResult.getAllSync()`](#getallsync), and [`SQLiteStatement.finalizeSync()`](#finalizesync).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param source A string containing the SQL query.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public getAllSync<T>(source: string, params: SQLiteBindParams): T[];\n /**\n * @hidden\n */\n public getAllSync<T>(source: string, ...params: SQLiteVariadicBindParams): T[];\n public getAllSync<T>(source: string, ...params: any[]): T[] {\n const statement = this.prepareSync(source);\n let allRows;\n try {\n const result = statement.executeSync<T>(...params);\n allRows = result.getAllSync();\n } finally {\n statement.finalizeSync();\n }\n return allRows;\n }\n\n //#endregion\n}\n\n/**\n * Open a database.\n *\n * @param databaseName The name of the database file to open.\n * @param options Open options.\n */\nexport async function openDatabaseAsync(\n databaseName: string,\n options?: SQLiteOpenOptions\n): Promise<SQLiteDatabase> {\n const openOptions = options ?? {};\n const nativeDatabase = new ExpoSQLite.NativeDatabase(databaseName, openOptions);\n await nativeDatabase.initAsync();\n return new SQLiteDatabase(databaseName, openOptions, nativeDatabase);\n}\n\n/**\n * Open a database.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param databaseName The name of the database file to open.\n * @param options Open options.\n */\nexport function openDatabaseSync(\n databaseName: string,\n options?: SQLiteOpenOptions\n): SQLiteDatabase {\n const openOptions = options ?? {};\n const nativeDatabase = new ExpoSQLite.NativeDatabase(databaseName, openOptions);\n nativeDatabase.initSync();\n return new SQLiteDatabase(databaseName, openOptions, nativeDatabase);\n}\n\n/**\n * Given a `Uint8Array` data and [deserialize to memory database](https://sqlite.org/c3ref/deserialize.html).\n *\n * @param serializedData The binary array to deserialize from [`SQLiteDatabase.serializeAsync()`](#serializeasyncdatabasename).\n * @param options Open options.\n */\nexport async function deserializeDatabaseAsync(\n serializedData: Uint8Array,\n options?: SQLiteOpenOptions\n): Promise<SQLiteDatabase> {\n const openOptions = options ?? {};\n const nativeDatabase = new ExpoSQLite.NativeDatabase(':memory:', openOptions, serializedData);\n await nativeDatabase.initAsync();\n return new SQLiteDatabase(':memory:', openOptions, nativeDatabase);\n}\n\n/**\n * Given a `Uint8Array` data and [deserialize to memory database](https://sqlite.org/c3ref/deserialize.html).\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param serializedData The binary array to deserialize from [`SQLiteDatabase.serializeSync()`](#serializesyncdatabasename)\n * @param options Open options.\n */\nexport function deserializeDatabaseSync(\n serializedData: Uint8Array,\n options?: SQLiteOpenOptions\n): SQLiteDatabase {\n const openOptions = options ?? {};\n const nativeDatabase = new ExpoSQLite.NativeDatabase(':memory:', openOptions, serializedData);\n nativeDatabase.initSync();\n return new SQLiteDatabase(':memory:', openOptions, nativeDatabase);\n}\n\n/**\n * Delete a database file.\n *\n * @param databaseName The name of the database file to delete.\n */\nexport async function deleteDatabaseAsync(databaseName: string): Promise<void> {\n return await ExpoSQLite.deleteDatabaseAsync(databaseName);\n}\n\n/**\n * Delete a database file.\n *\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n *\n * @param databaseName The name of the database file to delete.\n */\nexport function deleteDatabaseSync(databaseName: string): void {\n return ExpoSQLite.deleteDatabaseSync(databaseName);\n}\n\n/**\n * The event payload for the listener of [`addDatabaseChangeListener`](#sqliteadddatabasechangelistenerlistener)\n */\nexport type DatabaseChangeEvent = {\n /** The database name. The value would be `main` by default and other database names if you use `ATTACH DATABASE` statement. */\n databaseName: string;\n\n /** The absolute file path to the database. */\n databaseFilePath: string;\n\n /** The table name. */\n tableName: string;\n\n /** The changed row ID. */\n rowId: number;\n};\n\n/**\n * Add a listener for database changes.\n * > Note: to enable this feature, you must set [`enableChangeListener` to `true`](#sqliteopenoptions) when opening the database.\n *\n * @param listener A function that receives the `databaseName`, `databaseFilePath`, `tableName` and `rowId` of the modified data.\n * @returns A `Subscription` object that you can call `remove()` on when you would like to unsubscribe the listener.\n */\nexport function addDatabaseChangeListener(\n listener: (event: DatabaseChangeEvent) => void\n): Subscription {\n return emitter.addListener('onDatabaseChange', listener);\n}\n\n/**\n * A new connection specific used for [`withExclusiveTransactionAsync`](#withexclusivetransactionasynctask).\n * @hidden not going to pull all the database methods to the document.\n */\nclass Transaction extends SQLiteDatabase {\n public static async createAsync(db: SQLiteDatabase): Promise<Transaction> {\n const options = { ...db.options, useNewConnection: true };\n const nativeDatabase = new ExpoSQLite.NativeDatabase(db.databaseName, options);\n await nativeDatabase.initAsync();\n return new Transaction(db.databaseName, options, nativeDatabase);\n }\n}\n"]}
@@ -1,6 +1,9 @@
1
1
  require 'json'
2
2
 
3
3
  package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
4
+ podfile_properties = JSON.parse(File.read("#{Pod::Config.instance.installation_root}/Podfile.properties.json")) rescue {}
5
+
6
+ sqliteVersion = '3.42.0'
4
7
 
5
8
  Pod::Spec.new do |s|
6
9
  s.name = 'ExpoSQLite'
@@ -14,8 +17,12 @@ Pod::Spec.new do |s|
14
17
  s.source = { git: 'https://github.com/expo/expo.git' }
15
18
  s.static_framework = true
16
19
  s.dependency 'ExpoModulesCore'
17
- # The builtin sqlite does not support extensions so we update it
18
- s.dependency 'sqlite3', '~> 3.42.0'
20
+
21
+ s.dependency 'sqlite3', "~> #{sqliteVersion}"
22
+ unless podfile_properties['expo.sqlite.enableFTS'] === 'false'
23
+ s.dependency 'sqlite3/fts', "~> #{sqliteVersion}"
24
+ s.dependency 'sqlite3/fts5', "~> #{sqliteVersion}"
25
+ end
19
26
 
20
27
  # Swift/Objective-C compatibility
21
28
  s.pod_target_xcconfig = {
@@ -48,19 +48,24 @@ public final class SQLiteModuleNext: Module {
48
48
 
49
49
  // swiftlint:disable:next closure_body_length
50
50
  Class(NativeDatabase.self) {
51
- Constructor { (databaseName: String, options: OpenDatabaseOptions) -> NativeDatabase in
52
- guard let path = pathForDatabaseName(name: databaseName) else {
53
- throw DatabaseException()
54
- }
55
-
56
- // Try to find opened database for fast refresh
57
- if let cachedDb = findCachedDatabase(where: { $0.databaseName == databaseName && $0.openOptions == options && !options.useNewConnection }) {
58
- return cachedDb
59
- }
60
-
51
+ Constructor { (databaseName: String, options: OpenDatabaseOptions, serializedData: Data?) -> NativeDatabase in
61
52
  var db: OpaquePointer?
62
- if sqlite3_open(path.absoluteString, &db) != SQLITE_OK {
63
- throw DatabaseException()
53
+
54
+ if let serializedData = serializedData {
55
+ db = try deserializeDatabase(serializedData)
56
+ } else {
57
+ guard let path = pathForDatabaseName(name: databaseName) else {
58
+ throw DatabaseException()
59
+ }
60
+
61
+ // Try to find opened database for fast refresh
62
+ if let cachedDb = findCachedDatabase(where: { $0.databaseName == databaseName && $0.openOptions == options && !options.useNewConnection }) {
63
+ return cachedDb
64
+ }
65
+
66
+ if sqlite3_open(path.absoluteString, &db) != SQLITE_OK {
67
+ throw DatabaseException()
68
+ }
64
69
  }
65
70
 
66
71
  let database = NativeDatabase(db, databaseName: databaseName, openOptions: options)
@@ -100,6 +105,13 @@ public final class SQLiteModuleNext: Module {
100
105
  try exec(database: database, source: source)
101
106
  }
102
107
 
108
+ AsyncFunction("serializeAsync") { (database: NativeDatabase, databaseName: String) in
109
+ try serialize(database: database, databaseName: databaseName)
110
+ }
111
+ Function("serializeSync") { (database: NativeDatabase, databaseName: String) in
112
+ try serialize(database: database, databaseName: databaseName)
113
+ }
114
+
103
115
  AsyncFunction("prepareAsync") { (database: NativeDatabase, statement: NativeStatement, source: String) in
104
116
  try prepareStatement(database: database, statement: statement, source: source)
105
117
  }
@@ -176,6 +188,30 @@ public final class SQLiteModuleNext: Module {
176
188
  return directory?.appendingPathComponent(name)
177
189
  }
178
190
 
191
+ private func deserializeDatabase(_ serializedData: Data) throws -> OpaquePointer? {
192
+ var db: OpaquePointer?
193
+ if sqlite3_open(MEMORY_DB_NAME, &db) != SQLITE_OK {
194
+ throw DatabaseException()
195
+ }
196
+ let size = sqlite3_int64(serializedData.count)
197
+ guard let buffer = sqlite3_malloc64(sqlite3_uint64(size)) else {
198
+ throw SQLiteErrorException("Unable to allocate memory for \(size) bytes")
199
+ }
200
+ try serializedData.withUnsafeBytes {
201
+ guard let baseAddress = $0.baseAddress else {
202
+ sqlite3_free(buffer)
203
+ throw SQLiteErrorException("Unable to get allocated memory base address")
204
+ }
205
+ memcpy(buffer, baseAddress, Int(size))
206
+ }
207
+ let flags = UInt32(SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE)
208
+ let ret = sqlite3_deserialize(db, "main", buffer.assumingMemoryBound(to: UInt8.self), size, size, flags)
209
+ if ret != SQLITE_OK {
210
+ throw SQLiteErrorException(convertSqlLiteErrorToString(db))
211
+ }
212
+ return db
213
+ }
214
+
179
215
  private func initDb(database: NativeDatabase) throws {
180
216
  try maybeThrowForClosedDatabase(database)
181
217
  if database.openOptions.enableCRSQLite {
@@ -197,6 +233,19 @@ public final class SQLiteModuleNext: Module {
197
233
  }
198
234
  }
199
235
 
236
+ private func serialize(database: NativeDatabase, databaseName: String) throws -> Data {
237
+ try maybeThrowForClosedDatabase(database)
238
+
239
+ var size: sqlite3_int64 = 0
240
+ guard let bytes = sqlite3_serialize(database.pointer, databaseName, &size, 0) else {
241
+ throw SQLiteErrorException(convertSqlLiteErrorToString(database))
242
+ }
243
+
244
+ let serializedData = Data(bytes: bytes, count: Int(size))
245
+ sqlite3_free(bytes)
246
+ return serializedData
247
+ }
248
+
200
249
  private func prepareStatement(database: NativeDatabase, statement: NativeStatement, source: String) throws {
201
250
  try maybeThrowForClosedDatabase(database)
202
251
  try maybeThrowForFinalizedStatement(statement)
@@ -289,12 +338,16 @@ public final class SQLiteModuleNext: Module {
289
338
  statement.isFinalized = true
290
339
  }
291
340
 
292
- private func convertSqlLiteErrorToString(_ db: NativeDatabase) -> String {
293
- let code = sqlite3_errcode(db.pointer)
294
- let message = String(cString: sqlite3_errmsg(db.pointer), encoding: .utf8) ?? ""
341
+ private func convertSqlLiteErrorToString(_ db: OpaquePointer?) -> String {
342
+ let code = sqlite3_errcode(db)
343
+ let message = String(cString: sqlite3_errmsg(db), encoding: .utf8) ?? ""
295
344
  return "Error code \(code): \(message)"
296
345
  }
297
346
 
347
+ private func convertSqlLiteErrorToString(_ db: NativeDatabase) -> String {
348
+ return convertSqlLiteErrorToString(db.pointer)
349
+ }
350
+
298
351
  private func closeDatabase(_ db: NativeDatabase) throws {
299
352
  try maybeThrowForClosedDatabase(db)
300
353
  for removedStatement in maybeRemoveAllCachedStatements(database: db) {
package/package.json CHANGED
@@ -1,10 +1,20 @@
1
1
  {
2
2
  "name": "expo-sqlite",
3
- "version": "13.2.2",
3
+ "version": "13.4.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",
7
7
  "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "default": "./build/index.js",
11
+ "types": "./build/index.d.ts"
12
+ },
13
+ "./next": {
14
+ "default": "./build/next/index.js",
15
+ "types": "./build/next/index.d.ts"
16
+ }
17
+ },
8
18
  "scripts": {
9
19
  "build": "expo-module build",
10
20
  "clean": "expo-module clean",
@@ -47,5 +57,5 @@
47
57
  "peerDependencies": {
48
58
  "expo": "*"
49
59
  },
50
- "gitHead": "ba36acbbe93bac3114612bd578619de9663c2a16"
60
+ "gitHead": "74264a222fcc02d5885b451597113df852d272fb"
51
61
  }
@@ -5,7 +5,11 @@ export default {
5
5
  return 'ExpoSQLiteNext';
6
6
  },
7
7
 
8
- NativeDatabase(databaseName: string, options?: SQLiteOpenOptions): void {
8
+ NativeDatabase(
9
+ databaseName: string,
10
+ options?: SQLiteOpenOptions,
11
+ serializedData?: Uint8Array
12
+ ): void {
9
13
  throw new Error('Unimplemented');
10
14
  },
11
15
 
@@ -4,7 +4,7 @@ import { NativeStatement } from './NativeStatement';
4
4
  * A class that represents an instance of the SQLite database.
5
5
  */
6
6
  export declare class NativeDatabase {
7
- constructor(databaseName: string, options?: SQLiteOpenOptions);
7
+ constructor(databaseName: string, options?: SQLiteOpenOptions, serializedData?: Uint8Array);
8
8
 
9
9
  //#region Asynchronous API
10
10
 
@@ -12,6 +12,7 @@ export declare class NativeDatabase {
12
12
  public isInTransactionAsync(): Promise<boolean>;
13
13
  public closeAsync(): Promise<void>;
14
14
  public execAsync(source: string): Promise<void>;
15
+ public serializeAsync(databaseName: string): Promise<Uint8Array>;
15
16
  public prepareAsync(nativeStatement: NativeStatement, source: string): Promise<NativeStatement>;
16
17
 
17
18
  //#endregion
@@ -22,6 +23,7 @@ export declare class NativeDatabase {
22
23
  public isInTransactionSync(): boolean;
23
24
  public closeSync(): void;
24
25
  public execSync(source: string): void;
26
+ public serializeSync(databaseName: string): Uint8Array;
25
27
  public prepareSync(nativeStatement: NativeStatement, source: string): NativeStatement;
26
28
 
27
29
  //#endregion
@@ -49,6 +49,15 @@ export class SQLiteDatabase {
49
49
  return this.nativeDatabase.execAsync(source);
50
50
  }
51
51
 
52
+ /**
53
+ * [Serialize the database](https://sqlite.org/c3ref/serialize.html) as `Uint8Array`.
54
+ *
55
+ * @param databaseName The name of the current attached databases. The default value is `main` which is the default database name.
56
+ */
57
+ public serializeAsync(databaseName: string = 'main'): Promise<Uint8Array> {
58
+ return this.nativeDatabase.serializeAsync(databaseName);
59
+ }
60
+
52
61
  /**
53
62
  * Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).
54
63
  *
@@ -158,6 +167,17 @@ export class SQLiteDatabase {
158
167
  return this.nativeDatabase.execSync(source);
159
168
  }
160
169
 
170
+ /**
171
+ * [Serialize the database](https://sqlite.org/c3ref/serialize.html) as `Uint8Array`.
172
+ *
173
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
174
+ *
175
+ * @param databaseName The name of the current attached databases. The default value is `main` which is the default database name.
176
+ */
177
+ public serializeSync(databaseName: string = 'main'): Uint8Array {
178
+ return this.nativeDatabase.serializeSync(databaseName);
179
+ }
180
+
161
181
  /**
162
182
  * Create a [prepared SQLite statement](https://www.sqlite.org/c3ref/prepare.html).
163
183
  *
@@ -423,6 +443,40 @@ export function openDatabaseSync(
423
443
  return new SQLiteDatabase(databaseName, openOptions, nativeDatabase);
424
444
  }
425
445
 
446
+ /**
447
+ * Given a `Uint8Array` data and [deserialize to memory database](https://sqlite.org/c3ref/deserialize.html).
448
+ *
449
+ * @param serializedData The binary array to deserialize from [`SQLiteDatabase.serializeAsync()`](#serializeasyncdatabasename).
450
+ * @param options Open options.
451
+ */
452
+ export async function deserializeDatabaseAsync(
453
+ serializedData: Uint8Array,
454
+ options?: SQLiteOpenOptions
455
+ ): Promise<SQLiteDatabase> {
456
+ const openOptions = options ?? {};
457
+ const nativeDatabase = new ExpoSQLite.NativeDatabase(':memory:', openOptions, serializedData);
458
+ await nativeDatabase.initAsync();
459
+ return new SQLiteDatabase(':memory:', openOptions, nativeDatabase);
460
+ }
461
+
462
+ /**
463
+ * Given a `Uint8Array` data and [deserialize to memory database](https://sqlite.org/c3ref/deserialize.html).
464
+ *
465
+ * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.
466
+ *
467
+ * @param serializedData The binary array to deserialize from [`SQLiteDatabase.serializeSync()`](#serializesyncdatabasename)
468
+ * @param options Open options.
469
+ */
470
+ export function deserializeDatabaseSync(
471
+ serializedData: Uint8Array,
472
+ options?: SQLiteOpenOptions
473
+ ): SQLiteDatabase {
474
+ const openOptions = options ?? {};
475
+ const nativeDatabase = new ExpoSQLite.NativeDatabase(':memory:', openOptions, serializedData);
476
+ nativeDatabase.initSync();
477
+ return new SQLiteDatabase(':memory:', openOptions, nativeDatabase);
478
+ }
479
+
426
480
  /**
427
481
  * Delete a database file.
428
482
  *