@op-engineering/op-sqlite 15.1.2 โ†’ 15.1.4

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.
@@ -85,28 +85,27 @@ if(useSQLCipher) {
85
85
  }
86
86
 
87
87
  if(useCRSQLite) {
88
- println "[OP-SQLITE] using CR-SQLite ๐Ÿค–"
88
+ println "[OP-SQLITE] using CR-SQLite"
89
89
  }
90
90
 
91
91
  if(performanceMode) {
92
- println "[OP-SQLITE] Performance mode enabled! ๐Ÿš€"
92
+ println "[OP-SQLITE] Performance mode enabled"
93
93
  }
94
94
 
95
95
  if(enableFTS5) {
96
- println "[OP-SQLITE] FTS5 enabled! ๐Ÿ”Ž"
96
+ println "[OP-SQLITE] FTS5 enabled"
97
97
  }
98
98
 
99
99
  if(enableRtree) {
100
- println "[OP-SQLITE] RTree enabled! ๐ŸŒฒ"
100
+ println "[OP-SQLITE] RTree enabled"
101
101
  }
102
102
 
103
103
  if(useSqliteVec) {
104
- println "[OP-SQLITE] Sqlite Vec enabled! โ†—๏ธ"
104
+ println "[OP-SQLITE] Sqlite-vec enabled"
105
105
  }
106
106
 
107
-
108
107
  if (!tokenizers.isEmpty()) {
109
- println "[OP-SQLITE] Tokenizers enabled! ๐Ÿงพ Tokenizers: " + tokenizers
108
+ println "[OP-SQLITE] Tokenizers enabled. Detected tokenizers: " + tokenizers
110
109
  }
111
110
 
112
111
  android {
@@ -120,58 +119,58 @@ android {
120
119
 
121
120
  externalNativeBuild {
122
121
  cmake {
123
- if(useSQLCipher) {
124
- cFlags += "-DOP_SQLITE_USE_SQLCIPHER=1"
125
- cppFlags += "-DOP_SQLITE_USE_SQLCIPHER=1"
126
- }
127
- if(useLibsql) {
128
- cFlags += "-DOP_SQLITE_USE_LIBSQL=1"
129
- cppFlags += "-DOP_SQLITE_USE_LIBSQL=1"
130
- }
131
- if(useCRSQLite) {
132
- cFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
133
- cppFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
134
- }
135
- if(performanceMode) {
136
- cFlags += ["-DSQLITE_DQS=0", "-DSQLITE_THREADSAFE=1", "-DSQLITE_DEFAULT_MEMSTATUS=0", "-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1", "-DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1", "-DSQLITE_MAX_EXPR_DEPTH=0", "-DSQLITE_OMIT_DEPRECATED=1", "-DSQLITE_OMIT_PROGRESS_CALLBACK=1", "-DSQLITE_OMIT_SHARED_CACHE=1", "-DSQLITE_USE_ALLOCA=1"]
137
- }
138
- if(enableFTS5) {
139
- cFlags += ["-DSQLITE_ENABLE_FTS5=1"]
140
- }
141
- if(enableRtree) {
142
- cFlags += ["-DSQLITE_ENABLE_RTREE=1"]
143
- }
144
- if(useSqliteVec) {
145
- cFlags += "-DOP_SQLITE_USE_SQLITE_VEC=1"
146
- cppFlags += "-DOP_SQLITE_USE_SQLITE_VEC=1"
147
- }
122
+ if(useSQLCipher) {
123
+ cFlags += "-DOP_SQLITE_USE_SQLCIPHER=1"
124
+ cppFlags += "-DOP_SQLITE_USE_SQLCIPHER=1"
125
+ }
126
+ if(useLibsql) {
127
+ cFlags += "-DOP_SQLITE_USE_LIBSQL=1"
128
+ cppFlags += "-DOP_SQLITE_USE_LIBSQL=1"
129
+ }
130
+ if(useCRSQLite) {
131
+ cFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
132
+ cppFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
133
+ }
134
+ if(performanceMode) {
135
+ cFlags += ["-DSQLITE_DQS=0", "-DSQLITE_DEFAULT_MEMSTATUS=0", "-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1", "-DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1", "-DSQLITE_MAX_EXPR_DEPTH=0", "-DSQLITE_OMIT_DEPRECATED=1", "-DSQLITE_OMIT_PROGRESS_CALLBACK=1", "-DSQLITE_OMIT_SHARED_CACHE=1", "-DSQLITE_USE_ALLOCA=1", "-DSQLITE_THREADSAFE=1"]
136
+ }
137
+ if(enableFTS5) {
138
+ cFlags += ["-DSQLITE_ENABLE_FTS5=1"]
139
+ }
140
+ if(enableRtree) {
141
+ cFlags += ["-DSQLITE_ENABLE_RTREE=1"]
142
+ }
143
+ if(useSqliteVec) {
144
+ cFlags += "-DOP_SQLITE_USE_SQLITE_VEC=1"
145
+ cppFlags += "-DOP_SQLITE_USE_SQLITE_VEC=1"
146
+ }
148
147
 
149
- // This are zeroes because they will be passed as C flags, so they become falsy
150
- def sourceFiles = 0
151
- // def tokenizerInitStrings = 0
152
- def tokenizersHeaderPath = 0
153
- if (!tokenizers.isEmpty()) {
154
- def sourceDir = isUserApp ? file("$rootDir/../../../c_sources") : file("$rootDir/../c_sources")
155
- def destDir = file("$buildscript.sourceFile.parentFile/c_sources")
156
- copy {
157
- from sourceDir
158
- into destDir
159
- include "**/*.cpp", "**/*.h"
148
+ // This are zeroes because they will be passed as C flags, so they become falsy
149
+ def sourceFiles = 0
150
+ // def tokenizerInitStrings = 0
151
+ def tokenizersHeaderPath = 0
152
+ if (!tokenizers.isEmpty()) {
153
+ def sourceDir = isUserApp ? file("$rootDir/../../../c_sources") : file("$rootDir/../c_sources")
154
+ def destDir = file("$buildscript.sourceFile.parentFile/c_sources")
155
+ copy {
156
+ from sourceDir
157
+ into destDir
158
+ include "**/*.cpp", "**/*.h"
159
+ }
160
+ sourceFiles = fileTree(dir: destDir, include: ["**/*.cpp", "**/*.h"]).files.join(";")
161
+ tokenizersHeaderPath = "../c_sources/tokenizers.h"
160
162
  }
161
- sourceFiles = fileTree(dir: destDir, include: ["**/*.cpp", "**/*.h"]).files.join(";")
162
- tokenizersHeaderPath = "../c_sources/tokenizers.h"
163
- }
164
163
 
165
- cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
166
- arguments "-DANDROID_STL=c++_shared",
167
- "-DSQLITE_FLAGS='$sqliteFlags'",
168
- "-DUSE_SQLCIPHER=${useSQLCipher ? 1 : 0}",
169
- "-DUSE_CRSQLITE=${useCRSQLite ? 1 : 0}",
170
- "-DUSE_LIBSQL=${useLibsql ? 1 : 0}",
171
- "-DUSE_SQLITE_VEC=${useSqliteVec ? 1 : 0}",
172
- "-DUSER_DEFINED_SOURCE_FILES=${sourceFiles}",
173
- "-DUSER_DEFINED_TOKENIZERS_HEADER_PATH='${tokenizersHeaderPath}'",
174
- "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
164
+ cppFlags "-O3 -frtti -fexceptions -Wall -fstack-protector-all"
165
+ arguments "-DANDROID_STL=c++_shared",
166
+ "-DSQLITE_FLAGS='$sqliteFlags'",
167
+ "-DUSE_SQLCIPHER=${useSQLCipher ? 1 : 0}",
168
+ "-DUSE_CRSQLITE=${useCRSQLite ? 1 : 0}",
169
+ "-DUSE_LIBSQL=${useLibsql ? 1 : 0}",
170
+ "-DUSE_SQLITE_VEC=${useSqliteVec ? 1 : 0}",
171
+ "-DUSER_DEFINED_SOURCE_FILES=${sourceFiles}",
172
+ "-DUSER_DEFINED_TOKENIZERS_HEADER_PATH='${tokenizersHeaderPath}'",
173
+ "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
175
174
  }
176
175
  }
177
176
  }
@@ -20,7 +20,7 @@ namespace react = facebook::react;
20
20
  void DBHostObject::flush_pending_reactive_queries(
21
21
  const std::shared_ptr<jsi::Value> &resolve) {
22
22
  invoker->invokeAsync(
23
- [this, resolve]() { resolve->asObject(rt).asFunction(rt).call(rt, {}); });
23
+ [resolve](jsi::Runtime &rt) { resolve->asObject(rt).asFunction(rt).call(rt, {}); });
24
24
  }
25
25
  #else
26
26
  void DBHostObject::flush_pending_reactive_queries(
@@ -36,8 +36,8 @@ void DBHostObject::flush_pending_reactive_queries(
36
36
  metadata);
37
37
 
38
38
  invoker->invokeAsync(
39
- [this, results = std::make_shared<std::vector<DumbHostObject>>(results),
40
- callback = query->callback, metadata, status = std::move(status)] {
39
+ [results = std::make_shared<std::vector<DumbHostObject>>(results),
40
+ callback = query->callback, metadata, status = std::move(status)](jsi::Runtime &rt) {
41
41
  auto jsiResult = create_result(rt, status, results.get(), metadata);
42
42
  callback->asObject(rt).asFunction(rt).call(rt, jsiResult);
43
43
  });
@@ -46,24 +46,24 @@ void DBHostObject::flush_pending_reactive_queries(
46
46
  pending_reactive_queries.clear();
47
47
 
48
48
  invoker->invokeAsync(
49
- [this, resolve]() { resolve->asObject(rt).asFunction(rt).call(rt, {}); });
49
+ [resolve](jsi::Runtime &rt) { resolve->asObject(rt).asFunction(rt).call(rt, {}); });
50
50
  }
51
51
 
52
52
  void DBHostObject::on_commit() {
53
53
  invoker->invokeAsync(
54
- [this] { commit_hook_callback->asObject(rt).asFunction(rt).call(rt); });
54
+ [this](jsi::Runtime &rt) { commit_hook_callback->asObject(rt).asFunction(rt).call(rt); });
55
55
  }
56
56
 
57
57
  void DBHostObject::on_rollback() {
58
58
  invoker->invokeAsync(
59
- [this] { rollback_hook_callback->asObject(rt).asFunction(rt).call(rt); });
59
+ [this](jsi::Runtime &rt) { rollback_hook_callback->asObject(rt).asFunction(rt).call(rt); });
60
60
  }
61
61
 
62
62
  void DBHostObject::on_update(const std::string &table,
63
63
  const std::string &operation, long long row_id) {
64
64
  if (update_hook_callback != nullptr) {
65
65
  invoker->invokeAsync(
66
- [this, callback = update_hook_callback, table, operation, row_id] {
66
+ [callback = update_hook_callback, table, operation, row_id](jsi::Runtime &rt) {
67
67
  auto res = jsi::Object(rt);
68
68
  res.setProperty(rt, "table", jsi::String::createFromUtf8(rt, table));
69
69
  res.setProperty(rt, "operation",
@@ -142,24 +142,21 @@ void DBHostObject::auto_register_update_hook() {
142
142
  #ifdef OP_SQLITE_USE_LIBSQL
143
143
  // Remote connection constructor
144
144
  DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &url,
145
- std::string &auth_token,
146
- std::shared_ptr<react::CallInvoker> invoker)
147
- : db_name(url), invoker(std::move(invoker)), rt(rt) {
145
+ std::string &auth_token)
146
+ : db_name(url) {
148
147
  _thread_pool = std::make_shared<ThreadPool>();
149
148
  db = opsqlite_libsql_open_remote(url, auth_token);
150
149
 
151
- create_jsi_functions();
150
+ create_jsi_functions(rt);
152
151
  }
153
152
 
154
153
  // Sync connection constructor
155
- DBHostObject::DBHostObject(jsi::Runtime &rt,
156
- std::shared_ptr<react::CallInvoker> invoker,
157
- std::string &db_name, std::string &path,
158
- std::string &url, std::string &auth_token,
159
- int sync_interval, bool offline,
160
- std::string &encryption_key,
154
+ DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &db_name,
155
+ std::string &path, std::string &url,
156
+ std::string &auth_token, int sync_interval,
157
+ bool offline, std::string &encryption_key,
161
158
  std::string &remote_encryption_key)
162
- : db_name(db_name), invoker(std::move(invoker)), rt(rt) {
159
+ : db_name(db_name) {
163
160
 
164
161
  _thread_pool = std::make_shared<ThreadPool>();
165
162
 
@@ -167,19 +164,17 @@ DBHostObject::DBHostObject(jsi::Runtime &rt,
167
164
  opsqlite_libsql_open_sync(db_name, path, url, auth_token, sync_interval,
168
165
  offline, encryption_key, remote_encryption_key);
169
166
 
170
- create_jsi_functions();
167
+ create_jsi_functions(rt);
171
168
  }
172
169
 
173
170
  #endif
174
171
 
175
172
  DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &base_path,
176
- std::shared_ptr<react::CallInvoker> invoker,
177
173
  std::string &db_name, std::string &path,
178
174
  std::string &crsqlite_path,
179
175
  std::string &sqlite_vec_path,
180
176
  std::string &encryption_key)
181
- : base_path(base_path), invoker(std::move(invoker)), db_name(db_name),
182
- rt(rt) {
177
+ : base_path(base_path), db_name(db_name) {
183
178
  _thread_pool = std::make_shared<ThreadPool>();
184
179
 
185
180
  #ifdef OP_SQLITE_USE_SQLCIPHER
@@ -190,10 +185,10 @@ DBHostObject::DBHostObject(jsi::Runtime &rt, std::string &base_path,
190
185
  #else
191
186
  db = opsqlite_open(db_name, path, crsqlite_path, sqlite_vec_path);
192
187
  #endif
193
- create_jsi_functions();
188
+ create_jsi_functions(rt);
194
189
  };
195
190
 
196
- void DBHostObject::create_jsi_functions() {
191
+ void DBHostObject::create_jsi_functions(jsi::Runtime &rt) {
197
192
  function_map["attach"] = HFN(this) {
198
193
  std::string secondary_db_path = std::string(base_path);
199
194
 
@@ -432,19 +427,19 @@ void DBHostObject::create_jsi_functions() {
432
427
  });
433
428
 
434
429
  #ifdef OP_SQLITE_USE_LIBSQL
435
- function_map["sync"] = HOSTFN("sync") {
430
+ function_map["sync"] = HFN(this) {
436
431
  opsqlite_libsql_sync(db);
437
432
  return {};
438
433
  });
439
434
 
440
- function_map["setReservedBytes"] = HOSTFN("setReservedBytes") {
441
- int32_t reserved_bytes = static_cast<int32_t>(args[0].asNumber());
435
+ function_map["setReservedBytes"] =HFN(this) {
436
+ auto reserved_bytes = static_cast<int32_t>(args[0].asNumber());
442
437
  opsqlite_libsql_set_reserved_bytes(db, reserved_bytes);
443
438
  return {};
444
439
  });
445
440
 
446
- function_map["getReservedBytes"] = HOSTFN("getReservedBytes") {
447
- return jsi::Value(opsqlite_libsql_get_reserved_bytes(db));
441
+ function_map["getReservedBytes"] = HFN(this) {
442
+ return {opsqlite_libsql_get_reserved_bytes(db)};
448
443
  });
449
444
  #else
450
445
  function_map["loadFile"] = HFN(this) {
@@ -466,7 +461,7 @@ void DBHostObject::create_jsi_functions() {
466
461
  });
467
462
  });
468
463
 
469
- function_map["updateHook"] = HOSTFN("updateHook") {
464
+ function_map["updateHook"] = HFN(this) {
470
465
  auto callback = std::make_shared<jsi::Value>(rt, args[0]);
471
466
 
472
467
  if (callback->isUndefined() || callback->isNull()) {
@@ -479,7 +474,7 @@ void DBHostObject::create_jsi_functions() {
479
474
  return {};
480
475
  });
481
476
 
482
- function_map["commitHook"] = HOSTFN("commitHook") {
477
+ function_map["commitHook"] = HFN(this) {
483
478
  if (count < 1) {
484
479
  throw std::runtime_error("[op-sqlite][commitHook] callback needed");
485
480
  }
@@ -495,7 +490,7 @@ void DBHostObject::create_jsi_functions() {
495
490
  return {};
496
491
  });
497
492
 
498
- function_map["rollbackHook"] = HOSTFN("rollbackHook") {
493
+ function_map["rollbackHook"] = HFN(this) {
499
494
  if (count < 1) {
500
495
  throw std::runtime_error("[op-sqlite][rollbackHook] callback needed");
501
496
  }
@@ -512,7 +507,7 @@ void DBHostObject::create_jsi_functions() {
512
507
  return {};
513
508
  });
514
509
 
515
- function_map["loadExtension"] = HOSTFN("loadExtension") {
510
+ function_map["loadExtension"] = HFN(this) {
516
511
  auto path = args[0].asString(rt).utf8(rt);
517
512
  std::string entry_point;
518
513
  if (count > 1 && args[1].isString()) {
@@ -523,7 +518,7 @@ void DBHostObject::create_jsi_functions() {
523
518
  return {};
524
519
  });
525
520
 
526
- function_map["reactiveExecute"] = HOSTFN("reactiveExecute") {
521
+ function_map["reactiveExecute"] = HFN(this) {
527
522
  auto query = args[0].asObject(rt);
528
523
 
529
524
  const std::string query_str =
@@ -566,7 +561,7 @@ void DBHostObject::create_jsi_functions() {
566
561
 
567
562
  auto_register_update_hook();
568
563
 
569
- auto unsubscribe = HOSTFN("unsubscribe") {
564
+ auto unsubscribe = HFN2(this, reactiveQuery) {
570
565
  auto it = std::find(reactive_queries.begin(), reactive_queries.end(),
571
566
  reactiveQuery);
572
567
  if (it != reactive_queries.end()) {
@@ -580,7 +575,7 @@ void DBHostObject::create_jsi_functions() {
580
575
  });
581
576
  #endif
582
577
 
583
- function_map["prepareStatement"] = HOSTFN("prepareStatement") {
578
+ function_map["prepareStatement"] = HFN(this) {
584
579
  auto query = args[0].asString(rt).utf8(rt);
585
580
  #ifdef OP_SQLITE_USE_LIBSQL
586
581
  libsql_stmt_t statement = opsqlite_libsql_prepare_statement(db, query);
@@ -593,7 +588,7 @@ void DBHostObject::create_jsi_functions() {
593
588
  return jsi::Object::createFromHostObject(rt, preparedStatementHostObject);
594
589
  });
595
590
 
596
- function_map["getDbPath"] = HOSTFN("getDbPath") {
591
+ function_map["getDbPath"] = HFN(this) {
597
592
  std::string path = std::string(base_path);
598
593
 
599
594
  if (count == 1) {
@@ -617,13 +612,12 @@ void DBHostObject::create_jsi_functions() {
617
612
  return jsi::String::createFromUtf8(rt, result);
618
613
  });
619
614
 
620
- function_map["flushPendingReactiveQueries"] =
621
- HOSTFN("flushPendingReactiveQueries") {
615
+ function_map["flushPendingReactiveQueries"] = HFN(this) {
622
616
  auto promiseCtr = rt.global().getPropertyAsFunction(rt, "Promise");
623
- auto promise = promiseCtr.callAsConstructor(rt, HOSTFN("executor") {
617
+ auto promise = promiseCtr.callAsConstructor(rt, HFN(this) {
624
618
  auto resolve = std::make_shared<jsi::Value>(rt, args[0]);
625
619
 
626
- auto task = [&rt, this, resolve]() {
620
+ auto task = [this, resolve]() {
627
621
  flush_pending_reactive_queries(resolve);
628
622
  };
629
623
 
@@ -645,11 +639,11 @@ std::vector<jsi::PropNameID> DBHostObject::getPropertyNames(jsi::Runtime &_rt) {
645
639
  return keys;
646
640
  }
647
641
 
648
- jsi::Value DBHostObject::get(jsi::Runtime &_rt,
642
+ jsi::Value DBHostObject::get(jsi::Runtime &rt,
649
643
  const jsi::PropNameID &propNameID) {
650
644
  auto name = propNameID.utf8(rt);
651
645
  if (function_map.count(name) != 1) {
652
- return HOST_STATIC_FN(name.c_str()) {
646
+ return HFN(name) {
653
647
  throw std::runtime_error(
654
648
  "[op-sqlite] Function " + name +
655
649
  " not implemented for current backend (libsql or sqlcipher)");
@@ -44,22 +44,19 @@ struct ReactiveQuery {
44
44
  class JSI_EXPORT DBHostObject : public jsi::HostObject {
45
45
  public:
46
46
  // Normal constructor shared between all backends
47
- DBHostObject(jsi::Runtime &rt, std::string &base_path,
48
- std::shared_ptr<react::CallInvoker> invoker,
49
- std::string &db_name, std::string &path,
50
- std::string &crsqlite_path, std::string &sqlite_vec_path,
51
- std::string &encryption_key);
47
+ DBHostObject(jsi::Runtime &rt, std::string &base_path, std::string &db_name,
48
+ std::string &path, std::string &crsqlite_path,
49
+ std::string &sqlite_vec_path, std::string &encryption_key);
52
50
 
53
51
  #ifdef OP_SQLITE_USE_LIBSQL
54
52
  // Constructor for remoteOpen, purely for remote databases
55
- DBHostObject(jsi::Runtime &rt, std::string &url, std::string &auth_token,
56
- std::shared_ptr<react::CallInvoker> invoker);
53
+ DBHostObject(jsi::Runtime &rt, std::string &url, std::string &auth_token);
57
54
 
58
55
  // Constructor for a local database with remote sync
59
- DBHostObject(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> invoker,
60
- std::string &db_name, std::string &path, std::string &url,
61
- std::string &auth_token, int sync_interval, bool offline,
62
- std::string &encryption_key, std::string &remote_encryption_key);
56
+ DBHostObject(jsi::Runtime &rt, std::string &db_name, std::string &path,
57
+ std::string &url, std::string &auth_token, int sync_interval,
58
+ bool offline, std::string &encryption_key,
59
+ std::string &remote_encryption_key);
63
60
  #endif
64
61
 
65
62
  std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
@@ -76,19 +73,16 @@ public:
76
73
  private:
77
74
  std::set<std::shared_ptr<ReactiveQuery>> pending_reactive_queries;
78
75
  void auto_register_update_hook();
79
- void create_jsi_functions();
80
- void
81
- flush_pending_reactive_queries(const std::shared_ptr<jsi::Value> &resolve);
76
+ void create_jsi_functions(jsi::Runtime &rt);
77
+ void flush_pending_reactive_queries(const std::shared_ptr<jsi::Value> &resolve);
82
78
 
83
79
  std::unordered_map<std::string, jsi::Value> function_map;
84
80
  std::string base_path;
85
- std::shared_ptr<react::CallInvoker> invoker;
86
81
  std::shared_ptr<ThreadPool> _thread_pool;
87
82
  std::string db_name;
88
83
  std::shared_ptr<jsi::Value> update_hook_callback;
89
84
  std::shared_ptr<jsi::Value> commit_hook_callback;
90
85
  std::shared_ptr<jsi::Value> rollback_hook_callback;
91
- jsi::Runtime &rt;
92
86
  std::vector<std::shared_ptr<ReactiveQuery>> reactive_queries;
93
87
  std::vector<PendingReactiveInvocation> pending_reactive_invocations;
94
88
  bool is_update_hook_registered = false;
package/cpp/OPSqlite.cpp CHANGED
@@ -43,14 +43,14 @@ void invalidate() {
43
43
  }
44
44
 
45
45
  void install(jsi::Runtime &rt,
46
- const std::shared_ptr<react::CallInvoker> &invoker,
46
+ const std::shared_ptr<react::CallInvoker> &_invoker,
47
47
  const char *base_path, const char *crsqlite_path,
48
48
  const char *sqlite_vec_path) {
49
49
 
50
50
  _base_path = std::string(base_path);
51
51
  _crsqlite_path = std::string(crsqlite_path);
52
52
  _sqlite_vec_path = std::string(sqlite_vec_path);
53
- opsqlite::invoker = invoker;
53
+ opsqlite::invoker = _invoker;
54
54
  opsqlite::invalidated = false;
55
55
 
56
56
  auto open = HFN0 {
@@ -69,12 +69,6 @@ void install(jsi::Runtime &rt,
69
69
  options.getProperty(rt, "encryptionKey").asString(rt).utf8(rt);
70
70
  }
71
71
 
72
- #ifdef OP_SQLITE_USE_SQLCIPHER
73
- if (encryption_key.empty()) {
74
- log_to_console(rt, "Encryption key is missing for SQLCipher");
75
- }
76
- #endif
77
-
78
72
  if (!location.empty()) {
79
73
  if (location == ":memory:") {
80
74
  path = ":memory:";
@@ -86,13 +80,12 @@ void install(jsi::Runtime &rt,
86
80
  }
87
81
 
88
82
  std::shared_ptr<DBHostObject> db = std::make_shared<DBHostObject>(
89
- rt, path, opsqlite::invoker, name, path, _crsqlite_path,
90
- _sqlite_vec_path, encryption_key);
83
+ rt, path, name, path, _crsqlite_path, _sqlite_vec_path, encryption_key);
91
84
  dbs.emplace_back(db);
92
85
  return jsi::Object::createFromHostObject(rt, db);
93
86
  });
94
87
 
95
- auto is_sqlcipher = HOST_STATIC_FN("isSQLCipher") {
88
+ auto is_sqlcipher = HFN(=) {
96
89
  #ifdef OP_SQLITE_USE_SQLCIPHER
97
90
  return true;
98
91
  #else
@@ -100,7 +93,7 @@ void install(jsi::Runtime &rt,
100
93
  #endif
101
94
  });
102
95
 
103
- auto is_ios_embedded = HOST_STATIC_FN("isIOSEmbedded") {
96
+ auto is_ios_embedded = HFN(=) {
104
97
  #ifdef OP_SQLITE_USE_PHONE_VERSION
105
98
  return true;
106
99
  #else
@@ -108,7 +101,7 @@ void install(jsi::Runtime &rt,
108
101
  #endif
109
102
  });
110
103
 
111
- auto is_libsql = HOST_STATIC_FN("isLibsql") {
104
+ auto is_libsql = HFN(=) {
112
105
  #ifdef OP_SQLITE_USE_LIBSQL
113
106
  return true;
114
107
  #else
@@ -117,7 +110,7 @@ void install(jsi::Runtime &rt,
117
110
  });
118
111
 
119
112
  #ifdef OP_SQLITE_USE_LIBSQL
120
- auto open_remote = HOST_STATIC_FN("openRemote") {
113
+ auto open_remote = HFN(=) {
121
114
  jsi::Object options = args[0].asObject(rt);
122
115
 
123
116
  std::string url = options.getProperty(rt, "url").asString(rt).utf8(rt);
@@ -126,12 +119,12 @@ void install(jsi::Runtime &rt,
126
119
  options.getProperty(rt, "authToken").asString(rt).utf8(rt);
127
120
 
128
121
  std::shared_ptr<DBHostObject> db =
129
- std::make_shared<DBHostObject>(rt, url, auth_token, invoker);
122
+ std::make_shared<DBHostObject>(rt, url, auth_token);
130
123
 
131
124
  return jsi::Object::createFromHostObject(rt, db);
132
125
  });
133
126
 
134
- auto open_sync = HOST_STATIC_FN("openSync") {
127
+ auto open_sync = HFN(=) {
135
128
  jsi::Object options = args[0].asObject(rt);
136
129
  std::string name = options.getProperty(rt, "name").asString(rt).utf8(rt);
137
130
  std::string path = std::string(_base_path);
@@ -169,7 +162,7 @@ void install(jsi::Runtime &rt,
169
162
  if (!location.empty()) {
170
163
  if (location == ":memory:") {
171
164
  path = ":memory:";
172
- } else if (location.rfind("/", 0) == 0) {
165
+ } else if (location.rfind('/', 0) == 0) {
173
166
  path = location;
174
167
  } else {
175
168
  path = path + "/" + location;
@@ -177,8 +170,8 @@ void install(jsi::Runtime &rt,
177
170
  }
178
171
 
179
172
  std::shared_ptr<DBHostObject> db = std::make_shared<DBHostObject>(
180
- rt, invoker, name, path, url, auth_token, sync_interval, offline,
181
- encryption_key, remote_encryption_key);
173
+ rt, name, path, url, auth_token, sync_interval, offline, encryption_key,
174
+ remote_encryption_key);
182
175
  return jsi::Object::createFromHostObject(rt, db);
183
176
  });
184
177
  #endif
@@ -48,7 +48,7 @@ jsi::Value PreparedStatementHostObject::get(jsi::Runtime &rt,
48
48
  }
49
49
 
50
50
  if (name == "bindSync") {
51
- return HOSTFN("bindSync") {
51
+ return HFN(this) {
52
52
  if (_stmt == nullptr) {
53
53
  throw std::runtime_error("statement has been freed");
54
54
  }
@@ -71,7 +71,7 @@ jsi::Value PreparedStatementHostObject::get(jsi::Runtime &rt,
71
71
  }
72
72
 
73
73
  if (name == "execute") {
74
- return HOSTFN("execute") {
74
+ return HFN(this) {
75
75
  if (_stmt == nullptr) {
76
76
  throw std::runtime_error("statement has been freed");
77
77
  }
package/cpp/macros.hpp CHANGED
@@ -1,19 +1,5 @@
1
1
  #pragma once
2
2
 
3
- #define HOSTFN(name) \
4
- jsi::Function::createFromHostFunction( \
5
- rt, \
6
- jsi::PropNameID::forAscii(rt, name), \
7
- 0, \
8
- [=, this](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value
9
-
10
- #define HOST_STATIC_FN(name) \
11
- jsi::Function::createFromHostFunction( \
12
- rt, \
13
- jsi::PropNameID::forAscii(rt, name), \
14
- 0, \
15
- [=](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value
16
-
17
3
  // Do not unroll into multi lines to avoid Xcode reporting the wrong lines
18
4
  #define HFN0 jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, ""), 0, [](jsi::Runtime &rt, const jsi::Value &that, const jsi::Value *args, size_t count) -> jsi::Value
19
5
  #define HFN(c1) jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, ""), 0, [c1](jsi::Runtime &rt, const jsi::Value &that, const jsi::Value *args, size_t count) -> jsi::Value
package/ios/OPSQLite.mm CHANGED
@@ -72,22 +72,24 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
72
72
  documentPath = [paths objectAtIndex:0];
73
73
  }
74
74
 
75
+ #ifdef OP_SQLITE_USE_CRSQLITE
75
76
  NSBundle *crsqlite_bundle =
76
77
  [NSBundle bundleWithIdentifier:@"io.vlcn.crsqlite"];
77
78
  NSString *crsqlite_path = [crsqlite_bundle pathForResource:@"crsqlite"
78
79
  ofType:@""];
80
+ #else
81
+ NSString *crsqlite_path = @"";
82
+ #endif
83
+
84
+
85
+ #ifdef OP_SQLITE_USE_SQLITE_VEC
79
86
  NSBundle *libsqlitevec_bundle =
80
87
  [NSBundle bundleWithIdentifier:@"com.ospfranco.sqlitevec"];
81
88
  NSString *sqlite_vec_path = [libsqlitevec_bundle pathForResource:@"sqlitevec"
82
89
  ofType:@""];
83
-
84
- if (crsqlite_path == nil) {
85
- crsqlite_path = @"";
86
- }
87
-
88
- if (sqlite_vec_path == nil) {
89
- sqlite_vec_path = @"";
90
- }
90
+ #else
91
+ NSString *sqlite_vec_path = @"";
92
+ #endif
91
93
 
92
94
  opsqlite::install(runtime, callInvoker, [documentPath UTF8String],
93
95
  [crsqlite_path UTF8String], [sqlite_vec_path UTF8String]);
@@ -1 +1 @@
1
- {"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../../src/functions.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,EAAE,EAEP,KAAK,aAAa,EAKnB,MAAM,SAAS,CAAC;AAEjB,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;CACzC;AA0BD,eAAO,MAAM,QAAQ,eAAyB,CAAC;AA8T/C;;;GAGG;AACH,eAAO,MAAM,QAAQ,WAAY;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,aAAa,CAA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Aa,QAAO,OAMhC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,QAXO,OAWS,CAAC"}
package/op-sqlite.podspec CHANGED
@@ -33,8 +33,8 @@ if is_user_app
33
33
  raise "package.json not found" if package_json_path.nil?
34
34
 
35
35
  app_package = JSON.parse(File.read(package_json_path))
36
- # When running on the example app
37
36
  else
37
+ # When running on the example app
38
38
  package_json_path = File.join(__dir__, "example", "package.json")
39
39
  app_package = JSON.parse(File.read(File.join(__dir__, "example", "package.json")))
40
40
  end
@@ -66,19 +66,19 @@ end
66
66
 
67
67
  if phone_version then
68
68
  if use_sqlcipher then
69
- raise "SQLCipher is not supported with phone version"
69
+ raise "SQLCipher is not supported with phone version. It cannot load extensions."
70
70
  end
71
71
 
72
72
  if use_crsqlite then
73
- raise "CRSQLite is not supported with phone version"
73
+ raise "CRSQLite is not supported with phone version. It cannot load extensions."
74
74
  end
75
75
 
76
76
  if rtree then
77
- raise "RTree is not supported with phone version"
77
+ raise "RTree is not supported with phone version. It cannot load extensions."
78
78
  end
79
79
 
80
80
  if use_sqlite_vec then
81
- raise "SQLite Vec is not supported with phone version"
81
+ raise "SQLite Vec is not supported with phone version. It cannot load extensions."
82
82
  end
83
83
  end
84
84
 
@@ -90,9 +90,11 @@ Pod::Spec.new do |s|
90
90
  s.license = package["license"]
91
91
  s.authors = package["author"]
92
92
 
93
- s.platforms = { :ios => "13.0", :tvos => "13.0", :osx => "10.15", :visionos => "1.0" }
93
+ s.platforms = { :ios => min_ios_version_supported, :tvos => "13.0", :osx => "10.15", :visionos => "1.0" }
94
94
  s.source = { :git => "https://github.com/op-engineering/op-sqlite.git", :tag => "#{s.version}" }
95
95
 
96
+ log_message.call("[OP-SQLITE] Configuration found at #{package_json_path}")
97
+
96
98
  install_modules_dependencies(s)
97
99
 
98
100
  # Base source files
@@ -114,41 +116,37 @@ Pod::Spec.new do |s|
114
116
 
115
117
  # Assign the collected source files to `s.source_files`
116
118
  s.source_files = source_files
117
-
119
+
118
120
  xcconfig = {
119
- :GCC_PREPROCESSOR_DEFINITIONS => "HAVE_FULLFSYNC=1",
120
- :WARNING_CFLAGS => "-Wno-shorten-64-to-32 -Wno-comma -Wno-unreachable-code -Wno-conditional-uninitialized -Wno-deprecated-declarations",
121
- :CLANG_CXX_LANGUAGE_STANDARD => "c++17",
121
+ :GCC_PREPROCESSOR_DEFINITIONS => "",
122
+ :CLANG_CXX_LANGUAGE_STANDARD => "c++20",
123
+ :GCC_OPTIMIZATION_LEVEL => "2",
122
124
  }
123
-
124
- log_message.call("[OP-SQLITE] Configuration found at #{package_json_path}")
125
125
 
126
126
  exclude_files = []
127
127
 
128
128
  if use_sqlcipher then
129
- log_message.call("[OP-SQLITE] using SQLCipher ๐Ÿ”’")
129
+ log_message.call("[OP-SQLITE] using SQLCipher")
130
130
  exclude_files += ["cpp/sqlite3.c", "cpp/sqlite3.h", "cpp/libsql/bridge.c", "cpp/libsql/bridge.h", "cpp/libsql/bridge.cpp", "cpp/libsql/libsql.h"]
131
131
  xcconfig[:GCC_PREPROCESSOR_DEFINITIONS] += " OP_SQLITE_USE_SQLCIPHER=1 HAVE_FULLFSYNC=1 SQLITE_HAS_CODEC SQLITE_TEMP_STORE=3 SQLITE_EXTRA_INIT=sqlcipher_extra_init SQLITE_EXTRA_SHUTDOWN=sqlcipher_extra_shutdown"
132
132
  s.dependency "OpenSSL-Universal"
133
133
  elsif use_libsql then
134
- log_message.call("[OP-SQLITE] using libsql ๐Ÿ“˜")
134
+ log_message.call("[OP-SQLITE] using libsql. Please contact turso (via Discord) for libsql issues")
135
135
  exclude_files += ["cpp/sqlite3.c", "cpp/sqlite3.h", "cpp/sqlcipher/sqlite3.c", "cpp/sqlcipher/sqlite3.h", "cpp/bridge.h", "cpp/bridge.cpp"]
136
136
  else
137
- log_message.call("[OP-SQLITE] using vanilla SQLite ๐Ÿ“ฆ")
137
+ log_message.call("[OP-SQLITE] using pure SQLite from CocoaPods with performance optimizations")
138
138
  exclude_files += ["cpp/sqlcipher/sqlite3.c", "cpp/sqlcipher/sqlite3.h", "cpp/libsql/bridge.c", "cpp/libsql/bridge.h", "cpp/libsql/bridge.cpp", "cpp/libsql/libsql.h"]
139
139
  end
140
140
 
141
- other_cflags = '-DSQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION=1'
142
- optimizedCflags = '$(inherited) -DSQLITE_DQS=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1 -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_OMIT_DEPRECATED=1 -DSQLITE_OMIT_PROGRESS_CALLBACK=1 -DSQLITE_OMIT_SHARED_CACHE=1 -DSQLITE_USE_ALLOCA=1 -DSQLITE_THREADSAFE=1'
141
+ other_cflags = '$(inherited) -DSQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION=1 -DHAVE_USLEEP=1 -DSQLITE_ENABLE_LOCKING_STYLE=0'
142
+ optimizedCflags = ' -DSQLITE_DQS=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1 -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_OMIT_DEPRECATED=1 -DSQLITE_OMIT_PROGRESS_CALLBACK=1 -DSQLITE_OMIT_SHARED_CACHE=1 -DSQLITE_USE_ALLOCA=1 -DSQLITE_STRICT_SUBTYPE=1'
143
143
  frameworks = []
144
144
 
145
145
  if fts5 then
146
- log_message.call("[OP-SQLITE] FTS5 enabled ๐Ÿ”Ž")
147
146
  xcconfig[:GCC_PREPROCESSOR_DEFINITIONS] += " SQLITE_ENABLE_FTS5=1"
148
147
  end
149
148
 
150
149
  if rtree then
151
- log_message.call("[OP-SQLITE] RTree enabled ๐ŸŒฒ")
152
150
  xcconfig[:GCC_PREPROCESSOR_DEFINITIONS] += " SQLITE_ENABLE_RTREE=1"
153
151
  end
154
152
 
@@ -160,7 +158,7 @@ Pod::Spec.new do |s|
160
158
  end
161
159
 
162
160
  if performance_mode then
163
- log_message.call("[OP-SQLITE] Performance mode enabled, some features might be disabled ๐Ÿš€")
161
+ log_message.call("[OP-SQLITE] Performance mode enabled")
164
162
  other_cflags += optimizedCflags
165
163
  end
166
164
 
@@ -186,7 +184,7 @@ Pod::Spec.new do |s|
186
184
  end
187
185
 
188
186
  if sqlite_flags != "" then
189
- log_message.call("[OP-SQLITE] Custom SQLite flags: #{sqlite_flags}")
187
+ log_message.call("[OP-SQLITE] Detected custom SQLite flags: #{sqlite_flags}")
190
188
  other_cflags += " #{sqlite_flags}"
191
189
  end
192
190
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@op-engineering/op-sqlite",
3
- "version": "15.1.2",
3
+ "version": "15.1.4",
4
4
  "description": "Fastest SQLite for React Native",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -62,7 +62,7 @@
62
62
  "react": "19.1.1",
63
63
  "react-native": "0.82.1",
64
64
  "react-native-builder-bob": "^0.40.15",
65
- "typescript": "5.0.4"
65
+ "typescript": "^5.9.2"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "react": "*",