@op-engineering/op-sqlite 9.1.1 → 9.1.3

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.
@@ -333,6 +333,10 @@ void DBHostObject::create_jsi_functions() {
333
333
  auto status = opsqlite_execute_raw(db_name, query, &params, &results);
334
334
  #endif
335
335
 
336
+ if (invalidated) {
337
+ return;
338
+ }
339
+
336
340
  invoker->invokeAsync([&rt, results = std::move(results),
337
341
  status = std::move(status), resolve, reject] {
338
342
  if (status.type == SQLiteOk) {
@@ -379,8 +383,9 @@ void DBHostObject::create_jsi_functions() {
379
383
  auto resolve = std::make_shared<jsi::Value>(rt, args[0]);
380
384
  auto reject = std::make_shared<jsi::Value>(rt, args[1]);
381
385
 
382
- auto task = [&rt, this, query = std::move(query), params = std::move(params), resolve,
383
- reject, invoker = this->jsCallInvoker]() {
386
+ auto task = [&rt, this, query = std::move(query),
387
+ params = std::move(params), resolve, reject,
388
+ invoker = this->jsCallInvoker]() {
384
389
  try {
385
390
 
386
391
  #ifdef OP_SQLITE_USE_LIBSQL
@@ -389,9 +394,9 @@ void DBHostObject::create_jsi_functions() {
389
394
  auto status = opsqlite_execute(db_name, query, &params);
390
395
  #endif
391
396
 
392
- // if (invalidated) {
393
- // return;
394
- // }
397
+ if (invalidated) {
398
+ return;
399
+ }
395
400
 
396
401
  invoker->invokeAsync([&rt, status = std::move(status), resolve,
397
402
  reject] {
@@ -455,9 +460,9 @@ void DBHostObject::create_jsi_functions() {
455
460
  &results, metadata);
456
461
  #endif
457
462
 
458
- // if (invalidated) {
459
- // return;
460
- // }
463
+ if (invalidated) {
464
+ return;
465
+ }
461
466
 
462
467
  invoker->invokeAsync(
463
468
  [&rt,
@@ -533,6 +538,11 @@ void DBHostObject::create_jsi_functions() {
533
538
  #else
534
539
  auto batchResult = opsqlite_execute_batch(db_name, commands.get());
535
540
  #endif
541
+
542
+ if (invalidated) {
543
+ return;
544
+ }
545
+
536
546
  jsCallInvoker->invokeAsync([&rt, batchResult = std::move(batchResult),
537
547
  resolve, reject] {
538
548
  if (batchResult.type == SQLiteOk) {
@@ -934,4 +944,8 @@ void DBHostObject::set(jsi::Runtime &rt, const jsi::PropNameID &name,
934
944
  throw std::runtime_error("You cannot write to this object!");
935
945
  }
936
946
 
947
+ void DBHostObject::invalidate() { invalidated = true; }
948
+
949
+ DBHostObject::~DBHostObject() { invalidated = true; }
950
+
937
951
  } // namespace opsqlite
@@ -51,6 +51,8 @@ public:
51
51
  jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
52
52
  void set(jsi::Runtime &rt, const jsi::PropNameID &name,
53
53
  const jsi::Value &value);
54
+ void invalidate();
55
+ ~DBHostObject();
54
56
 
55
57
  private:
56
58
  void auto_register_update_hook();
@@ -68,6 +70,7 @@ private:
68
70
  jsi::Runtime &rt;
69
71
  std::vector<std::shared_ptr<ReactiveQuery>> reactive_queries;
70
72
  bool is_update_hook_registered = false;
73
+ bool invalidated = false;
71
74
  };
72
75
 
73
76
  } // namespace opsqlite
package/cpp/bindings.cpp CHANGED
@@ -24,6 +24,7 @@ std::string _crsqlite_path;
24
24
  std::string _sqlite_vec_path;
25
25
  std::shared_ptr<react::CallInvoker> _invoker;
26
26
  std::shared_ptr<ThreadPool> thread_pool = std::make_shared<ThreadPool>();
27
+ std::vector<std::shared_ptr<DBHostObject>> dbs;
27
28
 
28
29
  // React native will try to clean the module on JS context invalidation
29
30
  // (CodePush/Hot Reload) The clearState function is called and we use this flag
@@ -31,6 +32,9 @@ std::shared_ptr<ThreadPool> thread_pool = std::make_shared<ThreadPool>();
31
32
  bool invalidated = false;
32
33
 
33
34
  void clearState() {
35
+ for (const auto &db : dbs) {
36
+ db->invalidate();
37
+ }
34
38
  invalidated = true;
35
39
 
36
40
  #ifdef OP_SQLITE_USE_LIBSQL
@@ -88,6 +92,7 @@ void install(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> invoker,
88
92
  std::shared_ptr<DBHostObject> db = std::make_shared<DBHostObject>(
89
93
  rt, path, invoker, thread_pool, name, path, _crsqlite_path,
90
94
  _sqlite_vec_path, encryptionKey);
95
+ dbs.emplace_back(db);
91
96
  return jsi::Object::createFromHostObject(rt, db);
92
97
  });
93
98
 
package/cpp/bridge.cpp CHANGED
@@ -63,7 +63,7 @@ BridgeResult opsqlite_open(std::string const &name,
63
63
 
64
64
  if (dbMap.count(name) != 0) {
65
65
  throw std::runtime_error(
66
- "[OP-SQLITE] Only JS connection per database is allowed, db name: " +
66
+ "[OP-SQLITE] Only one connection per database is allowed, db name: " +
67
67
  name);
68
68
  }
69
69
  #endif
@@ -742,9 +742,11 @@ opsqlite_execute_raw(std::string const &dbName, std::string const &query,
742
742
  opsqlite_bind_statement(statement, params);
743
743
  }
744
744
 
745
- int i, count, column_type;
745
+ int i, column_type;
746
746
  std::string column_name, column_declared_type;
747
747
 
748
+ int column_count = sqlite3_column_count(statement);
749
+
748
750
  while (isConsuming) {
749
751
  step = sqlite3_step(statement);
750
752
 
@@ -755,25 +757,15 @@ opsqlite_execute_raw(std::string const &dbName, std::string const &query,
755
757
  }
756
758
 
757
759
  std::vector<JSVariant> row;
760
+ row.reserve(column_count);
758
761
 
759
762
  i = 0;
760
763
 
761
- count = sqlite3_column_count(statement);
762
-
763
- while (i < count) {
764
+ while (i < column_count) {
764
765
  column_type = sqlite3_column_type(statement, i);
765
766
 
766
767
  switch (column_type) {
767
- case SQLITE_INTEGER: {
768
- /**
769
- * Warning this will loose precision because JS can
770
- * only represent Integers up to 53 bits
771
- */
772
- double column_value = sqlite3_column_double(statement, i);
773
- row.emplace_back(column_value);
774
- break;
775
- }
776
-
768
+ case SQLITE_INTEGER:
777
769
  case SQLITE_FLOAT: {
778
770
  double column_value = sqlite3_column_double(statement, i);
779
771
  row.emplace_back(column_value);
@@ -809,7 +801,7 @@ opsqlite_execute_raw(std::string const &dbName, std::string const &query,
809
801
  i++;
810
802
  }
811
803
 
812
- results->push_back(row);
804
+ results->emplace_back(row);
813
805
 
814
806
  break;
815
807
  }
@@ -871,7 +863,7 @@ std::string operation_to_string(int operation_type) {
871
863
  return "UPDATE";
872
864
 
873
865
  default:
874
- throw std::invalid_argument("Uknown SQLite operation on hook");
866
+ throw std::invalid_argument("Unknown SQLite operation on hook");
875
867
  }
876
868
  }
877
869
 
package/ios/OPSQLite.mm CHANGED
@@ -12,10 +12,6 @@
12
12
 
13
13
  RCT_EXPORT_MODULE()
14
14
 
15
- - (void)setBridge:(RCTBridge *)bridge {
16
- _bridge = bridge;
17
- }
18
-
19
15
  + (BOOL)requiresMainQueueSetup {
20
16
  return YES;
21
17
  }
@@ -97,10 +93,8 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
97
93
  return @true;
98
94
  }
99
95
 
100
- RCT_EXPORT_METHOD(moveAssetsDatabase
101
- : (NSDictionary *)args resolve
102
- : (RCTPromiseResolveBlock)resolve reject
103
- : (RCTPromiseRejectBlock)reject) {
96
+ RCT_EXPORT_METHOD(moveAssetsDatabase : (NSDictionary *)args resolve : (
97
+ RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject) {
104
98
  NSString *documentPath = [NSSearchPathForDirectoriesInDomains(
105
99
  NSLibraryDirectory, NSUserDomainMask, true) objectAtIndex:0];
106
100
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@op-engineering/op-sqlite",
3
- "version": "9.1.1",
3
+ "version": "9.1.3",
4
4
  "description": "Next generation SQLite for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",