@op-engineering/op-sqlite 1.0.14 → 2.0.1

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/README.md CHANGED
@@ -16,43 +16,89 @@ Created by [@ospfranco](https://twitter.com/ospfranco). **Please consider Sponso
16
16
 
17
17
  ## Benchmarks
18
18
 
19
- You can find the [benchmarking code in the example app](https://github.com/OP-Engineering/op-sqlite/blob/main/example/src/Database.ts#L44). You should expect anywhere between a 5x to a 8x improvement over non-JSI packages, and now a 5x to 8x improvement over quick-sqlite and expo-sqlite. Loading a 300k record database (in milliseconds).
19
+ You can find the [benchmarking code in the example app](https://github.com/OP-Engineering/op-sqlite/blob/main/example/src/Database.ts#L44). You should expect anywhere between a 5x to an 8x improvement over non-JSI packages, and now a 5x to 8x improvement over quick-sqlite and expo-sqlite. Loading a 300k record database (in milliseconds).
20
20
 
21
21
  ![benchmark](benchmark.png)
22
22
 
23
- Memory consumption is also is also 1/4 compared to `react-native-quick-sqlite`. This query used to take 1.2gb of peak memory usage, now runs in 250mbs.
23
+ Memory consumption is also 1/4 compared to `react-native-quick-sqlite`. This query used to take 1.2 GB of peak memory usage, and now runs in 250mbs.
24
24
 
25
25
  # Encryption
26
26
 
27
- If you need to encrypt your entire database, there is [`op-sqlcipher`](https://github.com/OP-Engineering/op-sqlcipher), which is a fork of this library which uses [SQLCipher](https://github.com/sqlcipher/sqlcipher). It completely encrypts all the database with minimal overhead. Bear in mind, however, it is a fork maintained by a third-party.
27
+ If you need to encrypt your entire database, there is [`op-sqlcipher`](https://github.com/OP-Engineering/op-sqlcipher), which is a fork of this library that uses [SQLCipher](https://github.com/sqlcipher/sqlcipher). It completely encrypts the database with minimal overhead.
28
28
 
29
- # DB Paths
29
+ # Database Location
30
30
 
31
- The library creates/opens databases by appending the passed name plus, the [library directory on iOS](https://github.com/OP-Engineering/op-sqlite/blob/main/ios/OPSQLite.mm#L51) and the [database directory on Android](https://github.com/OP-Engineering/op-sqlite/blob/main/android/src/main/java/com/op/sqlite/OPSQLiteBridge.java#L18). If you are migrating from `react-native-quick-sqlite` you will have to move your library using one of the many react-native fs libraries.
31
+ ## Default location
32
32
 
33
- If you have an existing database file you want to load you can navigate from these directories using dot notation. e.g.:
33
+ If you don't pass a `location` the library creates/opens databases by appending the passed name plus, the [library directory on iOS](https://github.com/OP-Engineering/op-sqlite/blob/main/ios/OPSQLite.mm#L51) and the [database directory on Android](https://github.com/OP-Engineering/op-sqlite/blob/main/android/src/main/java/com/op/sqlite/OPSQLiteBridge.java#L18).
34
+
35
+ ## Relative location
36
+
37
+ You can use relative location to navigate in and out of the **default location**
34
38
 
35
39
  ```ts
36
40
  import { open } from '@op-engineering/op-sqlite';
37
41
 
38
- const largeDb = open({
39
- name: 'largeDB',
42
+ const db = open({
43
+ name: 'myDB',
40
44
  location: '../files/databases',
41
45
  });
42
46
  ```
43
47
 
44
48
  Note that on iOS the file system is sand-boxed, so you cannot access files/directories outside your app bundle directories.
45
49
 
50
+ ## Passing absolute paths
51
+
52
+ You can also pass absolute paths to completely change the location of the database, the library exports useful paths you can use:
53
+
54
+ ```ts
55
+ import {
56
+ IOS_LIBRARY_PATH, // Default iOS
57
+ IOS_DOCUMENT_PATH,
58
+ ANDROID_DATABASE_PATH, // Default Android
59
+ ANDROID_FILES_PATH,
60
+ ANDROID_EXTERNAL_FILES_PATH,
61
+ open,
62
+ } from '@op-engineering/op-sqlite';
63
+
64
+ const db = open({
65
+ name: 'myDb',
66
+ location: Platform.OS === 'ios' ? IOS_LIBRARY_PATH : ANDROID_DATABASE_PATH,
67
+ });
68
+ ```
69
+
70
+ Here is an example if you want to access the SD card app's directory:
71
+
72
+ ```ts
73
+ const db = open({
74
+ name: 'myDB',
75
+ location:
76
+ Platform.OS === 'ios' ? IOS_LIBRARY_PATH : ANDROID_EXTERNAL_FILES_PATH,
77
+ });
78
+ ```
79
+
80
+ You can even drill down:
81
+
82
+ ```ts
83
+ const db = open({
84
+ name: 'myDB',
85
+ location:
86
+ Platform.OS === 'ios'
87
+ ? IOS_LIBRARY_PATH
88
+ : `${ANDROID_EXTERNAL_FILES_PATH}/dbs/`,
89
+ });
90
+ ```
91
+
46
92
  ## In-memory
47
93
 
48
- Using SQLite in-memory mode is supported:
94
+ Using SQLite in-memory mode is supported by passing a `':memory:'` as a location:
49
95
 
50
96
  ```ts
51
97
  import { open } from '@op-engineering/op-sqlite';
52
98
 
53
99
  const largeDb = open({
54
100
  name: 'inMemoryDb',
55
- inMemory: true,
101
+ location: ':memory:',
56
102
  });
57
103
  ```
58
104
 
@@ -47,11 +47,9 @@ set_target_properties(
47
47
 
48
48
  find_package(ReactAndroid REQUIRED CONFIG)
49
49
  find_package(fbjni REQUIRED CONFIG)
50
- find_library(LOG_LIB log)
51
50
 
52
51
  target_link_libraries(
53
52
  ${PACKAGE_NAME}
54
- ${LOG_LIB}
55
53
  fbjni::fbjni
56
54
  ReactAndroid::jsi
57
55
  ReactAndroid::turbomodulejsijni
@@ -12,7 +12,7 @@ struct OPSQLiteBridge : jni::JavaClass<OPSQLiteBridge> {
12
12
 
13
13
  static void registerNatives() {
14
14
  javaClassStatic()->registerNatives(
15
- {// initialization for JSI
15
+ {
16
16
  makeNativeMethod("installNativeJsi",
17
17
  OPSQLiteBridge::installNativeJsi),
18
18
  makeNativeMethod("clearStateNativeJsi",
@@ -24,12 +24,12 @@ private:
24
24
  static void installNativeJsi(
25
25
  jni::alias_ref<jni::JObject> thiz, jlong jsiRuntimePtr,
26
26
  jni::alias_ref<react::CallInvokerHolder::javaobject> jsCallInvokerHolder,
27
- jni::alias_ref<jni::JString> docPath) {
27
+ jni::alias_ref<jni::JString> dbPath) {
28
28
  auto jsiRuntime = reinterpret_cast<jsi::Runtime *>(jsiRuntimePtr);
29
29
  auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker();
30
- std::string docPathString = docPath->toStdString();
30
+ std::string dbPathStr = dbPath->toStdString();
31
31
 
32
- opsqlite::install(*jsiRuntime, jsCallInvoker, docPathString.c_str());
32
+ opsqlite::install(*jsiRuntime, jsCallInvoker, dbPathStr.c_str());
33
33
  }
34
34
 
35
35
  static void clearStateNativeJsi(jni::alias_ref<jni::JObject> thiz) {
@@ -1,14 +1,11 @@
1
1
  package com.op.sqlite;
2
2
 
3
3
  import androidx.annotation.NonNull;
4
- import android.util.Log;
5
-
6
- import com.facebook.jni.HybridData;
7
- import com.facebook.jni.annotations.DoNotStrip;
8
4
  import com.facebook.react.bridge.ReactApplicationContext;
9
5
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
10
6
  import com.facebook.react.bridge.ReactMethod;
11
- import com.facebook.react.turbomodule.core.CallInvokerHolderImpl;
7
+ import java.util.HashMap;
8
+ import java.util.Map;
12
9
 
13
10
  class OPSQLiteModule extends ReactContextBaseJavaModule {
14
11
  public static final String NAME = "OPSQLite";
@@ -23,6 +20,25 @@ class OPSQLiteModule extends ReactContextBaseJavaModule {
23
20
  return NAME;
24
21
  }
25
22
 
23
+ @Override
24
+ public Map<String, Object> getConstants() {
25
+ final Map<String, Object> constants = new HashMap<>();
26
+ ReactApplicationContext context = getReactApplicationContext();
27
+ final String dbPath = context
28
+ .getDatabasePath("defaultDatabase")
29
+ .getAbsolutePath()
30
+ .replace("defaultDatabase", "");
31
+ constants.put("ANDROID_DATABASE_PATH", dbPath);
32
+
33
+ final String filesPath = context.getFilesDir().getAbsolutePath();
34
+ constants.put("ANDROID_FILES_PATH", filesPath);
35
+
36
+ final String externalFilesDir = context.getExternalFilesDir(null).getAbsolutePath();
37
+ constants.put("ANDROID_EXTERNAL_FILES_PATH", externalFilesDir);
38
+
39
+ return constants;
40
+ }
41
+
26
42
  @ReactMethod(isBlockingSynchronousMethod = true)
27
43
  public boolean install() {
28
44
  try {
@@ -30,17 +46,12 @@ class OPSQLiteModule extends ReactContextBaseJavaModule {
30
46
  OPSQLiteBridge.instance.install(getReactApplicationContext());
31
47
  return true;
32
48
  } catch (Exception exception) {
33
- Log.e(NAME, "Failed to install JSI Bindings!", exception);
34
49
  return false;
35
50
  }
36
51
  }
37
52
 
38
53
  @Override
39
54
  public void onCatalystInstanceDestroy() {
40
- try {
41
- OPSQLiteBridge.instance.clearState();
42
- } catch (Exception exception) {
43
- Log.e(NAME, "Failed to clear state!", exception);
44
- }
55
+ OPSQLiteBridge.instance.clearState();
45
56
  }
46
57
  }
package/cpp/bindings.cpp CHANGED
@@ -54,8 +54,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
54
54
  }
55
55
 
56
56
  std::string dbName = args[0].asString(rt).utf8(rt);
57
- std::string tempDocPath = std::string(basePath);
58
- bool memoryStorage = false;
57
+ std::string path = std::string(basePath);
59
58
 
60
59
  if (count > 1 && !args[1].isUndefined() && !args[1].isNull())
61
60
  {
@@ -63,19 +62,19 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
63
62
  {
64
63
  throw jsi::JSError(rt, "[op-sqlite][open] database location must be a string");
65
64
  }
66
-
67
- tempDocPath = tempDocPath + "/" + args[1].asString(rt).utf8(rt);
68
- }
69
-
70
- if(count == 3) {
71
- if(!args[2].isBool()) {
72
- throw jsi::JSError(rt, "[op-sqlite][open] memoryStorage must be a bool");
65
+
66
+ std::string lastPath = args[1].asString(rt).utf8(rt);
67
+
68
+ if(lastPath == ":memory:") {
69
+ path = ":memory:";
70
+ } else if( lastPath.rfind("/", 0) == 0) {
71
+ path = lastPath;
72
+ } else {
73
+ path = path + "/" + lastPath;
73
74
  }
74
-
75
- memoryStorage = args[2].asBool();
76
75
  }
77
76
 
78
- BridgeResult result = sqliteOpenDb(dbName, tempDocPath, memoryStorage);
77
+ BridgeResult result = sqliteOpenDb(dbName, path);
79
78
 
80
79
  if (result.type == SQLiteError)
81
80
  {
package/cpp/bridge.cpp CHANGED
@@ -83,15 +83,18 @@ namespace opsqlite {
83
83
  return (stat(path.c_str(), &buffer) == 0);
84
84
  }
85
85
 
86
- std::string get_db_path(std::string const dbName, std::string const docPath)
86
+ std::string get_db_path(std::string const dbName, std::string const lastPath)
87
87
  {
88
- mkdir(docPath.c_str());
89
- return docPath + "/" + dbName;
88
+ if(lastPath == ":memory:") {
89
+ return lastPath;
90
+ }
91
+ mkdir(lastPath.c_str());
92
+ return lastPath + "/" + dbName;
90
93
  }
91
94
 
92
- BridgeResult sqliteOpenDb(std::string const dbName, std::string const docPath, bool memoryStorage)
95
+ BridgeResult sqliteOpenDb(std::string const dbName, std::string const lastPath)
93
96
  {
94
- std::string dbPath = memoryStorage ? ":memory:" : get_db_path(dbName, docPath);
97
+ std::string dbPath = get_db_path(dbName, lastPath);
95
98
 
96
99
  int sqlOpenFlags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX;
97
100
 
package/cpp/bridge.h CHANGED
@@ -11,7 +11,7 @@ namespace opsqlite {
11
11
 
12
12
  namespace jsi = facebook::jsi;
13
13
 
14
- BridgeResult sqliteOpenDb(std::string const dbName, std::string const docPath, bool memoryStorage);
14
+ BridgeResult sqliteOpenDb(std::string const dbName, std::string const dbPath);
15
15
 
16
16
  BridgeResult sqliteCloseDb(std::string const dbName);
17
17
 
package/ios/OPSQLite.mm CHANGED
@@ -7,13 +7,33 @@
7
7
 
8
8
  @implementation OPSQLite
9
9
 
10
+ @synthesize bridge=_bridge;
11
+
10
12
  RCT_EXPORT_MODULE(OPSQLite)
11
13
 
12
- RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
13
- NSLog(@"Initializing OP-SQLite module...");
14
+ - (void)setBridge:(RCTBridge *)bridge {
15
+ _bridge = bridge;
16
+ }
17
+
18
+ + (BOOL)requiresMainQueueSetup
19
+ {
20
+ return YES;
21
+ }
22
+
23
+ - (NSDictionary *)constantsToExport {
24
+ NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, true);
25
+ NSString *libraryPath = [libraryPaths objectAtIndex:0];
14
26
 
15
- RCTBridge *bridge = [RCTBridge currentBridge];
16
- RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge;
27
+ NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true);
28
+ NSString *documentPath = [documentPaths objectAtIndex:0];
29
+ return @{
30
+ @"IOS_DOCUMENT_PATH": documentPath,
31
+ @"IOS_LIBRARY_PATH": libraryPath
32
+ };
33
+ }
34
+
35
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
36
+ RCTCxxBridge *cxxBridge = (RCTCxxBridge *)_bridge;
17
37
  if (cxxBridge == nil) {
18
38
  return @false;
19
39
  }
@@ -25,7 +45,7 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
25
45
  return @false;
26
46
  }
27
47
  auto &runtime = *jsiRuntime;
28
- auto callInvoker = bridge.jsCallInvoker;
48
+ auto callInvoker = _bridge.jsCallInvoker;
29
49
 
30
50
  // Get appGroupID value from Info.plist using key "AppGroup"
31
51
  NSString *appGroupID = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"OPSQLite_AppGroup"];
@@ -37,10 +57,9 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
37
57
  NSURL *storeUrl = [fileManager containerURLForSecurityApplicationGroupIdentifier:appGroupID];
38
58
 
39
59
  if (storeUrl == nil) {
40
- NSLog(@"Invalid AppGroup ID provided (%@). Check the value of \"AppGroup\" in your Info.plist file", appGroupID);
60
+ NSLog(@"OP-SQLite: Invalid AppGroup ID provided (%@). Check the value of \"AppGroup\" in your Info.plist file", appGroupID);
41
61
  return @false;
42
62
  }
43
- NSLog(@"Configured with AppGroup ID: %@", appGroupID);
44
63
 
45
64
  documentPath = [storeUrl path];
46
65
  } else {
@@ -49,8 +68,6 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
49
68
  }
50
69
 
51
70
  opsqlite::install(runtime, callInvoker, [documentPath UTF8String]);
52
-
53
- NSLog(@"OP-SQLite initialized");
54
71
  return @true;
55
72
  }
56
73
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.open = exports.OPSQLite = void 0;
6
+ exports.open = exports.OPSQLite = exports.IOS_LIBRARY_PATH = exports.IOS_DOCUMENT_PATH = exports.ANDROID_FILES_PATH = exports.ANDROID_EXTERNAL_FILES_PATH = exports.ANDROID_DATABASE_PATH = void 0;
7
7
  var _reactNative = require("react-native");
8
8
  if (global.__OPSQLiteProxy == null) {
9
9
  const OPSQLiteModule = _reactNative.NativeModules.OPSQLite;
@@ -29,6 +29,14 @@ if (global.__OPSQLiteProxy == null) {
29
29
  }
30
30
  const proxy = global.__OPSQLiteProxy;
31
31
  const OPSQLite = proxy;
32
+ exports.OPSQLite = OPSQLite;
33
+ const {
34
+ IOS_DOCUMENT_PATH,
35
+ IOS_LIBRARY_PATH,
36
+ ANDROID_DATABASE_PATH,
37
+ ANDROID_FILES_PATH,
38
+ ANDROID_EXTERNAL_FILES_PATH
39
+ } = _reactNative.NativeModules.OPSQLite;
32
40
 
33
41
  /**
34
42
  * Object returned by SQL Query executions {
@@ -40,7 +48,11 @@ const OPSQLite = proxy;
40
48
  *
41
49
  * @interface QueryResult
42
50
  */
43
- exports.OPSQLite = OPSQLite;
51
+ exports.ANDROID_EXTERNAL_FILES_PATH = ANDROID_EXTERNAL_FILES_PATH;
52
+ exports.ANDROID_FILES_PATH = ANDROID_FILES_PATH;
53
+ exports.ANDROID_DATABASE_PATH = ANDROID_DATABASE_PATH;
54
+ exports.IOS_LIBRARY_PATH = IOS_LIBRARY_PATH;
55
+ exports.IOS_DOCUMENT_PATH = IOS_DOCUMENT_PATH;
44
56
  const locks = {};
45
57
 
46
58
  // Enhance some host functions
@@ -65,8 +77,8 @@ function enhanceQueryResult(result) {
65
77
  }
66
78
  }
67
79
  const _open = OPSQLite.open;
68
- OPSQLite.open = (dbName, location, inMemory) => {
69
- _open(dbName, location, !!inMemory);
80
+ OPSQLite.open = (dbName, location) => {
81
+ _open(dbName, location);
70
82
  locks[dbName] = {
71
83
  queue: [],
72
84
  inProgress: false
@@ -193,7 +205,7 @@ const startNextTransaction = dbName => {
193
205
  }
194
206
  };
195
207
  const open = options => {
196
- OPSQLite.open(options.name, options.location, options.inMemory);
208
+ OPSQLite.open(options.name, options.location);
197
209
  return {
198
210
  close: () => OPSQLite.close(options.name),
199
211
  delete: () => OPSQLite.delete(options.name, options.location),
@@ -1 +1 @@
1
- {"version":3,"names":["global","__OPSQLiteProxy","OPSQLiteModule","NativeModules","OPSQLite","Error","nativeCallSyncHook","install","result","proxy","locks","enhanceQueryResult","rows","_array","length","item","idx","_open","open","dbName","location","inMemory","queue","inProgress","_close","close","_execute","execute","query","params","sanitizedParams","map","p","ArrayBuffer","isView","buffer","_executeAsync","executeAsync","res","transaction","fn","isFinalized","commit","rollback","run","executionError","rollbackError","startNextTransaction","Promise","resolve","reject","tx","start","then","catch","push","shift","setImmediate","options","name","delete","attach","dbNameToAttach","alias","detach","executeBatch","commands","executeBatchAsync","loadFile","updateHook","callback","commitHook","rollbackHook"],"sources":["index.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\ndeclare global {\n function nativeCallSyncHook(): unknown;\n var __OPSQLiteProxy: object | undefined;\n}\n\nif (global.__OPSQLiteProxy == null) {\n const OPSQLiteModule = NativeModules.OPSQLite;\n\n if (OPSQLiteModule == null) {\n throw new Error('Base module not found. Maybe try rebuilding the app.');\n }\n\n // Check if we are running on-device (JSI)\n if (global.nativeCallSyncHook == null || OPSQLiteModule.install == null) {\n throw new Error(\n 'Failed to install op-sqlite: React Native is not running on-device. OPSQLite can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.'\n );\n }\n\n // Call the synchronous blocking install() function\n const result = OPSQLiteModule.install();\n if (result !== true) {\n throw new Error(\n `Failed to install op-sqlite: The native OPSQLite Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`\n );\n }\n\n // Check again if the constructor now exists. If not, throw an error.\n if (global.__OPSQLiteProxy == null) {\n throw new Error(\n 'Failed to install op-sqlite, the native initializer function does not exist. Are you trying to use OPSQLite from different JS Runtimes?'\n );\n }\n}\n\nconst proxy = global.__OPSQLiteProxy;\nexport const OPSQLite = proxy as ISQLite;\n\n/**\n * Object returned by SQL Query executions {\n * insertId: Represent the auto-generated row id if applicable\n * rowsAffected: Number of affected rows if result of a update query\n * message: if status === 1, here you will find error description\n * rows: if status is undefined or 0 this object will contain the query results\n * }\n *\n * @interface QueryResult\n */\nexport type QueryResult = {\n insertId?: number;\n rowsAffected: number;\n rows?: {\n /** Raw array with all dataset */\n _array: any[];\n /** The lengh of the dataset */\n length: number;\n /** A convenience function to acess the index based the row object\n * @param idx the row index\n * @returns the row structure identified by column names\n */\n item: (idx: number) => any;\n };\n /**\n * Query metadata, avaliable only for select query results\n */\n metadata?: ColumnMetadata[];\n};\n\n/**\n * Column metadata\n * Describes some information about columns fetched by the query\n */\nexport type ColumnMetadata = {\n /** The name used for this column for this resultset */\n name: string;\n /** The declared column type for this column, when fetched directly from a table or a View resulting from a table column. \"UNKNOWN\" for dynamic values, like function returned ones. */\n type: string;\n /**\n * The index for this column for this resultset*/\n index: number;\n};\n\n/**\n * Allows the execution of bulk of sql commands\n * inside a transaction\n * If a single query must be executed many times with different arguments, its preferred\n * to declare it a single time, and use an array of array parameters.\n */\nexport type SQLBatchTuple = [string] | [string, Array<any> | Array<Array<any>>];\n\nexport type UpdateHookOperation = 'INSERT' | 'DELETE' | 'UPDATE';\n\n/**\n * status: 0 or undefined for correct execution, 1 for error\n * message: if status === 1, here you will find error description\n * rowsAffected: Number of affected rows if status == 0\n */\nexport type BatchQueryResult = {\n rowsAffected?: number;\n};\n\n/**\n * Result of loading a file and executing every line as a SQL command\n * Similar to BatchQueryResult\n */\nexport interface FileLoadResult extends BatchQueryResult {\n commands?: number;\n}\n\nexport interface Transaction {\n commit: () => QueryResult;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ) => Promise<QueryResult>;\n rollback: () => QueryResult;\n}\n\nexport interface PendingTransaction {\n /*\n * The start function should not throw or return a promise because the\n * queue just calls it and does not monitor for failures or completions.\n *\n * It should catch any errors and call the resolve or reject of the wrapping\n * promise when complete.\n *\n * It should also automatically commit or rollback the transaction if needed\n */\n start: () => void;\n}\n\ninterface ISQLite {\n open: (dbName: string, location?: string, inMemory?: boolean) => void;\n close: (dbName: string) => void;\n delete: (dbName: string, location?: string) => void;\n attach: (\n mainDbName: string,\n dbNameToAttach: string,\n alias: string,\n location?: string\n ) => void;\n detach: (mainDbName: string, alias: string) => void;\n transaction: (\n dbName: string,\n fn: (tx: Transaction) => Promise<void>\n ) => Promise<void>;\n execute: (dbName: string, query: string, params?: any[]) => QueryResult;\n executeAsync: (\n dbName: string,\n query: string,\n params?: any[]\n ) => Promise<QueryResult>;\n executeBatch: (dbName: string, commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (\n dbName: string,\n commands: SQLBatchTuple[]\n ) => Promise<BatchQueryResult>;\n loadFile: (dbName: string, location: string) => Promise<FileLoadResult>;\n updateHook: (\n dbName: string,\n callback?: ((params: {\n table: string;\n operation: UpdateHookOperation;\n row?: any;\n rowId: number;\n }) => void) | null\n ) => void;\n commitHook: (dbName: string, callback?: (() => void) | null) => void;\n rollbackHook: (dbName: string, callback?: (() => void) | null) => void;\n}\n\nconst locks: Record<\n string,\n { queue: PendingTransaction[]; inProgress: boolean }\n> = {};\n\n// Enhance some host functions\n\n// Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\nfunction enhanceQueryResult(result: QueryResult): void {\n // Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\n if (result.rows == null) {\n result.rows = {\n _array: [],\n length: 0,\n item: (idx: number) => result.rows?._array[idx],\n };\n } else {\n result.rows.item = (idx: number) => result.rows?._array[idx];\n }\n}\n\nconst _open = OPSQLite.open;\nOPSQLite.open = (dbName: string, location?: string, inMemory?: boolean) => {\n _open(dbName, location, !!inMemory);\n\n locks[dbName] = {\n queue: [],\n inProgress: false,\n };\n};\n\nconst _close = OPSQLite.close;\nOPSQLite.close = (dbName: string) => {\n _close(dbName);\n delete locks[dbName];\n};\n\nconst _execute = OPSQLite.execute;\nOPSQLite.execute = (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): QueryResult => {\n const sanitizedParams = params?.map((p) => {\n if (ArrayBuffer.isView(p)) {\n return p.buffer;\n }\n\n return p;\n });\n\n const result = _execute(dbName, query, sanitizedParams);\n enhanceQueryResult(result);\n return result;\n};\n\nconst _executeAsync = OPSQLite.executeAsync;\nOPSQLite.executeAsync = async (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): Promise<QueryResult> => {\n const sanitizedParams = params?.map((p) => {\n if (ArrayBuffer.isView(p)) {\n return p.buffer;\n }\n\n return p;\n });\n\n const res = await _executeAsync(dbName, query, sanitizedParams);\n enhanceQueryResult(res);\n return res;\n};\n\nOPSQLite.transaction = async (\n dbName: string,\n fn: (tx: Transaction) => Promise<void>\n): Promise<void> => {\n if (!locks[dbName]) {\n throw Error(`SQLite Error: No lock found on db: ${dbName}`);\n }\n\n let isFinalized = false;\n\n // Local transaction context object implementation\n const execute = (query: string, params?: any[]): QueryResult => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.execute(dbName, query, params);\n };\n\n const executeAsync = (query: string, params?: any[] | undefined) => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.executeAsync(dbName, query, params);\n };\n\n const commit = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute commit on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'COMMIT');\n isFinalized = true;\n return result;\n };\n\n const rollback = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute rollback on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'ROLLBACK');\n isFinalized = true;\n return result;\n };\n\n async function run() {\n try {\n await OPSQLite.executeAsync(dbName, 'BEGIN TRANSACTION');\n\n await fn({\n commit,\n execute,\n executeAsync,\n rollback,\n });\n\n if (!isFinalized) {\n commit();\n }\n } catch (executionError) {\n if (!isFinalized) {\n try {\n rollback();\n } catch (rollbackError) {\n throw rollbackError;\n }\n }\n\n throw executionError;\n } finally {\n locks[dbName].inProgress = false;\n isFinalized = false;\n startNextTransaction(dbName);\n }\n }\n\n return await new Promise((resolve, reject) => {\n const tx: PendingTransaction = {\n start: () => {\n run().then(resolve).catch(reject);\n },\n };\n\n locks[dbName].queue.push(tx);\n startNextTransaction(dbName);\n });\n};\n\nconst startNextTransaction = (dbName: string) => {\n if (!locks[dbName]) {\n throw Error(`Lock not found for db: ${dbName}`);\n }\n\n if (locks[dbName].inProgress) {\n // Transaction is already in process bail out\n return;\n }\n\n if (locks[dbName].queue.length) {\n locks[dbName].inProgress = true;\n const tx = locks[dbName].queue.shift();\n\n if (!tx) {\n throw new Error('Could not get a operation on datebase');\n }\n\n setImmediate(() => {\n tx.start();\n });\n }\n};\n\nexport type OPSQLiteConnection = {\n close: () => void;\n delete: () => void;\n attach: (dbNameToAttach: string, alias: string, location?: string) => void;\n detach: (alias: string) => void;\n transaction: (fn: (tx: Transaction) => Promise<void>) => Promise<void>;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (query: string, params?: any[]) => Promise<QueryResult>;\n executeBatch: (commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;\n loadFile: (location: string) => Promise<FileLoadResult>;\n updateHook: (\n callback: ((params: {\n table: string;\n operation: UpdateHookOperation;\n row?: any;\n rowId: number;\n }) => void) | null\n ) => void;\n commitHook: (callback: (() => void) | null) => void;\n rollbackHook: (callback: (() => void) | null) => void;\n};\n\nexport const open = (options: {\n name: string;\n location?: string;\n inMemory?: boolean;\n}): OPSQLiteConnection => {\n OPSQLite.open(options.name, options.location, options.inMemory);\n\n return {\n close: () => OPSQLite.close(options.name),\n delete: () => OPSQLite.delete(options.name, options.location),\n attach: (dbNameToAttach: string, alias: string, location?: string) =>\n OPSQLite.attach(options.name, dbNameToAttach, alias, location),\n detach: (alias: string) => OPSQLite.detach(options.name, alias),\n transaction: (fn: (tx: Transaction) => Promise<void>) =>\n OPSQLite.transaction(options.name, fn),\n execute: (query: string, params?: any[] | undefined): QueryResult =>\n OPSQLite.execute(options.name, query, params),\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ): Promise<QueryResult> =>\n OPSQLite.executeAsync(options.name, query, params),\n executeBatch: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatch(options.name, commands),\n executeBatchAsync: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatchAsync(options.name, commands),\n loadFile: (location: string) => OPSQLite.loadFile(options.name, location),\n updateHook: (callback) => OPSQLite.updateHook(options.name, callback),\n commitHook: (callback) => OPSQLite.commitHook(options.name, callback),\n rollbackHook: (callback) => OPSQLite.rollbackHook(options.name, callback),\n };\n};\n"],"mappings":";;;;;;AAAA;AAOA,IAAIA,MAAM,CAACC,eAAe,IAAI,IAAI,EAAE;EAClC,MAAMC,cAAc,GAAGC,0BAAa,CAACC,QAAQ;EAE7C,IAAIF,cAAc,IAAI,IAAI,EAAE;IAC1B,MAAM,IAAIG,KAAK,CAAC,sDAAsD,CAAC;EACzE;;EAEA;EACA,IAAIL,MAAM,CAACM,kBAAkB,IAAI,IAAI,IAAIJ,cAAc,CAACK,OAAO,IAAI,IAAI,EAAE;IACvE,MAAM,IAAIF,KAAK,CACb,iQAAiQ,CAClQ;EACH;;EAEA;EACA,MAAMG,MAAM,GAAGN,cAAc,CAACK,OAAO,EAAE;EACvC,IAAIC,MAAM,KAAK,IAAI,EAAE;IACnB,MAAM,IAAIH,KAAK,C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,CAACT,OAAO,CAACC,IAAI,EAAEO,QAAQ,CAAC;IACpDE,QAAQ,EAAGhD,QAAgB,IAAKhB,QAAQ,CAACgE,QAAQ,CAACV,OAAO,CAACC,IAAI,EAAEvC,QAAQ,CAAC;IACzEiD,UAAU,EAAGC,QAAQ,IAAKlE,QAAQ,CAACiE,UAAU,CAACX,OAAO,CAACC,IAAI,EAAEW,QAAQ,CAAC;IACrEC,UAAU,EAAGD,QAAQ,IAAKlE,QAAQ,CAACmE,UAAU,CAACb,OAAO,CAACC,IAAI,EAAEW,QAAQ,CAAC;IACrEE,YAAY,EAAGF,QAAQ,IAAKlE,QAAQ,CAACoE,YAAY,CAACd,OAAO,CAACC,IAAI,EAAEW,QAAQ;EAC1E,CAAC;AACH,CAAC;AAAC"}
1
+ {"version":3,"names":["global","__OPSQLiteProxy","OPSQLiteModule","NativeModules","OPSQLite","Error","nativeCallSyncHook","install","result","proxy","IOS_DOCUMENT_PATH","IOS_LIBRARY_PATH","ANDROID_DATABASE_PATH","ANDROID_FILES_PATH","ANDROID_EXTERNAL_FILES_PATH","locks","enhanceQueryResult","rows","_array","length","item","idx","_open","open","dbName","location","queue","inProgress","_close","close","_execute","execute","query","params","sanitizedParams","map","p","ArrayBuffer","isView","buffer","_executeAsync","executeAsync","res","transaction","fn","isFinalized","commit","rollback","run","executionError","rollbackError","startNextTransaction","Promise","resolve","reject","tx","start","then","catch","push","shift","setImmediate","options","name","delete","attach","dbNameToAttach","alias","detach","executeBatch","commands","executeBatchAsync","loadFile","updateHook","callback","commitHook","rollbackHook"],"sources":["index.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\ndeclare global {\n function nativeCallSyncHook(): unknown;\n var __OPSQLiteProxy: object | undefined;\n}\n\nif (global.__OPSQLiteProxy == null) {\n const OPSQLiteModule = NativeModules.OPSQLite;\n\n if (OPSQLiteModule == null) {\n throw new Error('Base module not found. Maybe try rebuilding the app.');\n }\n\n // Check if we are running on-device (JSI)\n if (global.nativeCallSyncHook == null || OPSQLiteModule.install == null) {\n throw new Error(\n 'Failed to install op-sqlite: React Native is not running on-device. OPSQLite can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.'\n );\n }\n\n // Call the synchronous blocking install() function\n const result = OPSQLiteModule.install();\n if (result !== true) {\n throw new Error(\n `Failed to install op-sqlite: The native OPSQLite Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`\n );\n }\n\n // Check again if the constructor now exists. If not, throw an error.\n if (global.__OPSQLiteProxy == null) {\n throw new Error(\n 'Failed to install op-sqlite, the native initializer function does not exist. Are you trying to use OPSQLite from different JS Runtimes?'\n );\n }\n}\n\nconst proxy = global.__OPSQLiteProxy;\nexport const OPSQLite = proxy as ISQLite;\n\nexport const {\n IOS_DOCUMENT_PATH,\n IOS_LIBRARY_PATH,\n ANDROID_DATABASE_PATH,\n ANDROID_FILES_PATH,\n ANDROID_EXTERNAL_FILES_PATH,\n} = NativeModules.OPSQLite;\n\n/**\n * Object returned by SQL Query executions {\n * insertId: Represent the auto-generated row id if applicable\n * rowsAffected: Number of affected rows if result of a update query\n * message: if status === 1, here you will find error description\n * rows: if status is undefined or 0 this object will contain the query results\n * }\n *\n * @interface QueryResult\n */\nexport type QueryResult = {\n insertId?: number;\n rowsAffected: number;\n rows?: {\n /** Raw array with all dataset */\n _array: any[];\n /** The lengh of the dataset */\n length: number;\n /** A convenience function to acess the index based the row object\n * @param idx the row index\n * @returns the row structure identified by column names\n */\n item: (idx: number) => any;\n };\n /**\n * Query metadata, avaliable only for select query results\n */\n metadata?: ColumnMetadata[];\n};\n\n/**\n * Column metadata\n * Describes some information about columns fetched by the query\n */\nexport type ColumnMetadata = {\n /** The name used for this column for this resultset */\n name: string;\n /** The declared column type for this column, when fetched directly from a table or a View resulting from a table column. \"UNKNOWN\" for dynamic values, like function returned ones. */\n type: string;\n /**\n * The index for this column for this resultset*/\n index: number;\n};\n\n/**\n * Allows the execution of bulk of sql commands\n * inside a transaction\n * If a single query must be executed many times with different arguments, its preferred\n * to declare it a single time, and use an array of array parameters.\n */\nexport type SQLBatchTuple = [string] | [string, Array<any> | Array<Array<any>>];\n\nexport type UpdateHookOperation = 'INSERT' | 'DELETE' | 'UPDATE';\n\n/**\n * status: 0 or undefined for correct execution, 1 for error\n * message: if status === 1, here you will find error description\n * rowsAffected: Number of affected rows if status == 0\n */\nexport type BatchQueryResult = {\n rowsAffected?: number;\n};\n\n/**\n * Result of loading a file and executing every line as a SQL command\n * Similar to BatchQueryResult\n */\nexport interface FileLoadResult extends BatchQueryResult {\n commands?: number;\n}\n\nexport interface Transaction {\n commit: () => QueryResult;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ) => Promise<QueryResult>;\n rollback: () => QueryResult;\n}\n\nexport interface PendingTransaction {\n /*\n * The start function should not throw or return a promise because the\n * queue just calls it and does not monitor for failures or completions.\n *\n * It should catch any errors and call the resolve or reject of the wrapping\n * promise when complete.\n *\n * It should also automatically commit or rollback the transaction if needed\n */\n start: () => void;\n}\n\ninterface ISQLite {\n open: (dbName: string, location?: string) => void;\n close: (dbName: string) => void;\n delete: (dbName: string, location?: string) => void;\n attach: (\n mainDbName: string,\n dbNameToAttach: string,\n alias: string,\n location?: string\n ) => void;\n detach: (mainDbName: string, alias: string) => void;\n transaction: (\n dbName: string,\n fn: (tx: Transaction) => Promise<void>\n ) => Promise<void>;\n execute: (dbName: string, query: string, params?: any[]) => QueryResult;\n executeAsync: (\n dbName: string,\n query: string,\n params?: any[]\n ) => Promise<QueryResult>;\n executeBatch: (dbName: string, commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (\n dbName: string,\n commands: SQLBatchTuple[]\n ) => Promise<BatchQueryResult>;\n loadFile: (dbName: string, location: string) => Promise<FileLoadResult>;\n updateHook: (\n dbName: string,\n callback?:\n | ((params: {\n table: string;\n operation: UpdateHookOperation;\n row?: any;\n rowId: number;\n }) => void)\n | null\n ) => void;\n commitHook: (dbName: string, callback?: (() => void) | null) => void;\n rollbackHook: (dbName: string, callback?: (() => void) | null) => void;\n}\n\nconst locks: Record<\n string,\n { queue: PendingTransaction[]; inProgress: boolean }\n> = {};\n\n// Enhance some host functions\n\n// Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\nfunction enhanceQueryResult(result: QueryResult): void {\n // Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\n if (result.rows == null) {\n result.rows = {\n _array: [],\n length: 0,\n item: (idx: number) => result.rows?._array[idx],\n };\n } else {\n result.rows.item = (idx: number) => result.rows?._array[idx];\n }\n}\n\nconst _open = OPSQLite.open;\nOPSQLite.open = (dbName: string, location?: string) => {\n _open(dbName, location);\n\n locks[dbName] = {\n queue: [],\n inProgress: false,\n };\n};\n\nconst _close = OPSQLite.close;\nOPSQLite.close = (dbName: string) => {\n _close(dbName);\n delete locks[dbName];\n};\n\nconst _execute = OPSQLite.execute;\nOPSQLite.execute = (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): QueryResult => {\n const sanitizedParams = params?.map((p) => {\n if (ArrayBuffer.isView(p)) {\n return p.buffer;\n }\n\n return p;\n });\n\n const result = _execute(dbName, query, sanitizedParams);\n enhanceQueryResult(result);\n return result;\n};\n\nconst _executeAsync = OPSQLite.executeAsync;\nOPSQLite.executeAsync = async (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): Promise<QueryResult> => {\n const sanitizedParams = params?.map((p) => {\n if (ArrayBuffer.isView(p)) {\n return p.buffer;\n }\n\n return p;\n });\n\n const res = await _executeAsync(dbName, query, sanitizedParams);\n enhanceQueryResult(res);\n return res;\n};\n\nOPSQLite.transaction = async (\n dbName: string,\n fn: (tx: Transaction) => Promise<void>\n): Promise<void> => {\n if (!locks[dbName]) {\n throw Error(`SQLite Error: No lock found on db: ${dbName}`);\n }\n\n let isFinalized = false;\n\n // Local transaction context object implementation\n const execute = (query: string, params?: any[]): QueryResult => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.execute(dbName, query, params);\n };\n\n const executeAsync = (query: string, params?: any[] | undefined) => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.executeAsync(dbName, query, params);\n };\n\n const commit = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute commit on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'COMMIT');\n isFinalized = true;\n return result;\n };\n\n const rollback = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute rollback on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'ROLLBACK');\n isFinalized = true;\n return result;\n };\n\n async function run() {\n try {\n await OPSQLite.executeAsync(dbName, 'BEGIN TRANSACTION');\n\n await fn({\n commit,\n execute,\n executeAsync,\n rollback,\n });\n\n if (!isFinalized) {\n commit();\n }\n } catch (executionError) {\n if (!isFinalized) {\n try {\n rollback();\n } catch (rollbackError) {\n throw rollbackError;\n }\n }\n\n throw executionError;\n } finally {\n locks[dbName].inProgress = false;\n isFinalized = false;\n startNextTransaction(dbName);\n }\n }\n\n return await new Promise((resolve, reject) => {\n const tx: PendingTransaction = {\n start: () => {\n run().then(resolve).catch(reject);\n },\n };\n\n locks[dbName].queue.push(tx);\n startNextTransaction(dbName);\n });\n};\n\nconst startNextTransaction = (dbName: string) => {\n if (!locks[dbName]) {\n throw Error(`Lock not found for db: ${dbName}`);\n }\n\n if (locks[dbName].inProgress) {\n // Transaction is already in process bail out\n return;\n }\n\n if (locks[dbName].queue.length) {\n locks[dbName].inProgress = true;\n const tx = locks[dbName].queue.shift();\n\n if (!tx) {\n throw new Error('Could not get a operation on datebase');\n }\n\n setImmediate(() => {\n tx.start();\n });\n }\n};\n\nexport type OPSQLiteConnection = {\n close: () => void;\n delete: () => void;\n attach: (dbNameToAttach: string, alias: string, location?: string) => void;\n detach: (alias: string) => void;\n transaction: (fn: (tx: Transaction) => Promise<void>) => Promise<void>;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (query: string, params?: any[]) => Promise<QueryResult>;\n executeBatch: (commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;\n loadFile: (location: string) => Promise<FileLoadResult>;\n updateHook: (\n callback:\n | ((params: {\n table: string;\n operation: UpdateHookOperation;\n row?: any;\n rowId: number;\n }) => void)\n | null\n ) => void;\n commitHook: (callback: (() => void) | null) => void;\n rollbackHook: (callback: (() => void) | null) => void;\n};\n\nexport const open = (options: {\n name: string;\n location?: string;\n}): OPSQLiteConnection => {\n OPSQLite.open(options.name, options.location);\n\n return {\n close: () => OPSQLite.close(options.name),\n delete: () => OPSQLite.delete(options.name, options.location),\n attach: (dbNameToAttach: string, alias: string, location?: string) =>\n OPSQLite.attach(options.name, dbNameToAttach, alias, location),\n detach: (alias: string) => OPSQLite.detach(options.name, alias),\n transaction: (fn: (tx: Transaction) => Promise<void>) =>\n OPSQLite.transaction(options.name, fn),\n execute: (query: string, params?: any[] | undefined): QueryResult =>\n OPSQLite.execute(options.name, query, params),\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ): Promise<QueryResult> =>\n OPSQLite.executeAsync(options.name, query, params),\n executeBatch: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatch(options.name, commands),\n executeBatchAsync: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatchAsync(options.name, commands),\n loadFile: (location: string) => OPSQLite.loadFile(options.name, location),\n updateHook: (callback) => OPSQLite.updateHook(options.name, callback),\n commitHook: (callback) => OPSQLite.commitHook(options.name, callback),\n rollbackHook: (callback) => OPSQLite.rollbackHook(options.name, callback),\n };\n};\n"],"mappings":";;;;;;AAAA;AAOA,IAAIA,MAAM,CAACC,eAAe,IAAI,IAAI,EAAE;EAClC,MAAMC,cAAc,GAAGC,0BAAa,CAACC,QA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ACmB,OAAO,CAACC,IAAI,EAAEnB,EAAE,CAAC;IACxCb,OAAO,EAAE,CAACC,KAAa,EAAEC,MAA0B,KACjD7B,QAAQ,CAAC2B,OAAO,CAAC+B,OAAO,CAACC,IAAI,EAAE/B,KAAK,EAAEC,MAAM,CAAC;IAC/CQ,YAAY,EAAE,CACZT,KAAa,EACbC,MAA0B,KAE1B7B,QAAQ,CAACqC,YAAY,CAACqB,OAAO,CAACC,IAAI,EAAE/B,KAAK,EAAEC,MAAM,CAAC;IACpDoC,YAAY,EAAGC,QAAyB,IACtClE,QAAQ,CAACiE,YAAY,CAACP,OAAO,CAACC,IAAI,EAAEO,QAAQ,CAAC;IAC/CC,iBAAiB,EAAGD,QAAyB,IAC3ClE,QAAQ,CAACmE,iBAAiB,CAACT,OAAO,CAACC,IAAI,EAAEO,QAAQ,CAAC;IACpDE,QAAQ,EAAG/C,QAAgB,IAAKrB,QAAQ,CAACoE,QAAQ,CAACV,OAAO,CAACC,IAAI,EAAEtC,QAAQ,CAAC;IACzEgD,UAAU,EAAGC,QAAQ,IAAKtE,QAAQ,CAACqE,UAAU,CAACX,OAAO,CAACC,IAAI,EAAEW,QAAQ,CAAC;IACrEC,UAAU,EAAGD,QAAQ,IAAKtE,QAAQ,CAACuE,UAAU,CAACb,OAAO,CAACC,IAAI,EAAEW,QAAQ,CAAC;IACrEE,YAAY,EAAGF,QAAQ,IAAKtE,QAAQ,CAACwE,YAAY,CAACd,OAAO,CAACC,IAAI,EAAEW,QAAQ;EAC1E,CAAC;AACH,CAAC;AAAC"}
@@ -23,6 +23,13 @@ if (global.__OPSQLiteProxy == null) {
23
23
  }
24
24
  const proxy = global.__OPSQLiteProxy;
25
25
  export const OPSQLite = proxy;
26
+ export const {
27
+ IOS_DOCUMENT_PATH,
28
+ IOS_LIBRARY_PATH,
29
+ ANDROID_DATABASE_PATH,
30
+ ANDROID_FILES_PATH,
31
+ ANDROID_EXTERNAL_FILES_PATH
32
+ } = NativeModules.OPSQLite;
26
33
 
27
34
  /**
28
35
  * Object returned by SQL Query executions {
@@ -59,8 +66,8 @@ function enhanceQueryResult(result) {
59
66
  }
60
67
  }
61
68
  const _open = OPSQLite.open;
62
- OPSQLite.open = (dbName, location, inMemory) => {
63
- _open(dbName, location, !!inMemory);
69
+ OPSQLite.open = (dbName, location) => {
70
+ _open(dbName, location);
64
71
  locks[dbName] = {
65
72
  queue: [],
66
73
  inProgress: false
@@ -187,7 +194,7 @@ const startNextTransaction = dbName => {
187
194
  }
188
195
  };
189
196
  export const open = options => {
190
- OPSQLite.open(options.name, options.location, options.inMemory);
197
+ OPSQLite.open(options.name, options.location);
191
198
  return {
192
199
  close: () => OPSQLite.close(options.name),
193
200
  delete: () => OPSQLite.delete(options.name, options.location),
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","global","__OPSQLiteProxy","OPSQLiteModule","OPSQLite","Error","nativeCallSyncHook","install","result","proxy","locks","enhanceQueryResult","rows","_array","length","item","idx","_open","open","dbName","location","inMemory","queue","inProgress","_close","close","_execute","execute","query","params","sanitizedParams","map","p","ArrayBuffer","isView","buffer","_executeAsync","executeAsync","res","transaction","fn","isFinalized","commit","rollback","run","executionError","rollbackError","startNextTransaction","Promise","resolve","reject","tx","start","then","catch","push","shift","setImmediate","options","name","delete","attach","dbNameToAttach","alias","detach","executeBatch","commands","executeBatchAsync","loadFile","updateHook","callback","commitHook","rollbackHook"],"sources":["index.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\ndeclare global {\n function nativeCallSyncHook(): unknown;\n var __OPSQLiteProxy: object | undefined;\n}\n\nif (global.__OPSQLiteProxy == null) {\n const OPSQLiteModule = NativeModules.OPSQLite;\n\n if (OPSQLiteModule == null) {\n throw new Error('Base module not found. Maybe try rebuilding the app.');\n }\n\n // Check if we are running on-device (JSI)\n if (global.nativeCallSyncHook == null || OPSQLiteModule.install == null) {\n throw new Error(\n 'Failed to install op-sqlite: React Native is not running on-device. OPSQLite can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.'\n );\n }\n\n // Call the synchronous blocking install() function\n const result = OPSQLiteModule.install();\n if (result !== true) {\n throw new Error(\n `Failed to install op-sqlite: The native OPSQLite Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`\n );\n }\n\n // Check again if the constructor now exists. If not, throw an error.\n if (global.__OPSQLiteProxy == null) {\n throw new Error(\n 'Failed to install op-sqlite, the native initializer function does not exist. Are you trying to use OPSQLite from different JS Runtimes?'\n );\n }\n}\n\nconst proxy = global.__OPSQLiteProxy;\nexport const OPSQLite = proxy as ISQLite;\n\n/**\n * Object returned by SQL Query executions {\n * insertId: Represent the auto-generated row id if applicable\n * rowsAffected: Number of affected rows if result of a update query\n * message: if status === 1, here you will find error description\n * rows: if status is undefined or 0 this object will contain the query results\n * }\n *\n * @interface QueryResult\n */\nexport type QueryResult = {\n insertId?: number;\n rowsAffected: number;\n rows?: {\n /** Raw array with all dataset */\n _array: any[];\n /** The lengh of the dataset */\n length: number;\n /** A convenience function to acess the index based the row object\n * @param idx the row index\n * @returns the row structure identified by column names\n */\n item: (idx: number) => any;\n };\n /**\n * Query metadata, avaliable only for select query results\n */\n metadata?: ColumnMetadata[];\n};\n\n/**\n * Column metadata\n * Describes some information about columns fetched by the query\n */\nexport type ColumnMetadata = {\n /** The name used for this column for this resultset */\n name: string;\n /** The declared column type for this column, when fetched directly from a table or a View resulting from a table column. \"UNKNOWN\" for dynamic values, like function returned ones. */\n type: string;\n /**\n * The index for this column for this resultset*/\n index: number;\n};\n\n/**\n * Allows the execution of bulk of sql commands\n * inside a transaction\n * If a single query must be executed many times with different arguments, its preferred\n * to declare it a single time, and use an array of array parameters.\n */\nexport type SQLBatchTuple = [string] | [string, Array<any> | Array<Array<any>>];\n\nexport type UpdateHookOperation = 'INSERT' | 'DELETE' | 'UPDATE';\n\n/**\n * status: 0 or undefined for correct execution, 1 for error\n * message: if status === 1, here you will find error description\n * rowsAffected: Number of affected rows if status == 0\n */\nexport type BatchQueryResult = {\n rowsAffected?: number;\n};\n\n/**\n * Result of loading a file and executing every line as a SQL command\n * Similar to BatchQueryResult\n */\nexport interface FileLoadResult extends BatchQueryResult {\n commands?: number;\n}\n\nexport interface Transaction {\n commit: () => QueryResult;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ) => Promise<QueryResult>;\n rollback: () => QueryResult;\n}\n\nexport interface PendingTransaction {\n /*\n * The start function should not throw or return a promise because the\n * queue just calls it and does not monitor for failures or completions.\n *\n * It should catch any errors and call the resolve or reject of the wrapping\n * promise when complete.\n *\n * It should also automatically commit or rollback the transaction if needed\n */\n start: () => void;\n}\n\ninterface ISQLite {\n open: (dbName: string, location?: string, inMemory?: boolean) => void;\n close: (dbName: string) => void;\n delete: (dbName: string, location?: string) => void;\n attach: (\n mainDbName: string,\n dbNameToAttach: string,\n alias: string,\n location?: string\n ) => void;\n detach: (mainDbName: string, alias: string) => void;\n transaction: (\n dbName: string,\n fn: (tx: Transaction) => Promise<void>\n ) => Promise<void>;\n execute: (dbName: string, query: string, params?: any[]) => QueryResult;\n executeAsync: (\n dbName: string,\n query: string,\n params?: any[]\n ) => Promise<QueryResult>;\n executeBatch: (dbName: string, commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (\n dbName: string,\n commands: SQLBatchTuple[]\n ) => Promise<BatchQueryResult>;\n loadFile: (dbName: string, location: string) => Promise<FileLoadResult>;\n updateHook: (\n dbName: string,\n callback?: ((params: {\n table: string;\n operation: UpdateHookOperation;\n row?: any;\n rowId: number;\n }) => void) | null\n ) => void;\n commitHook: (dbName: string, callback?: (() => void) | null) => void;\n rollbackHook: (dbName: string, callback?: (() => void) | null) => void;\n}\n\nconst locks: Record<\n string,\n { queue: PendingTransaction[]; inProgress: boolean }\n> = {};\n\n// Enhance some host functions\n\n// Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\nfunction enhanceQueryResult(result: QueryResult): void {\n // Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\n if (result.rows == null) {\n result.rows = {\n _array: [],\n length: 0,\n item: (idx: number) => result.rows?._array[idx],\n };\n } else {\n result.rows.item = (idx: number) => result.rows?._array[idx];\n }\n}\n\nconst _open = OPSQLite.open;\nOPSQLite.open = (dbName: string, location?: string, inMemory?: boolean) => {\n _open(dbName, location, !!inMemory);\n\n locks[dbName] = {\n queue: [],\n inProgress: false,\n };\n};\n\nconst _close = OPSQLite.close;\nOPSQLite.close = (dbName: string) => {\n _close(dbName);\n delete locks[dbName];\n};\n\nconst _execute = OPSQLite.execute;\nOPSQLite.execute = (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): QueryResult => {\n const sanitizedParams = params?.map((p) => {\n if (ArrayBuffer.isView(p)) {\n return p.buffer;\n }\n\n return p;\n });\n\n const result = _execute(dbName, query, sanitizedParams);\n enhanceQueryResult(result);\n return result;\n};\n\nconst _executeAsync = OPSQLite.executeAsync;\nOPSQLite.executeAsync = async (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): Promise<QueryResult> => {\n const sanitizedParams = params?.map((p) => {\n if (ArrayBuffer.isView(p)) {\n return p.buffer;\n }\n\n return p;\n });\n\n const res = await _executeAsync(dbName, query, sanitizedParams);\n enhanceQueryResult(res);\n return res;\n};\n\nOPSQLite.transaction = async (\n dbName: string,\n fn: (tx: Transaction) => Promise<void>\n): Promise<void> => {\n if (!locks[dbName]) {\n throw Error(`SQLite Error: No lock found on db: ${dbName}`);\n }\n\n let isFinalized = false;\n\n // Local transaction context object implementation\n const execute = (query: string, params?: any[]): QueryResult => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.execute(dbName, query, params);\n };\n\n const executeAsync = (query: string, params?: any[] | undefined) => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.executeAsync(dbName, query, params);\n };\n\n const commit = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute commit on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'COMMIT');\n isFinalized = true;\n return result;\n };\n\n const rollback = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute rollback on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'ROLLBACK');\n isFinalized = true;\n return result;\n };\n\n async function run() {\n try {\n await OPSQLite.executeAsync(dbName, 'BEGIN TRANSACTION');\n\n await fn({\n commit,\n execute,\n executeAsync,\n rollback,\n });\n\n if (!isFinalized) {\n commit();\n }\n } catch (executionError) {\n if (!isFinalized) {\n try {\n rollback();\n } catch (rollbackError) {\n throw rollbackError;\n }\n }\n\n throw executionError;\n } finally {\n locks[dbName].inProgress = false;\n isFinalized = false;\n startNextTransaction(dbName);\n }\n }\n\n return await new Promise((resolve, reject) => {\n const tx: PendingTransaction = {\n start: () => {\n run().then(resolve).catch(reject);\n },\n };\n\n locks[dbName].queue.push(tx);\n startNextTransaction(dbName);\n });\n};\n\nconst startNextTransaction = (dbName: string) => {\n if (!locks[dbName]) {\n throw Error(`Lock not found for db: ${dbName}`);\n }\n\n if (locks[dbName].inProgress) {\n // Transaction is already in process bail out\n return;\n }\n\n if (locks[dbName].queue.length) {\n locks[dbName].inProgress = true;\n const tx = locks[dbName].queue.shift();\n\n if (!tx) {\n throw new Error('Could not get a operation on datebase');\n }\n\n setImmediate(() => {\n tx.start();\n });\n }\n};\n\nexport type OPSQLiteConnection = {\n close: () => void;\n delete: () => void;\n attach: (dbNameToAttach: string, alias: string, location?: string) => void;\n detach: (alias: string) => void;\n transaction: (fn: (tx: Transaction) => Promise<void>) => Promise<void>;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (query: string, params?: any[]) => Promise<QueryResult>;\n executeBatch: (commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;\n loadFile: (location: string) => Promise<FileLoadResult>;\n updateHook: (\n callback: ((params: {\n table: string;\n operation: UpdateHookOperation;\n row?: any;\n rowId: number;\n }) => void) | null\n ) => void;\n commitHook: (callback: (() => void) | null) => void;\n rollbackHook: (callback: (() => void) | null) => void;\n};\n\nexport const open = (options: {\n name: string;\n location?: string;\n inMemory?: boolean;\n}): OPSQLiteConnection => {\n OPSQLite.open(options.name, options.location, options.inMemory);\n\n return {\n close: () => OPSQLite.close(options.name),\n delete: () => OPSQLite.delete(options.name, options.location),\n attach: (dbNameToAttach: string, alias: string, location?: string) =>\n OPSQLite.attach(options.name, dbNameToAttach, alias, location),\n detach: (alias: string) => OPSQLite.detach(options.name, alias),\n transaction: (fn: (tx: Transaction) => Promise<void>) =>\n OPSQLite.transaction(options.name, fn),\n execute: (query: string, params?: any[] | undefined): QueryResult =>\n OPSQLite.execute(options.name, query, params),\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ): Promise<QueryResult> =>\n OPSQLite.executeAsync(options.name, query, params),\n executeBatch: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatch(options.name, commands),\n executeBatchAsync: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatchAsync(options.name, commands),\n loadFile: (location: string) => OPSQLite.loadFile(options.name, location),\n updateHook: (callback) => OPSQLite.updateHook(options.name, callback),\n commitHook: (callback) => OPSQLite.commitHook(options.name, callback),\n rollbackHook: (callback) => OPSQLite.rollbackHook(options.name, callback),\n };\n};\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAO5C,IAAIC,MAAM,CAACC,eAAe,IAAI,IAAI,EAAE;EAClC,MAAMC,cAAc,GAAGH,aAAa,CAACI,QAAQ;EAE7C,IAAID,cAAc,IAAI,IAAI,EAAE;IAC1B,MAAM,IAAIE,KAAK,CAAC,sDAAsD,CAAC;EACzE;;EAEA;EACA,IAAIJ,MAAM,CAACK,kBAAkB,IAAI,IAAI,IAAIH,cAAc,CAACI,OAAO,IAAI,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AAK,EAAEC,MAAM,CAAC;IACpDoC,YAAY,EAAGC,QAAyB,IACtC9D,QAAQ,CAAC6D,YAAY,CAACP,OAAO,CAACC,IAAI,EAAEO,QAAQ,CAAC;IAC/CC,iBAAiB,EAAGD,QAAyB,IAC3C9D,QAAQ,CAAC+D,iBAAiB,CAACT,OAAO,CAACC,IAAI,EAAEO,QAAQ,CAAC;IACpDE,QAAQ,EAAGhD,QAAgB,IAAKhB,QAAQ,CAACgE,QAAQ,CAACV,OAAO,CAACC,IAAI,EAAEvC,QAAQ,CAAC;IACzEiD,UAAU,EAAGC,QAAQ,IAAKlE,QAAQ,CAACiE,UAAU,CAACX,OAAO,CAACC,IAAI,EAAEW,QAAQ,CAAC;IACrEC,UAAU,EAAGD,QAAQ,IAAKlE,QAAQ,CAACmE,UAAU,CAACb,OAAO,CAACC,IAAI,EAAEW,QAAQ,CAAC;IACrEE,YAAY,EAAGF,QAAQ,IAAKlE,QAAQ,CAACoE,YAAY,CAACd,OAAO,CAACC,IAAI,EAAEW,QAAQ;EAC1E,CAAC;AACH,CAAC"}
1
+ {"version":3,"names":["NativeModules","global","__OPSQLiteProxy","OPSQLiteModule","OPSQLite","Error","nativeCallSyncHook","install","result","proxy","IOS_DOCUMENT_PATH","IOS_LIBRARY_PATH","ANDROID_DATABASE_PATH","ANDROID_FILES_PATH","ANDROID_EXTERNAL_FILES_PATH","locks","enhanceQueryResult","rows","_array","length","item","idx","_open","open","dbName","location","queue","inProgress","_close","close","_execute","execute","query","params","sanitizedParams","map","p","ArrayBuffer","isView","buffer","_executeAsync","executeAsync","res","transaction","fn","isFinalized","commit","rollback","run","executionError","rollbackError","startNextTransaction","Promise","resolve","reject","tx","start","then","catch","push","shift","setImmediate","options","name","delete","attach","dbNameToAttach","alias","detach","executeBatch","commands","executeBatchAsync","loadFile","updateHook","callback","commitHook","rollbackHook"],"sources":["index.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\ndeclare global {\n function nativeCallSyncHook(): unknown;\n var __OPSQLiteProxy: object | undefined;\n}\n\nif (global.__OPSQLiteProxy == null) {\n const OPSQLiteModule = NativeModules.OPSQLite;\n\n if (OPSQLiteModule == null) {\n throw new Error('Base module not found. Maybe try rebuilding the app.');\n }\n\n // Check if we are running on-device (JSI)\n if (global.nativeCallSyncHook == null || OPSQLiteModule.install == null) {\n throw new Error(\n 'Failed to install op-sqlite: React Native is not running on-device. OPSQLite can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.'\n );\n }\n\n // Call the synchronous blocking install() function\n const result = OPSQLiteModule.install();\n if (result !== true) {\n throw new Error(\n `Failed to install op-sqlite: The native OPSQLite Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`\n );\n }\n\n // Check again if the constructor now exists. If not, throw an error.\n if (global.__OPSQLiteProxy == null) {\n throw new Error(\n 'Failed to install op-sqlite, the native initializer function does not exist. Are you trying to use OPSQLite from different JS Runtimes?'\n );\n }\n}\n\nconst proxy = global.__OPSQLiteProxy;\nexport const OPSQLite = proxy as ISQLite;\n\nexport const {\n IOS_DOCUMENT_PATH,\n IOS_LIBRARY_PATH,\n ANDROID_DATABASE_PATH,\n ANDROID_FILES_PATH,\n ANDROID_EXTERNAL_FILES_PATH,\n} = NativeModules.OPSQLite;\n\n/**\n * Object returned by SQL Query executions {\n * insertId: Represent the auto-generated row id if applicable\n * rowsAffected: Number of affected rows if result of a update query\n * message: if status === 1, here you will find error description\n * rows: if status is undefined or 0 this object will contain the query results\n * }\n *\n * @interface QueryResult\n */\nexport type QueryResult = {\n insertId?: number;\n rowsAffected: number;\n rows?: {\n /** Raw array with all dataset */\n _array: any[];\n /** The lengh of the dataset */\n length: number;\n /** A convenience function to acess the index based the row object\n * @param idx the row index\n * @returns the row structure identified by column names\n */\n item: (idx: number) => any;\n };\n /**\n * Query metadata, avaliable only for select query results\n */\n metadata?: ColumnMetadata[];\n};\n\n/**\n * Column metadata\n * Describes some information about columns fetched by the query\n */\nexport type ColumnMetadata = {\n /** The name used for this column for this resultset */\n name: string;\n /** The declared column type for this column, when fetched directly from a table or a View resulting from a table column. \"UNKNOWN\" for dynamic values, like function returned ones. */\n type: string;\n /**\n * The index for this column for this resultset*/\n index: number;\n};\n\n/**\n * Allows the execution of bulk of sql commands\n * inside a transaction\n * If a single query must be executed many times with different arguments, its preferred\n * to declare it a single time, and use an array of array parameters.\n */\nexport type SQLBatchTuple = [string] | [string, Array<any> | Array<Array<any>>];\n\nexport type UpdateHookOperation = 'INSERT' | 'DELETE' | 'UPDATE';\n\n/**\n * status: 0 or undefined for correct execution, 1 for error\n * message: if status === 1, here you will find error description\n * rowsAffected: Number of affected rows if status == 0\n */\nexport type BatchQueryResult = {\n rowsAffected?: number;\n};\n\n/**\n * Result of loading a file and executing every line as a SQL command\n * Similar to BatchQueryResult\n */\nexport interface FileLoadResult extends BatchQueryResult {\n commands?: number;\n}\n\nexport interface Transaction {\n commit: () => QueryResult;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ) => Promise<QueryResult>;\n rollback: () => QueryResult;\n}\n\nexport interface PendingTransaction {\n /*\n * The start function should not throw or return a promise because the\n * queue just calls it and does not monitor for failures or completions.\n *\n * It should catch any errors and call the resolve or reject of the wrapping\n * promise when complete.\n *\n * It should also automatically commit or rollback the transaction if needed\n */\n start: () => void;\n}\n\ninterface ISQLite {\n open: (dbName: string, location?: string) => void;\n close: (dbName: string) => void;\n delete: (dbName: string, location?: string) => void;\n attach: (\n mainDbName: string,\n dbNameToAttach: string,\n alias: string,\n location?: string\n ) => void;\n detach: (mainDbName: string, alias: string) => void;\n transaction: (\n dbName: string,\n fn: (tx: Transaction) => Promise<void>\n ) => Promise<void>;\n execute: (dbName: string, query: string, params?: any[]) => QueryResult;\n executeAsync: (\n dbName: string,\n query: string,\n params?: any[]\n ) => Promise<QueryResult>;\n executeBatch: (dbName: string, commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (\n dbName: string,\n commands: SQLBatchTuple[]\n ) => Promise<BatchQueryResult>;\n loadFile: (dbName: string, location: string) => Promise<FileLoadResult>;\n updateHook: (\n dbName: string,\n callback?:\n | ((params: {\n table: string;\n operation: UpdateHookOperation;\n row?: any;\n rowId: number;\n }) => void)\n | null\n ) => void;\n commitHook: (dbName: string, callback?: (() => void) | null) => void;\n rollbackHook: (dbName: string, callback?: (() => void) | null) => void;\n}\n\nconst locks: Record<\n string,\n { queue: PendingTransaction[]; inProgress: boolean }\n> = {};\n\n// Enhance some host functions\n\n// Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\nfunction enhanceQueryResult(result: QueryResult): void {\n // Add 'item' function to result object to allow the sqlite-storage typeorm driver to work\n if (result.rows == null) {\n result.rows = {\n _array: [],\n length: 0,\n item: (idx: number) => result.rows?._array[idx],\n };\n } else {\n result.rows.item = (idx: number) => result.rows?._array[idx];\n }\n}\n\nconst _open = OPSQLite.open;\nOPSQLite.open = (dbName: string, location?: string) => {\n _open(dbName, location);\n\n locks[dbName] = {\n queue: [],\n inProgress: false,\n };\n};\n\nconst _close = OPSQLite.close;\nOPSQLite.close = (dbName: string) => {\n _close(dbName);\n delete locks[dbName];\n};\n\nconst _execute = OPSQLite.execute;\nOPSQLite.execute = (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): QueryResult => {\n const sanitizedParams = params?.map((p) => {\n if (ArrayBuffer.isView(p)) {\n return p.buffer;\n }\n\n return p;\n });\n\n const result = _execute(dbName, query, sanitizedParams);\n enhanceQueryResult(result);\n return result;\n};\n\nconst _executeAsync = OPSQLite.executeAsync;\nOPSQLite.executeAsync = async (\n dbName: string,\n query: string,\n params?: any[] | undefined\n): Promise<QueryResult> => {\n const sanitizedParams = params?.map((p) => {\n if (ArrayBuffer.isView(p)) {\n return p.buffer;\n }\n\n return p;\n });\n\n const res = await _executeAsync(dbName, query, sanitizedParams);\n enhanceQueryResult(res);\n return res;\n};\n\nOPSQLite.transaction = async (\n dbName: string,\n fn: (tx: Transaction) => Promise<void>\n): Promise<void> => {\n if (!locks[dbName]) {\n throw Error(`SQLite Error: No lock found on db: ${dbName}`);\n }\n\n let isFinalized = false;\n\n // Local transaction context object implementation\n const execute = (query: string, params?: any[]): QueryResult => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.execute(dbName, query, params);\n };\n\n const executeAsync = (query: string, params?: any[] | undefined) => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute query on finalized transaction: ${dbName}`\n );\n }\n return OPSQLite.executeAsync(dbName, query, params);\n };\n\n const commit = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute commit on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'COMMIT');\n isFinalized = true;\n return result;\n };\n\n const rollback = () => {\n if (isFinalized) {\n throw Error(\n `SQLite Error: Cannot execute rollback on finalized transaction: ${dbName}`\n );\n }\n const result = OPSQLite.execute(dbName, 'ROLLBACK');\n isFinalized = true;\n return result;\n };\n\n async function run() {\n try {\n await OPSQLite.executeAsync(dbName, 'BEGIN TRANSACTION');\n\n await fn({\n commit,\n execute,\n executeAsync,\n rollback,\n });\n\n if (!isFinalized) {\n commit();\n }\n } catch (executionError) {\n if (!isFinalized) {\n try {\n rollback();\n } catch (rollbackError) {\n throw rollbackError;\n }\n }\n\n throw executionError;\n } finally {\n locks[dbName].inProgress = false;\n isFinalized = false;\n startNextTransaction(dbName);\n }\n }\n\n return await new Promise((resolve, reject) => {\n const tx: PendingTransaction = {\n start: () => {\n run().then(resolve).catch(reject);\n },\n };\n\n locks[dbName].queue.push(tx);\n startNextTransaction(dbName);\n });\n};\n\nconst startNextTransaction = (dbName: string) => {\n if (!locks[dbName]) {\n throw Error(`Lock not found for db: ${dbName}`);\n }\n\n if (locks[dbName].inProgress) {\n // Transaction is already in process bail out\n return;\n }\n\n if (locks[dbName].queue.length) {\n locks[dbName].inProgress = true;\n const tx = locks[dbName].queue.shift();\n\n if (!tx) {\n throw new Error('Could not get a operation on datebase');\n }\n\n setImmediate(() => {\n tx.start();\n });\n }\n};\n\nexport type OPSQLiteConnection = {\n close: () => void;\n delete: () => void;\n attach: (dbNameToAttach: string, alias: string, location?: string) => void;\n detach: (alias: string) => void;\n transaction: (fn: (tx: Transaction) => Promise<void>) => Promise<void>;\n execute: (query: string, params?: any[]) => QueryResult;\n executeAsync: (query: string, params?: any[]) => Promise<QueryResult>;\n executeBatch: (commands: SQLBatchTuple[]) => BatchQueryResult;\n executeBatchAsync: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;\n loadFile: (location: string) => Promise<FileLoadResult>;\n updateHook: (\n callback:\n | ((params: {\n table: string;\n operation: UpdateHookOperation;\n row?: any;\n rowId: number;\n }) => void)\n | null\n ) => void;\n commitHook: (callback: (() => void) | null) => void;\n rollbackHook: (callback: (() => void) | null) => void;\n};\n\nexport const open = (options: {\n name: string;\n location?: string;\n}): OPSQLiteConnection => {\n OPSQLite.open(options.name, options.location);\n\n return {\n close: () => OPSQLite.close(options.name),\n delete: () => OPSQLite.delete(options.name, options.location),\n attach: (dbNameToAttach: string, alias: string, location?: string) =>\n OPSQLite.attach(options.name, dbNameToAttach, alias, location),\n detach: (alias: string) => OPSQLite.detach(options.name, alias),\n transaction: (fn: (tx: Transaction) => Promise<void>) =>\n OPSQLite.transaction(options.name, fn),\n execute: (query: string, params?: any[] | undefined): QueryResult =>\n OPSQLite.execute(options.name, query, params),\n executeAsync: (\n query: string,\n params?: any[] | undefined\n ): Promise<QueryResult> =>\n OPSQLite.executeAsync(options.name, query, params),\n executeBatch: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatch(options.name, commands),\n executeBatchAsync: (commands: SQLBatchTuple[]) =>\n OPSQLite.executeBatchAsync(options.name, commands),\n loadFile: (location: string) => OPSQLite.loadFile(options.name, location),\n updateHook: (callback) => OPSQLite.updateHook(options.name, callback),\n commitHook: (callback) => OPSQLite.commitHook(options.name, callback),\n rollbackHook: (callback) => OPSQLite.rollbackHook(options.name, callback),\n };\n};\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAO5C,IAAIC,MAAM,CAACC,eAAe,IAAI,IAAI,EAAE;EAClC,MAAMC,cAAc,GAAGH,aAAa,CAACI,QAAQ;EAE7C,IAAID,cAAc,IAAI,IAAI,EAAE;IAC1B,MAAM,IAAIE,KAAK,CAAC,sDAAsD,CAAC;EACzE;;EAEA;EACA,IAAIJ,MAAM,CAACK,kBAAkB,IAAI,IAAI,IAAIH,cAAc,CAACI,OAAO,IAAI,IAAI,EAAE;IACvE,MAAM,IAAIF,KAAK,CACb,iQAAiQ,CAClQ;EACH;;EAEA;EACA,MAAMG,MAAM,GAAGL,cAAc,CAACI,OAAO,EAAE;EACvC,IAAIC,MAAM,KAAK,IAAI,EAAE;IACnB,MAAM,IAAIH,KAAK,CACZ,iJAAgJG,MAAO,EAAC,CAC1J;EACH;;EAEA;EACA,IAAIP,MAAM,CAACC,eAAe,IAAI,IAAI,EAAE;IAClC,MAAM,IAAIG,KAAK,CACb,yIAAyI,CAC1I;EACH;AACF;AAEA,MAAMI,KAAK,GAAGR,MAAM,CAACC,eAAe;AACpC,OAAO,MAAME,QAAQ,GAAGK,KAAgB;AAExC,OAAO,MAAM;EACXC,iBAAiB;EACjBC,gBAAgB;EAChBC,qBAAqB;EACrBC,kBAAkB;EAClBC;AACF,CAAC,GAAGd,aAAa,CAACI,QAAQ;;AAE1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA+HA,MAAMW,KAGL,GAAG,CAAC,CAAC;;AAEN;;AAEA;AACA,SAASC,kBAAkB,CAACR,MAAmB,EAAQ;EACrD;EACA,IAAIA,MAAM,CAACS,IAAI,IAAI,IAAI,EAAE;IACvBT,MAAM,CAACS,IAAI,GAAG;MACZC,MAAM,EAAE,EAAE;MACVC,MAAM,EAAE,CAAC;MACTC,IAAI,EAAGC,GAAW;QA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6
+ export declare const IOS_DOCUMENT_PATH: any, IOS_LIBRARY_PATH: any, ANDROID_DATABASE_PATH: any, ANDROID_FILES_PATH: any, ANDROID_EXTERNAL_FILES_PATH: any;
6
7
  /**
7
8
  * Object returned by SQL Query executions {
8
9
  * insertId: Represent the auto-generated row id if applicable
@@ -78,7 +79,7 @@ export interface PendingTransaction {
78
79
  start: () => void;
79
80
  }
80
81
  interface ISQLite {
81
- open: (dbName: string, location?: string, inMemory?: boolean) => void;
82
+ open: (dbName: string, location?: string) => void;
82
83
  close: (dbName: string) => void;
83
84
  delete: (dbName: string, location?: string) => void;
84
85
  attach: (mainDbName: string, dbNameToAttach: string, alias: string, location?: string) => void;
@@ -121,6 +122,5 @@ export type OPSQLiteConnection = {
121
122
  export declare const open: (options: {
122
123
  name: string;
123
124
  location?: string;
124
- inMemory?: boolean;
125
125
  }) => OPSQLiteConnection;
126
126
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@op-engineering/op-sqlite",
3
- "version": "1.0.14",
3
+ "version": "2.0.1",
4
4
  "description": "Next generation SQLite for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
package/src/index.ts CHANGED
@@ -38,6 +38,14 @@ if (global.__OPSQLiteProxy == null) {
38
38
  const proxy = global.__OPSQLiteProxy;
39
39
  export const OPSQLite = proxy as ISQLite;
40
40
 
41
+ export const {
42
+ IOS_DOCUMENT_PATH,
43
+ IOS_LIBRARY_PATH,
44
+ ANDROID_DATABASE_PATH,
45
+ ANDROID_FILES_PATH,
46
+ ANDROID_EXTERNAL_FILES_PATH,
47
+ } = NativeModules.OPSQLite;
48
+
41
49
  /**
42
50
  * Object returned by SQL Query executions {
43
51
  * insertId: Represent the auto-generated row id if applicable
@@ -133,7 +141,7 @@ export interface PendingTransaction {
133
141
  }
134
142
 
135
143
  interface ISQLite {
136
- open: (dbName: string, location?: string, inMemory?: boolean) => void;
144
+ open: (dbName: string, location?: string) => void;
137
145
  close: (dbName: string) => void;
138
146
  delete: (dbName: string, location?: string) => void;
139
147
  attach: (
@@ -161,12 +169,14 @@ interface ISQLite {
161
169
  loadFile: (dbName: string, location: string) => Promise<FileLoadResult>;
162
170
  updateHook: (
163
171
  dbName: string,
164
- callback?: ((params: {
165
- table: string;
166
- operation: UpdateHookOperation;
167
- row?: any;
168
- rowId: number;
169
- }) => void) | null
172
+ callback?:
173
+ | ((params: {
174
+ table: string;
175
+ operation: UpdateHookOperation;
176
+ row?: any;
177
+ rowId: number;
178
+ }) => void)
179
+ | null
170
180
  ) => void;
171
181
  commitHook: (dbName: string, callback?: (() => void) | null) => void;
172
182
  rollbackHook: (dbName: string, callback?: (() => void) | null) => void;
@@ -194,8 +204,8 @@ function enhanceQueryResult(result: QueryResult): void {
194
204
  }
195
205
 
196
206
  const _open = OPSQLite.open;
197
- OPSQLite.open = (dbName: string, location?: string, inMemory?: boolean) => {
198
- _open(dbName, location, !!inMemory);
207
+ OPSQLite.open = (dbName: string, location?: string) => {
208
+ _open(dbName, location);
199
209
 
200
210
  locks[dbName] = {
201
211
  queue: [],
@@ -377,12 +387,14 @@ export type OPSQLiteConnection = {
377
387
  executeBatchAsync: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;
378
388
  loadFile: (location: string) => Promise<FileLoadResult>;
379
389
  updateHook: (
380
- callback: ((params: {
381
- table: string;
382
- operation: UpdateHookOperation;
383
- row?: any;
384
- rowId: number;
385
- }) => void) | null
390
+ callback:
391
+ | ((params: {
392
+ table: string;
393
+ operation: UpdateHookOperation;
394
+ row?: any;
395
+ rowId: number;
396
+ }) => void)
397
+ | null
386
398
  ) => void;
387
399
  commitHook: (callback: (() => void) | null) => void;
388
400
  rollbackHook: (callback: (() => void) | null) => void;
@@ -391,9 +403,8 @@ export type OPSQLiteConnection = {
391
403
  export const open = (options: {
392
404
  name: string;
393
405
  location?: string;
394
- inMemory?: boolean;
395
406
  }): OPSQLiteConnection => {
396
- OPSQLite.open(options.name, options.location, options.inMemory);
407
+ OPSQLite.open(options.name, options.location);
397
408
 
398
409
  return {
399
410
  close: () => OPSQLite.close(options.name),