@op-engineering/op-sqlite 1.0.13 → 2.0.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/README.md CHANGED
@@ -16,21 +16,25 @@ 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 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';
@@ -43,16 +47,36 @@ const largeDb = open({
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
 
46
- ## In memory
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_DOCUMENT_PATH,
57
+ IOS_LIBRARY_PATH,
58
+ ANDROID_DATABASE_PATH,
59
+ ANDROID_FILES_PATH,
60
+ ANDROID_EXTERNAL_FILES_PATH,
61
+ open,
62
+ } from '@op-engineering/op-sqlite';
63
+
64
+ const largeDb = open({
65
+ name: 'largeDB',
66
+ location: Platform.OS === 'ios' ? IOS_LIBRARY_PATH : ANDROID_DATABASE_PATH,
67
+ });
68
+ ```
69
+
70
+ ## In-memory
47
71
 
48
- Using SQLite in memory mode is supported:
72
+ Using SQLite in-memory mode is supported by passing a `':memory:'` as a location:
49
73
 
50
74
  ```ts
51
75
  import { open } from '@op-engineering/op-sqlite';
52
76
 
53
77
  const largeDb = open({
54
78
  name: 'inMemoryDb',
55
- inMemory: true,
79
+ location: ':memory:',
56
80
  });
57
81
  ```
58
82
 
@@ -69,15 +93,22 @@ db = {
69
93
  delete: () => void,
70
94
  attach: (dbNameToAttach: string, alias: string, location?: string) => void,
71
95
  detach: (alias: string) => void,
72
- transaction: (fn: (tx: Transaction) => void) => Promise<void>,
96
+ transaction: (fn: (tx: Transaction) => Promise<void>) => Promise<void>,
73
97
  execute: (query: string, params?: any[]) => QueryResult,
74
- executeAsync: (
75
- query: string,
76
- params?: any[]
77
- ) => Promise<QueryResult>,
78
- executeBatch: (commands: SQLBatchParams[]) => BatchQueryResult,
79
- executeBatchAsync: (commands: SQLBatchParams[]) => Promise<BatchQueryResult>,
80
- loadFile: (location: string) => Promise<FileLoadResult>
98
+ executeAsync: (query: string, params?: any[]) => Promise<QueryResult>,
99
+ executeBatch: (commands: SQLBatchTuple[]) => BatchQueryResult,
100
+ executeBatchAsync: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>,
101
+ loadFile: (location: string) => Promise<FileLoadResult>,
102
+ updateHook: (
103
+ callback: ((params: {
104
+ table: string;
105
+ operation: UpdateHookOperation;
106
+ row?: any;
107
+ rowId: number;
108
+ }) => void) | null
109
+ ) => void,
110
+ commitHook: (callback: (() => void) | null) => void,
111
+ rollbackHook: (callback: (() => void) | null) => void
81
112
  }
82
113
  ```
83
114
 
@@ -281,7 +312,7 @@ const { rowsAffected, commands } = db
281
312
  });
282
313
  ```
283
314
 
284
- ## Update hook
315
+ ## Hooks
285
316
 
286
317
  You can subscribe to changes in your database by using an update hook:
287
318
 
@@ -303,6 +334,46 @@ db.execute('INSERT INTO "User" (id, name, age, networth) VALUES(?, ?, ?, ?)', [
303
334
  ]);
304
335
  ```
305
336
 
337
+ Same goes for commit and rollback hooks
338
+
339
+ ```ts
340
+ // will fire whenever a transaction commits
341
+ db.commitHook(() => {
342
+ console.log('Transaction commmitted!');
343
+ });
344
+
345
+ db.rollbackHook(() => {
346
+ console.log('Transaction rolled back!');
347
+ });
348
+
349
+ // will fire the commit hook
350
+ db.transaction(async (tx) => {
351
+ tx.execute(
352
+ 'INSERT INTO "User" (id, name, age, networth) VALUES(?, ?, ?, ?)',
353
+ [id, name, age, networth]
354
+ );
355
+ });
356
+
357
+ // will fire the rollback hook
358
+ try {
359
+ await db.transaction(async (tx) => {
360
+ throw new Error('Test Error');
361
+ });
362
+ } catch (e) {
363
+ // intentionally left blank
364
+ }
365
+ ```
366
+
367
+ You can pass `null`` to remove hooks at any moment:
368
+
369
+ ```ts
370
+ db.updateHook(null);
371
+
372
+ db.commitHook(null);
373
+
374
+ db.rollbackHook(null);
375
+ ```
376
+
306
377
  ## Use built-in SQLite
307
378
 
308
379
  On iOS you can use the embedded SQLite, when running `pod-install` add an environment flag:
@@ -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,8 +1,5 @@
1
1
  package com.op.sqlite;
2
2
 
3
- import android.util.Log;
4
-
5
- import com.facebook.react.bridge.ReactApplicationContext;
6
3
  import com.facebook.react.bridge.ReactContext;
7
4
  import com.facebook.react.turbomodule.core.CallInvokerHolderImpl;
8
5
 
@@ -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
  {
@@ -449,6 +448,13 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
449
448
 
450
449
  auto dbName = args[0].asString(rt).utf8(rt);
451
450
  auto callback = std::make_shared<jsi::Value>(rt, args[1]);
451
+
452
+ if (callback->isUndefined() || callback->isNull())
453
+ {
454
+ unregisterUpdateHook(dbName);
455
+ return {};
456
+ }
457
+
452
458
  updateHooks[dbName] = callback;
453
459
 
454
460
  auto hook = [&rt, callback](std::string dbName, std::string tableName, std::string operation, int rowId) {
@@ -491,6 +497,11 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
491
497
 
492
498
  auto dbName = args[0].asString(rt).utf8(rt);
493
499
  auto callback = std::make_shared<jsi::Value>(rt, args[1]);
500
+ if (callback->isUndefined() || callback->isNull())
501
+ {
502
+ unregisterCommitHook(dbName);
503
+ return {};
504
+ }
494
505
  commitHooks[dbName] = callback;
495
506
 
496
507
  auto hook = [&rt, callback](std::string dbName) {
@@ -504,7 +515,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
504
515
 
505
516
  return {};
506
517
  });
507
-
518
+
508
519
  auto rollbackHook = HOSTFN("rollbackHook", 2)
509
520
  {
510
521
  if (sizeof(args) < 2)
@@ -515,6 +526,12 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
515
526
 
516
527
  auto dbName = args[0].asString(rt).utf8(rt);
517
528
  auto callback = std::make_shared<jsi::Value>(rt, args[1]);
529
+
530
+ if (callback->isUndefined() || callback->isNull())
531
+ {
532
+ unregisterRollbackHook(dbName);
533
+ return {};
534
+ }
518
535
  rollbackHooks[dbName] = callback;
519
536
 
520
537
  auto hook = [&rt, callback](std::string dbName) {
@@ -529,7 +546,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> jsCallInvoker
529
546
 
530
547
  return {};
531
548
  });
532
-
549
+
533
550
  jsi::Object module = jsi::Object(rt);
534
551
 
535
552
  module.setProperty(rt, "open", std::move(open));
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
 
@@ -367,27 +370,30 @@ namespace opsqlite {
367
370
  }
368
371
  i++;
369
372
  }
370
- results->push_back(row);
373
+ if (results != nullptr) {
374
+ results->push_back(row);
375
+ }
371
376
  break;
372
377
  }
373
378
 
374
379
  case SQLITE_DONE:
375
- i = 0;
376
- count = sqlite3_column_count(statement);
377
-
378
- while (i < count)
379
- {
380
- column_name = sqlite3_column_name(statement, i);
381
- const char *type = sqlite3_column_decltype(statement, i);
382
- auto metadata = DynamicHostObject();
383
- metadata.fields.push_back(std::make_pair("name", column_name));
384
- metadata.fields.push_back(std::make_pair("index", i));
385
- metadata.fields.push_back(std::make_pair("type", type));
380
+ if (metadatas != nullptr) {
381
+ i = 0;
382
+ count = sqlite3_column_count(statement);
386
383
 
387
- metadatas->push_back(metadata);
388
- i++;
384
+ while (i < count)
385
+ {
386
+ column_name = sqlite3_column_name(statement, i);
387
+ const char *type = sqlite3_column_decltype(statement, i);
388
+ auto metadata = DynamicHostObject();
389
+ metadata.fields.push_back(std::make_pair("name", column_name));
390
+ metadata.fields.push_back(std::make_pair("index", i));
391
+ metadata.fields.push_back(std::make_pair("type", type == NULL ? "UNKNOWN" : type));
392
+
393
+ metadatas->push_back(metadata);
394
+ i++;
395
+ }
389
396
  }
390
-
391
397
  isConsuming = false;
392
398
  break;
393
399
 
@@ -557,6 +563,28 @@ namespace opsqlite {
557
563
  };
558
564
  }
559
565
 
566
+ BridgeResult unregisterUpdateHook(std::string const dbName) {
567
+ if (dbMap.count(dbName) == 0)
568
+ {
569
+ return {
570
+ SQLiteError,
571
+ "[op-sqlite] Database not opened: " + dbName
572
+ };
573
+ }
574
+
575
+ sqlite3 *db = dbMap[dbName];
576
+ updateCallbackMap.erase(dbName);
577
+
578
+ sqlite3_update_hook(
579
+ db,
580
+ NULL,
581
+ NULL);
582
+
583
+ return {
584
+ SQLiteOk
585
+ };
586
+ }
587
+
560
588
  int commit_callback(void *dbName) {
561
589
  std::string &strDbName = *(static_cast<std::string*>(dbName));
562
590
  auto callback = commitCallbackMap[strDbName];
@@ -596,6 +624,27 @@ namespace opsqlite {
596
624
  };
597
625
  }
598
626
 
627
+ BridgeResult unregisterCommitHook(std::string const dbName) {
628
+ if (dbMap.count(dbName) == 0)
629
+ {
630
+ return {
631
+ SQLiteError,
632
+ "[op-sqlite] Database not opened: " + dbName
633
+ };
634
+ }
635
+
636
+ sqlite3 *db = dbMap[dbName];
637
+ commitCallbackMap.erase(dbName);
638
+ sqlite3_commit_hook(
639
+ db,
640
+ NULL,
641
+ NULL);
642
+
643
+ return {
644
+ SQLiteOk
645
+ };
646
+ }
647
+
599
648
  void rollback_callback(void *dbName) {
600
649
  std::string &strDbName = *(static_cast<std::string*>(dbName));
601
650
  auto callback = rollbackCallbackMap[strDbName];
@@ -632,4 +681,26 @@ namespace opsqlite {
632
681
  SQLiteOk
633
682
  };
634
683
  }
684
+
685
+ BridgeResult unregisterRollbackHook(std::string const dbName) {
686
+ if (dbMap.count(dbName) == 0)
687
+ {
688
+ return {
689
+ SQLiteError,
690
+ "[op-sqlite] Database not opened: " + dbName
691
+ };
692
+ }
693
+
694
+ sqlite3 *db = dbMap[dbName];
695
+ rollbackCallbackMap.erase(dbName);
696
+
697
+ sqlite3_rollback_hook(
698
+ db,
699
+ NULL,
700
+ NULL);
701
+
702
+ return {
703
+ SQLiteOk
704
+ };
705
+ }
635
706
  }
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
 
@@ -33,11 +33,13 @@ void sqliteCloseAll();
33
33
 
34
34
  BridgeResult registerUpdateHook(std::string const dbName,
35
35
  std::function<void (std::string dbName, std::string tableName, std::string operation, int rowId)> const callback);
36
+ BridgeResult unregisterUpdateHook(std::string const dbName);
36
37
  BridgeResult registerCommitHook(std::string const dbName,
37
38
  std::function<void (std::string dbName)> const callback);
39
+ BridgeResult unregisterCommitHook(std::string const dbName);
38
40
  BridgeResult registerRollbackHook(std::string const dbName,
39
41
  std::function<void (std::string dbName)> const callback);
40
-
42
+ BridgeResult unregisterRollbackHook(std::string const dbName);
41
43
  }
42
44
 
43
45
  #endif /* bridge_h */
package/ios/OPSQLite.mm CHANGED
@@ -1,20 +1,27 @@
1
1
  #import "OPSQLite.h"
2
-
3
2
  #import <React/RCTBridge+Private.h>
4
-
5
3
  #import <React/RCTUtils.h>
6
4
  #import <ReactCommon/RCTTurboModule.h>
7
5
  #import <jsi/jsi.h>
8
-
9
6
  #import "../cpp/bindings.h"
10
7
 
11
8
  @implementation OPSQLite
12
9
 
13
10
  RCT_EXPORT_MODULE(OPSQLite)
14
11
 
15
- RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
16
- NSLog(@"Initializing OP-SQLite module...");
12
+ - (NSDictionary *)constantsToExport {
13
+ NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, true);
14
+ NSString *libraryPath = [libraryPaths objectAtIndex:0];
17
15
 
16
+ NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true);
17
+ NSString *documentPath = [documentPaths objectAtIndex:0];
18
+ return @{
19
+ @"IOS_DOCUMENT_PATH": documentPath,
20
+ @"IOS_LIBRARY_PATH": libraryPath
21
+ };
22
+ }
23
+
24
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
18
25
  RCTBridge *bridge = [RCTBridge currentBridge];
19
26
  RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge;
20
27
  if (cxxBridge == nil) {
@@ -40,10 +47,9 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
40
47
  NSURL *storeUrl = [fileManager containerURLForSecurityApplicationGroupIdentifier:appGroupID];
41
48
 
42
49
  if (storeUrl == nil) {
43
- NSLog(@"Invalid AppGroup ID provided (%@). Check the value of \"AppGroup\" in your Info.plist file", appGroupID);
50
+ NSLog(@"OP-SQLite: Invalid AppGroup ID provided (%@). Check the value of \"AppGroup\" in your Info.plist file", appGroupID);
44
51
  return @false;
45
52
  }
46
- NSLog(@"Configured with AppGroup ID: %@", appGroupID);
47
53
 
48
54
  documentPath = [storeUrl path];
49
55
  } else {
@@ -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\n ) => void;\n commitHook: (dbName: string, callback: () => void) => void;\n rollbackHook: (dbName: string, callback: () => void) => 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\n ) => void;\n commitHook: (callback: () => void) => void;\n rollbackHook: (callback: () => void) => 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,CACZ,iJAAgJG,MAAO,EAAC,CAC1J;EACH;;EAEA;EACA,IAAIR,MAAM,CAACC,eAAe,IAAI,IAAI,EAAE;IAClC,MAAM,IAAII,KAAK,CACb,yIAAyI,CAC1I;EACH;AACF;AAEA,MAAMI,KAAK,GAAGT,MAAM,CAACC,eAAe;AAC7B,MAAMG,QAAQ,GAAGK,KAAgB;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AATA;AAsIA,MAAMC,KAGL,GAAG,CAAC,CAAC;;AAEN;;AA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,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,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,E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GC,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\n ) => void;\n commitHook: (dbName: string, callback: () => void) => void;\n rollbackHook: (dbName: string, callback: () => void) => 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\n ) => void;\n commitHook: (callback: () => void) => void;\n rollbackHook: (callback: () => void) => 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,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,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AAQ,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,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AC/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"}
@@ -3,6 +3,7 @@ declare global {
3
3
  var __OPSQLiteProxy: object | undefined;
4
4
  }
5
5
  export declare const OPSQLite: ISQLite;
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;
@@ -89,14 +90,14 @@ interface ISQLite {
89
90
  executeBatch: (dbName: string, commands: SQLBatchTuple[]) => BatchQueryResult;
90
91
  executeBatchAsync: (dbName: string, commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;
91
92
  loadFile: (dbName: string, location: string) => Promise<FileLoadResult>;
92
- updateHook: (dbName: string, callback: (params: {
93
+ updateHook: (dbName: string, callback?: ((params: {
93
94
  table: string;
94
95
  operation: UpdateHookOperation;
95
96
  row?: any;
96
97
  rowId: number;
97
- }) => void) => void;
98
- commitHook: (dbName: string, callback: () => void) => void;
99
- rollbackHook: (dbName: string, callback: () => void) => void;
98
+ }) => void) | null) => void;
99
+ commitHook: (dbName: string, callback?: (() => void) | null) => void;
100
+ rollbackHook: (dbName: string, callback?: (() => void) | null) => void;
100
101
  }
101
102
  export type OPSQLiteConnection = {
102
103
  close: () => void;
@@ -109,18 +110,17 @@ export type OPSQLiteConnection = {
109
110
  executeBatch: (commands: SQLBatchTuple[]) => BatchQueryResult;
110
111
  executeBatchAsync: (commands: SQLBatchTuple[]) => Promise<BatchQueryResult>;
111
112
  loadFile: (location: string) => Promise<FileLoadResult>;
112
- updateHook: (callback: (params: {
113
+ updateHook: (callback: ((params: {
113
114
  table: string;
114
115
  operation: UpdateHookOperation;
115
116
  row?: any;
116
117
  rowId: number;
117
- }) => void) => void;
118
- commitHook: (callback: () => void) => void;
119
- rollbackHook: (callback: () => void) => void;
118
+ }) => void) | null) => void;
119
+ commitHook: (callback: (() => void) | null) => void;
120
+ rollbackHook: (callback: (() => void) | null) => void;
120
121
  };
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/op-sqlite.podspec CHANGED
@@ -1,6 +1,7 @@
1
1
  require "json"
2
2
 
3
3
  package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
4
5
 
5
6
  Pod::Spec.new do |s|
6
7
  s.name = "op-sqlite"
@@ -30,7 +31,6 @@ Pod::Spec.new do |s|
30
31
  'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
31
32
  }
32
33
 
33
-
34
34
  if ENV['OP_SQLITE_USE_PHONE_VERSION'] == '1' then
35
35
  s.exclude_files = "cpp/sqlite3.c", "cpp/sqlite3.h"
36
36
  s.library = "sqlite3"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@op-engineering/op-sqlite",
3
- "version": "1.0.13",
3
+ "version": "2.0.0",
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,15 +169,17 @@ 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
172
+ callback?:
173
+ | ((params: {
174
+ table: string;
175
+ operation: UpdateHookOperation;
176
+ row?: any;
177
+ rowId: number;
178
+ }) => void)
179
+ | null
170
180
  ) => void;
171
- commitHook: (dbName: string, callback: () => void) => void;
172
- rollbackHook: (dbName: string, callback: () => void) => void;
181
+ commitHook: (dbName: string, callback?: (() => void) | null) => void;
182
+ rollbackHook: (dbName: string, callback?: (() => void) | null) => void;
173
183
  }
174
184
 
175
185
  const locks: Record<
@@ -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,23 +387,24 @@ 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
390
+ callback:
391
+ | ((params: {
392
+ table: string;
393
+ operation: UpdateHookOperation;
394
+ row?: any;
395
+ rowId: number;
396
+ }) => void)
397
+ | null
386
398
  ) => void;
387
- commitHook: (callback: () => void) => void;
388
- rollbackHook: (callback: () => void) => void;
399
+ commitHook: (callback: (() => void) | null) => void;
400
+ rollbackHook: (callback: (() => void) | null) => void;
389
401
  };
390
402
 
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),