@op-engineering/op-sqlite 9.1.0 → 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.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ![benchmark](benchmark.png)
1
+ ![benchmark](benchmark.jpg)
2
2
 
3
3
  Created by [@ospfranco](https://twitter.com/ospfranco). **Please consider sponsoring!**.
4
4
 
@@ -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, 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
@@ -315,7 +315,7 @@ BridgeResult opsqlite_execute_prepared_statement(
315
315
  }
316
316
 
317
317
  if (results != nullptr) {
318
- results->push_back(row);
318
+ results->emplace_back(row);
319
319
  }
320
320
 
321
321
  break;
@@ -335,7 +335,7 @@ BridgeResult opsqlite_execute_prepared_statement(
335
335
  metadata.fields.emplace_back("type",
336
336
  type == nullptr ? "UNKNOWN" : type);
337
337
 
338
- metadatas->push_back(metadata);
338
+ metadatas->emplace_back(metadata);
339
339
  i++;
340
340
  }
341
341
  }
@@ -400,11 +400,9 @@ BridgeResult opsqlite_execute(std::string const &name, std::string const &query,
400
400
  int status, current_column, column_count, column_type;
401
401
  std::string column_name, column_declared_type;
402
402
  std::vector<std::string> column_names;
403
- column_names.reserve(20);
404
403
  std::vector<std::vector<JSVariant>> rows;
405
404
  rows.reserve(20);
406
405
  std::vector<JSVariant> row;
407
- row.reserve(10);
408
406
 
409
407
  do {
410
408
  const char *query_str =
@@ -432,6 +430,7 @@ BridgeResult opsqlite_execute(std::string const &name, std::string const &query,
432
430
  }
433
431
 
434
432
  column_count = sqlite3_column_count(statement);
433
+ column_names.reserve(column_count);
435
434
  bool is_consuming_rows = true;
436
435
  double double_value;
437
436
  const char *string_value;
@@ -449,7 +448,7 @@ BridgeResult opsqlite_execute(std::string const &name, std::string const &query,
449
448
  case SQLITE_ROW:
450
449
  current_column = 0;
451
450
  row = std::vector<JSVariant>();
452
- column_count = sqlite3_column_count(statement);
451
+ row.reserve(column_count);
453
452
 
454
453
  while (current_column < column_count) {
455
454
  column_type = sqlite3_column_type(statement, current_column);
@@ -494,7 +493,7 @@ BridgeResult opsqlite_execute(std::string const &name, std::string const &query,
494
493
  current_column++;
495
494
  }
496
495
 
497
- rows.push_back(row);
496
+ rows.emplace_back(std::move(row));
498
497
  break;
499
498
 
500
499
  case SQLITE_DONE:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@op-engineering/op-sqlite",
3
- "version": "9.1.0",
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",