@op-engineering/op-sqlite 5.0.1 → 5.0.6

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,11 +1,5 @@
1
1
  ![benchmark](benchmark.png)
2
2
 
3
- ```sh
4
- yarn add @op-engineering/op-sqlite && npx pod-install
5
- ```
6
-
7
- OP-SQLite embeds the latest version of SQLite and provides a low-level API to execute SQL queries.
8
-
9
3
  **Current SQLite version: 3.45.1**
10
4
 
11
5
  Created by [@ospfranco](https://twitter.com/ospfranco). **Please consider sponsoring!**.
@@ -14,10 +8,6 @@ Created by [@ospfranco](https://twitter.com/ospfranco). **Please consider sponso
14
8
 
15
9
  [See the docs](https://ospfranco.notion.site/OP-SQLite-Documentation-a279a52102464d0cb13c3fa230d2f2dc?pvs=4)
16
10
 
17
- # Contribute
18
-
19
- You need to have clang-format installed (`brew install clang-format`)
20
-
21
11
  # License
22
12
 
23
13
  MIT License.
@@ -39,7 +39,7 @@ add_library(
39
39
  cpp-adapter.cpp
40
40
  )
41
41
 
42
- if (OP_SQLITE_USE_SQLCIPHER)
42
+ if (USE_SQLCIPHER)
43
43
  target_sources(${PACKAGE_NAME} PRIVATE ../cpp/sqlcipher/sqlite3.h ../cpp/sqlcipher/sqlite3.c)
44
44
 
45
45
  add_definitions(
@@ -53,7 +53,7 @@ else()
53
53
  target_sources(${PACKAGE_NAME} PRIVATE ../cpp/sqlite3.h ../cpp/sqlite3.c)
54
54
  endif()
55
55
 
56
- if (OP_SQLITE_USE_CRSQLITE)
56
+ if (USE_CRSQLITE)
57
57
  add_definitions(
58
58
  -DOP_SQLITE_USE_CRSQLITE=1
59
59
  )
@@ -70,16 +70,25 @@ find_package(ReactAndroid REQUIRED CONFIG)
70
70
  find_package(fbjni REQUIRED CONFIG)
71
71
  find_library(LOG_LIB log)
72
72
 
73
- target_link_libraries(
74
- ${PACKAGE_NAME}
75
- ${LOG_LIB}
76
- fbjni::fbjni
77
- ReactAndroid::jsi
78
- ReactAndroid::turbomodulejsijni
79
- ReactAndroid::react_nativemodule_core
80
- android
81
- )
82
-
83
- if (OP_SQLITE_USE_SQLCIPHER)
84
- target_link_libraries(${PACKAGE_NAME} PRIVATE openssl::crypto)
73
+ if (USE_SQLCIPHER)
74
+ target_link_libraries(
75
+ ${PACKAGE_NAME}
76
+ ${LOG_LIB}
77
+ fbjni::fbjni
78
+ ReactAndroid::jsi
79
+ ReactAndroid::turbomodulejsijni
80
+ ReactAndroid::react_nativemodule_core
81
+ android
82
+ openssl::crypto
83
+ )
84
+ else()
85
+ target_link_libraries(
86
+ ${PACKAGE_NAME}
87
+ ${LOG_LIB}
88
+ fbjni::fbjni
89
+ ReactAndroid::jsi
90
+ ReactAndroid::turbomodulejsijni
91
+ ReactAndroid::react_nativemodule_core
92
+ android
93
+ )
85
94
  endif()
@@ -31,6 +31,7 @@ def useSQLCipher = false
31
31
  def useCRSQLite = false
32
32
  def performanceMode = "0"
33
33
  def sqliteFlags = ""
34
+ def enableFTS5 = false
34
35
 
35
36
  def packageJsonFile = new File("$rootDir/../package.json")
36
37
  def packageJson = new JsonSlurper().parseText(packageJsonFile.text)
@@ -41,6 +42,7 @@ if(opsqliteConfig) {
41
42
  useCRSQLite = opsqliteConfig["crsqlite"]
42
43
  performanceMode = opsqliteConfig["performanceMode"] ? opsqliteConfig["performanceMode"] : ""
43
44
  sqliteFlags = opsqliteConfig["sqliteFlags"] ? opsqliteConfig["sqliteFlags"] : ""
45
+ enableFTS5 = opsqliteConfig["fts5"]
44
46
  }
45
47
 
46
48
  if(useSQLCipher) {
@@ -61,6 +63,10 @@ if(performanceMode == "2") {
61
63
  println "[OP-SQLITE] Thread safe performance mode enabled! 🚀"
62
64
  }
63
65
 
66
+ if(enableFTS5) {
67
+ println "[OP-SQLITE] FTS5 enabled! 🔎"
68
+ }
69
+
64
70
  if (isNewArchitectureEnabled()) {
65
71
  apply plugin: "com.facebook.react"
66
72
  }
@@ -100,26 +106,37 @@ android {
100
106
  }
101
107
 
102
108
  defaultConfig {
103
- minSdkVersion 21
109
+ minSdkVersion 23
104
110
  targetSdkVersion safeExtGet('targetSdkVersion', 34)
105
111
  versionCode 1
106
112
  versionName "1.0"
107
113
 
108
114
  externalNativeBuild {
109
115
  cmake {
116
+ if(useSQLCipher) {
117
+ cFlags += "-DOP_SQLITE_USE_SQLCIPHER=1"
118
+ cppFlags += "-DOP_SQLITE_USE_SQLCIPHER=1"
119
+ }
120
+ if(useCRSQLite) {
121
+ cFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
122
+ cppFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
123
+ }
110
124
  if(performanceMode == '1') {
111
125
  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"]
112
126
  }
113
127
  if(performanceMode == '2') {
114
128
  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"]
115
129
  }
130
+ if(enableFTS5) {
131
+ cFlags += ["-DSQLITE_ENABLE_FTS4=1", "-DSQLITE_ENABLE_FTS3_PARENTHESIS=1", "-DSQLITE_ENABLE_FTS5=1"]
132
+ }
116
133
 
117
134
  cppFlags "-O2", "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID"
118
135
  abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
119
136
  arguments "-DANDROID_STL=c++_shared",
120
- "-DSQLITE_FLAGS='$sqliteFlags'"
121
- "-DOP_SQLITE_USE_SQLCIPHER='${useSQLCipher? 1 : 0}'"
122
- "-DOP_SQLITE_USE_CRSQLITE='${useCRSQLite? 1 : 0}'"
137
+ "-DSQLITE_FLAGS='$sqliteFlags'",
138
+ "-DUSE_SQLCIPHER=${useSQLCipher ? 1 : 0}",
139
+ "-DUSE_CRSQLITE=${useCRSQLite ? 1 : 0}"
123
140
  abiFilters (*reactNativeArchitectures())
124
141
  }
125
142
  }
@@ -170,7 +187,7 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
170
187
  dependencies {
171
188
  implementation 'com.facebook.react:react-native'
172
189
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
173
- if (System.getenv("OP_SQLITE_USE_SQLCIPHER") == '1') {
190
+ if (useSQLCipher) {
174
191
  implementation('com.android.ndk.thirdparty:openssl:1.1.1q-beta-1')
175
192
  }
176
193
  }
@@ -15,7 +15,7 @@ namespace jsi = facebook::jsi;
15
15
 
16
16
  class JSI_EXPORT DumbHostObject : public jsi::HostObject {
17
17
  public:
18
- DumbHostObject(){};
18
+ DumbHostObject() {};
19
19
 
20
20
  DumbHostObject(std::shared_ptr<std::vector<SmartHostObject>> metadata);
21
21
 
@@ -42,6 +42,7 @@ jsi::Value PreparedStatementHostObject::get(jsi::Runtime &rt,
42
42
  if (_statement == nullptr) {
43
43
  throw std::runtime_error("statement has been freed");
44
44
  }
45
+
45
46
  std::vector<DumbHostObject> results;
46
47
  std::shared_ptr<std::vector<SmartHostObject>> metadata =
47
48
  std::make_shared<std::vector<SmartHostObject>>();
@@ -12,7 +12,7 @@ namespace jsi = facebook::jsi;
12
12
 
13
13
  class JSI_EXPORT SmartHostObject : public jsi::HostObject {
14
14
  public:
15
- SmartHostObject(){};
15
+ SmartHostObject() {};
16
16
 
17
17
  std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt);
18
18
 
package/cpp/bindings.cpp CHANGED
@@ -199,7 +199,7 @@ void install(jsi::Runtime &rt,
199
199
 
200
200
  std::string dbName = args[0].asString(rt).utf8(rt);
201
201
 
202
- std::string tempDocPath = std::string(basePath);
202
+ std::string path = std::string(basePath);
203
203
 
204
204
  if (count > 1 && !args[1].isUndefined() && !args[1].isNull()) {
205
205
  if (!args[1].isString()) {
@@ -207,10 +207,20 @@ void install(jsi::Runtime &rt,
207
207
  "[op-sqlite][open] database location must be a string");
208
208
  }
209
209
 
210
- tempDocPath = tempDocPath + "/" + args[1].asString(rt).utf8(rt);
210
+ std::string location = args[1].asString(rt).utf8(rt);
211
+
212
+ if (!location.empty()) {
213
+ if (location == ":memory:") {
214
+ path = ":memory:";
215
+ } else if (location.rfind("/", 0) == 0) {
216
+ path = location;
217
+ } else {
218
+ path = path + "/" + location;
219
+ }
220
+ }
211
221
  }
212
222
 
213
- BridgeResult result = opsqlite_remove(dbName, tempDocPath);
223
+ BridgeResult result = opsqlite_remove(dbName, path);
214
224
 
215
225
  if (result.type == SQLiteError) {
216
226
  throw std::runtime_error(result.message);
@@ -663,6 +673,14 @@ void install(jsi::Runtime &rt,
663
673
  return jsi::String::createFromUtf8(rt, result);
664
674
  });
665
675
 
676
+ auto is_sqlcipher = HOSTFN("isSQLCipher", 0) {
677
+ #ifdef OP_SQLITE_USE_SQLCIPHER
678
+ return true;
679
+ #else
680
+ return false;
681
+ #endif
682
+ });
683
+
666
684
  jsi::Object module = jsi::Object(rt);
667
685
 
668
686
  module.setProperty(rt, "open", std::move(open));
@@ -682,6 +700,7 @@ void install(jsi::Runtime &rt,
682
700
  module.setProperty(rt, "loadExtension", std::move(load_extension));
683
701
  module.setProperty(rt, "executeRawAsync", std::move(execute_raw_async));
684
702
  module.setProperty(rt, "getDbPath", std::move(get_db_path));
703
+ module.setProperty(rt, "isSQLCipher", std::move(is_sqlcipher));
685
704
 
686
705
  rt.global().setProperty(rt, "__OPSQLiteProxy", std::move(module));
687
706
  }
package/cpp/bridge.cpp CHANGED
@@ -204,7 +204,7 @@ inline void opsqlite_bind_statement(sqlite3_stmt *statement,
204
204
  } else if (std::holds_alternative<ArrayBuffer>(value)) {
205
205
  ArrayBuffer buffer = std::get<ArrayBuffer>(value);
206
206
  sqlite3_bind_blob(statement, sqIndex, buffer.data.get(), buffer.size,
207
- SQLITE_STATIC);
207
+ SQLITE_TRANSIENT);
208
208
  } else {
209
209
  sqlite3_bind_null(statement, sqIndex);
210
210
  }