@op-engineering/op-sqlite 2.0.17 → 2.0.18

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
@@ -127,9 +127,9 @@ db.execute('PRAGMA journal_mode = MEMORY;'); // or OFF
127
127
 
128
128
  If you use [prepared statements](#prepared-statements) are useful to reduce the time of critical queries.
129
129
 
130
- # Perf flag
130
+ # Perf flags
131
131
 
132
- You can turn on the performance flag to tweak all possible performance enhancing compilation flags, this greatly affects performance of sqlite itself:
132
+ You can turn on the performance flag to tweak all possible performance enhancing compilation flags, this greatly affects performance of sqlite itself. Be aware this disables thread safety, you should only uses transactions (which operate based on a mutex in JS side) to avoid any issues.
133
133
 
134
134
  ```sh
135
135
  # For iOS install pods with the following env variable, you can also just an export like on Android
@@ -147,6 +147,14 @@ If correctly set you should see the following output in your console
147
147
  OP-SQLITE performance mode enabled! 🚀
148
148
  ```
149
149
 
150
+ If you want to keep SQLite thread safety based on mutexes, you can use OP_SQLITE_PERF=2. This flag will enable the general compilation flags, except DSQLITE_THREADSAFE=0.
151
+ If correctly set you should see the following output in your console
152
+
153
+ ```sh
154
+ OP-SQLITE (thread safe) performance mode enabled! 🚀
155
+ ```
156
+
157
+ Here you can read more about [SQLite Thread Safe](https://www.sqlite.org/threadsafe.html)
150
158
  # SQLite Gotchas
151
159
 
152
160
  ## Strictness
@@ -408,7 +416,7 @@ References: [Attach](https://www.sqlite.org/lang_attach.html) - [Detach](https:/
408
416
  ```ts
409
417
  db.attach('mainDatabase', 'statistics', 'stats', '../databases');
410
418
 
411
- const res = db.executeSql(
419
+ const res = db.execute(
412
420
  'mainDatabase',
413
421
  'SELECT * FROM some_table_from_mainschema a INNER JOIN stats.some_table b on a.id_column = b.id_column'
414
422
  );
@@ -80,6 +80,10 @@ android {
80
80
  println "OP-SQLITE performance mode enabled! 🚀"
81
81
  cFlags "-DSQLITE_DQS=0", "-DSQLITE_THREADSAFE=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"
82
82
  }
83
+ if(System.getenv("OP_SQLITE_PERF") == '2') {
84
+ println "OP-SQLITE (thread safe) performance mode enabled! 🚀"
85
+ 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"
86
+ }
83
87
  cppFlags "-O2", "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID"
84
88
  abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
85
89
  arguments '-DANDROID_STL=c++_shared',
package/cpp/bindings.cpp CHANGED
@@ -410,18 +410,20 @@ void install(jsi::Runtime &rt,
410
410
  resolve, reject]() {
411
411
  try {
412
412
  auto batchResult = sqliteExecuteBatch(dbName, commands.get());
413
- invoker->invokeAsync(
414
- [&rt, batchResult = std::move(batchResult), resolve, reject] {
415
- if (batchResult.type == SQLiteOk) {
416
- auto res = jsi::Object(rt);
417
- res.setProperty(rt, "rowsAffected",
418
- jsi::Value(batchResult.affectedRows));
419
- resolve->asObject(rt).asFunction(rt).call(rt, std::move(res));
420
- } else {
421
- // TODO replace with reject
422
- throw jsi::JSError(rt, batchResult.message);
423
- }
424
- });
413
+ invoker->invokeAsync([&rt, batchResult = std::move(batchResult),
414
+ resolve, reject] {
415
+ if (batchResult.type == SQLiteOk) {
416
+ auto res = jsi::Object(rt);
417
+ res.setProperty(rt, "rowsAffected",
418
+ jsi::Value(batchResult.affectedRows));
419
+ resolve->asObject(rt).asFunction(rt).call(rt, std::move(res));
420
+ } else {
421
+ auto errorCtr = rt.global().getPropertyAsFunction(rt, "Error");
422
+ auto error = errorCtr.callAsConstructor(
423
+ rt, jsi::String::createFromUtf8(rt, batchResult.message));
424
+ reject->asObject(rt).asFunction(rt).call(rt, error);
425
+ }
426
+ });
425
427
  } catch (std::exception &exc) {
426
428
  invoker->invokeAsync(
427
429
  [&rt, reject, &exc] { throw jsi::JSError(rt, exc.what()); });
@@ -438,7 +440,7 @@ void install(jsi::Runtime &rt,
438
440
  auto load_file = HOSTFN("loadFile", 2) {
439
441
  if (sizeof(args) < 2) {
440
442
  throw std::runtime_error(
441
- "[op-sqlite][loadFileAsync] Incorrect parameter count");
443
+ "[op-sqlite][loadFile] Incorrect parameter count");
442
444
  return {};
443
445
  }
444
446
 
@@ -454,18 +456,21 @@ void install(jsi::Runtime &rt,
454
456
  try {
455
457
  const auto importResult = importSQLFile(dbName, sqlFileName);
456
458
 
457
- invoker->invokeAsync(
458
- [&rt, result = std::move(importResult), resolve, reject] {
459
- if (result.type == SQLiteOk) {
460
- auto res = jsi::Object(rt);
461
- res.setProperty(rt, "rowsAffected",
462
- jsi::Value(result.affectedRows));
463
- res.setProperty(rt, "commands", jsi::Value(result.commands));
464
- resolve->asObject(rt).asFunction(rt).call(rt, std::move(res));
465
- } else {
466
- throw jsi::JSError(rt, result.message);
467
- }
468
- });
459
+ invoker->invokeAsync([&rt, result = std::move(importResult), resolve,
460
+ reject] {
461
+ if (result.type == SQLiteOk) {
462
+ auto res = jsi::Object(rt);
463
+ res.setProperty(rt, "rowsAffected",
464
+ jsi::Value(result.affectedRows));
465
+ res.setProperty(rt, "commands", jsi::Value(result.commands));
466
+ resolve->asObject(rt).asFunction(rt).call(rt, std::move(res));
467
+ } else {
468
+ auto errorCtr = rt.global().getPropertyAsFunction(rt, "Error");
469
+ auto error = errorCtr.callAsConstructor(
470
+ rt, jsi::String::createFromUtf8(rt, result.message));
471
+ reject->asObject(rt).asFunction(rt).call(rt, error);
472
+ }
473
+ });
469
474
  } catch (std::exception &exc) {
470
475
  invoker->invokeAsync(
471
476
  [&rt, err = exc.what(), reject] { throw jsi::JSError(rt, err); });
package/cpp/bridge.cpp CHANGED
@@ -257,7 +257,7 @@ BridgeResult opsqlite_execute_prepared_statement(
257
257
  // Intentionally left blank
258
258
 
259
259
  default:
260
- row.values.push_back(JSVariant(NULL));
260
+ row.values.push_back(JSVariant(nullptr));
261
261
  break;
262
262
  }
263
263
  i++;
@@ -445,7 +445,7 @@ opsqlite_execute(std::string const &dbName, std::string const &query,
445
445
  // Intentionally left blank
446
446
 
447
447
  default:
448
- row.values.push_back(JSVariant(NULL));
448
+ row.values.push_back(JSVariant(nullptr));
449
449
  break;
450
450
  }
451
451
  i++;
@@ -617,7 +617,7 @@ opsqlite_execute_raw(std::string const &dbName, std::string const &query,
617
617
  // Intentionally left blank
618
618
 
619
619
  default:
620
- row.push_back(JSVariant(NULL));
620
+ row.push_back(JSVariant(nullptr));
621
621
  break;
622
622
  }
623
623
  i++;
package/op-sqlite.podspec CHANGED
@@ -28,6 +28,8 @@ Pod::Spec.new do |s|
28
28
 
29
29
  other_cflags = '-DSQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION=1'
30
30
 
31
+ optimizedCflags = other_cflags + '$(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'
32
+
31
33
  xcconfig = {
32
34
  :GCC_PREPROCESSOR_DEFINITIONS => "HAVE_FULLFSYNC=1",
33
35
  :WARNING_CFLAGS => "-Wno-shorten-64-to-32 -Wno-comma -Wno-unreachable-code -Wno-conditional-uninitialized -Wno-deprecated-declarations",
@@ -43,7 +45,12 @@ Pod::Spec.new do |s|
43
45
 
44
46
  if ENV['OP_SQLITE_PERF'] == '1' then
45
47
  puts "OP-SQLITE performance mode enabled! 🚀\n"
46
- xcconfig[:OTHER_CFLAGS] = other_cflags + '$(inherited) -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=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'
48
+ xcconfig[:OTHER_CFLAGS] = optimizedCflags + ' -DSQLITE_THREADSAFE=0 '
49
+ end
50
+
51
+ if ENV['OP_SQLITE_PERF'] == '2' then
52
+ puts "OP-SQLITE (thread safe) performance mode enabled! 🚀\n"
53
+ xcconfig[:OTHER_CFLAGS] = optimizedCflags + ' -DSQLITE_THREADSAFE=1 '
47
54
  end
48
55
 
49
56
  s.pod_target_xcconfig = xcconfig
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@op-engineering/op-sqlite",
3
- "version": "2.0.17",
3
+ "version": "2.0.18",
4
4
  "description": "Next generation SQLite for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",