@op-engineering/op-sqlite 9.1.1 → 9.1.2

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
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.2",
4
4
  "description": "Next generation SQLite for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",