|
| 1 | +diff --git a/android/build.gradle b/android/build.gradle |
| 2 | +index d36fd855813e87b17da43156be64782b325b2733..751355645c0b6e28e2df01e9bdc32f545d8dc83c 100644 |
| 3 | +--- a/android/build.gradle |
| 4 | ++++ b/android/build.gradle |
| 5 | +@@ -1,5 +1,4 @@ |
| 6 | + import java.nio.file.Paths |
| 7 | +-import groovy.json.JsonSlurper |
| 8 | + |
| 9 | + buildscript { |
| 10 | + ext.getExtOrDefault = {name -> |
| 11 | +@@ -27,57 +26,16 @@ def getExtOrIntegerDefault(name) { |
| 12 | + return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["OPSQLite_" + name]).toInteger() |
| 13 | + } |
| 14 | + |
| 15 | +-def useSQLCipher = false |
| 16 | ++def useSQLCipher = true |
| 17 | + def useLibsql = false |
| 18 | + def useCRSQLite = false |
| 19 | +-def performanceMode = false |
| 20 | ++def performanceMode = true |
| 21 | + def sqliteFlags = "" |
| 22 | + def enableFTS5 = false |
| 23 | + def useSqliteVec = false |
| 24 | + def enableRtree = false |
| 25 | + def tokenizers = [] |
| 26 | + |
| 27 | +-// On the example app, the package.json is located at the root of the project |
| 28 | +-// On the user app, the package.json is located at the root of the node_modules directory |
| 29 | +-def isUserApp = rootDir.absolutePath.contains("node_modules") |
| 30 | +-def packageJsonFile |
| 31 | +- |
| 32 | +-if (isUserApp) { |
| 33 | +- // Start from the root + 1 level up (to avoid detecting the op-sqlite/package.json) and traverse upwards to find the first package.json |
| 34 | +- File currentDir = new File("$rootDir/../") |
| 35 | +- packageJsonFile = null |
| 36 | +- |
| 37 | +- // Try to find package.json by traversing upwards |
| 38 | +- while (currentDir != null) { |
| 39 | +- File potential = new File(currentDir, "package.json") |
| 40 | +- if (potential.exists()) { |
| 41 | +- packageJsonFile = potential |
| 42 | +- break |
| 43 | +- } |
| 44 | +- currentDir = currentDir.parentFile |
| 45 | +- } |
| 46 | +-} else { |
| 47 | +- packageJsonFile = new File("$rootDir/../package.json") |
| 48 | +-} |
| 49 | +- |
| 50 | +- |
| 51 | +-def packageJson = new JsonSlurper().parseText(packageJsonFile.text) |
| 52 | +- |
| 53 | +-def opsqliteConfig = packageJson["op-sqlite"] |
| 54 | +- |
| 55 | +-if(opsqliteConfig) { |
| 56 | +- println "[OP-SQLITE] Detected op-sqlite config from package.json at: " + packageJsonFile.absolutePath |
| 57 | +- useSQLCipher = opsqliteConfig["sqlcipher"] |
| 58 | +- useCRSQLite = opsqliteConfig["crsqlite"] |
| 59 | +- useSqliteVec = opsqliteConfig["sqliteVec"] |
| 60 | +- performanceMode = opsqliteConfig["performanceMode"] |
| 61 | +- sqliteFlags = opsqliteConfig["sqliteFlags"] ? opsqliteConfig["sqliteFlags"] : "" |
| 62 | +- enableFTS5 = opsqliteConfig["fts5"] |
| 63 | +- useLibsql = opsqliteConfig["libsql"] |
| 64 | +- enableRtree = opsqliteConfig["rtree"] |
| 65 | +- tokenizers = opsqliteConfig["tokenizers"] ? opsqliteConfig["tokenizers"] : [] |
| 66 | +-} |
| 67 | +- |
| 68 | + if(useSQLCipher) { |
| 69 | + println "[OP-SQLITE] using sqlcipher." |
| 70 | + } else if(useLibsql) { |
| 71 | +diff --git a/android/cpp-adapter.cpp b/android/cpp-adapter.cpp |
| 72 | +index 8feaf7719661ef248113f11b1643deedb4b510af..2393963bf982f80ccff2ed396f1538be7ee18fcb 100644 |
| 73 | +--- a/android/cpp-adapter.cpp |
| 74 | ++++ b/android/cpp-adapter.cpp |
| 75 | +@@ -19,8 +19,8 @@ struct OPSQLiteBridge : jni::JavaClass<OPSQLiteBridge> { |
| 76 | + static void registerNatives() { |
| 77 | + javaClassStatic()->registerNatives( |
| 78 | + {makeNativeMethod("installNativeJsi", OPSQLiteBridge::installNativeJsi), |
| 79 | +- makeNativeMethod("clearStateNativeJsi", |
| 80 | +- OPSQLiteBridge::clearStateNativeJsi)}); |
| 81 | ++ makeNativeMethod("clearStateNativeJsi", OPSQLiteBridge::clearStateNativeJsi), |
| 82 | ++ makeNativeMethod("deleteAllDBsJsi", OPSQLiteBridge::deleteAllDBsJsi)}); |
| 83 | + } |
| 84 | + |
| 85 | + private: |
| 86 | +@@ -39,6 +39,10 @@ private: |
| 87 | + static void clearStateNativeJsi(jni::alias_ref<jni::JObject> thiz) { |
| 88 | + opsqlite::invalidate(); |
| 89 | + } |
| 90 | ++ |
| 91 | ++ static bool deleteAllDBsJsi(jni::alias_ref<jni::JObject> thiz) { |
| 92 | ++ return opsqlite::deleteAllDbs(); |
| 93 | ++ } |
| 94 | + }; |
| 95 | + |
| 96 | + JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *) { |
| 97 | +diff --git a/android/src/main/java/com/op/sqlite/OPSQLiteBridge.kt b/android/src/main/java/com/op/sqlite/OPSQLiteBridge.kt |
| 98 | +index 44f86df6a21a6f7272b2c79b196586ef8fec886b..9d9f7100fd34361701b2addf09a4f36e33b35d56 100644 |
| 99 | +--- a/android/src/main/java/com/op/sqlite/OPSQLiteBridge.kt |
| 100 | ++++ b/android/src/main/java/com/op/sqlite/OPSQLiteBridge.kt |
| 101 | +@@ -12,6 +12,7 @@ class OPSQLiteBridge { |
| 102 | + docPath: String |
| 103 | + ) |
| 104 | + private external fun clearStateNativeJsi() |
| 105 | ++ private external fun deleteAllDBsJsi(): Boolean |
| 106 | + |
| 107 | + fun install(context: ReactContext) { |
| 108 | + val jsContextPointer = context.javaScriptContextHolder!!.get() |
| 109 | +@@ -31,6 +32,10 @@ class OPSQLiteBridge { |
| 110 | + clearStateNativeJsi() |
| 111 | + } |
| 112 | + |
| 113 | ++ fun deleteAllDBs() { |
| 114 | ++ deleteAllDBsJsi() |
| 115 | ++ } |
| 116 | ++ |
| 117 | + companion object { |
| 118 | + val instance = OPSQLiteBridge() |
| 119 | + } |
| 120 | +diff --git a/android/src/main/java/com/op/sqlite/OPSQLiteModule.kt b/android/src/main/java/com/op/sqlite/OPSQLiteModule.kt |
| 121 | +index 688832fa2f9a7f91d16cd50495caa8c9f8873864..9ea814bfa63f27356e804b82e941b7121152db3a 100644 |
| 122 | +--- a/android/src/main/java/com/op/sqlite/OPSQLiteModule.kt |
| 123 | ++++ b/android/src/main/java/com/op/sqlite/OPSQLiteModule.kt |
| 124 | +@@ -13,7 +13,7 @@ import java.io.OutputStream |
| 125 | + import com.facebook.react.util.RNLog; |
| 126 | + |
| 127 | + //@ReactModule(name = OPSQLiteModule.NAME) |
| 128 | +-internal class OPSQLiteModule(context: ReactApplicationContext?) : ReactContextBaseJavaModule(context) { |
| 129 | ++class OPSQLiteModule(context: ReactApplicationContext?) : ReactContextBaseJavaModule(context) { |
| 130 | + override fun getName(): String { |
| 131 | + return NAME |
| 132 | + } |
| 133 | +@@ -56,6 +56,17 @@ internal class OPSQLiteModule(context: ReactApplicationContext?) : ReactContextB |
| 134 | + return true |
| 135 | + } |
| 136 | + |
| 137 | ++ @ReactMethod(isBlockingSynchronousMethod = true) |
| 138 | ++ fun closeAllConnections() { |
| 139 | ++ OPSQLiteBridge.instance.invalidate() |
| 140 | ++ } |
| 141 | ++ |
| 142 | ++ @ReactMethod(isBlockingSynchronousMethod = true) |
| 143 | ++ fun deleteAllDBs() { |
| 144 | ++ OPSQLiteBridge.instance.deleteAllDBs(); |
| 145 | ++ } |
| 146 | ++ |
| 147 | ++ |
| 148 | + @ReactMethod |
| 149 | + fun moveAssetsDatabase(args: ReadableMap, promise: Promise) { |
| 150 | + val filename = args.getString("filename")!! |
| 151 | +diff --git a/cpp/DBHostObject.cpp b/cpp/DBHostObject.cpp |
| 152 | +index 85710eea286d45685aa526ed3851e8f1e1411039..8cf10f21ba467dea430aab106d43dd4e2adeacd6 100644 |
| 153 | +--- a/cpp/DBHostObject.cpp |
| 154 | ++++ b/cpp/DBHostObject.cpp |
| 155 | +@@ -889,6 +889,10 @@ void DBHostObject::invalidate() { |
| 156 | + #endif |
| 157 | + } |
| 158 | + |
| 159 | ++void DBHostObject::drop() { |
| 160 | ++ opsqlite_remove(db, db_name, std::string(base_path)); |
| 161 | ++} |
| 162 | ++ |
| 163 | + DBHostObject::~DBHostObject() { invalidate(); } |
| 164 | + |
| 165 | + } // namespace opsqlite |
| 166 | +diff --git a/cpp/DBHostObject.h b/cpp/DBHostObject.h |
| 167 | +index cc174b7c8c5ce500a6ffe5dc6fe092d282d2554c..ff36f742a22b8a84f37d6dd28441dbe9d0c6c873 100644 |
| 168 | +--- a/cpp/DBHostObject.h |
| 169 | ++++ b/cpp/DBHostObject.h |
| 170 | +@@ -73,6 +73,7 @@ class JSI_EXPORT DBHostObject : public jsi::HostObject { |
| 171 | + void on_commit(); |
| 172 | + void on_rollback(); |
| 173 | + void invalidate(); |
| 174 | ++ void drop(); |
| 175 | + ~DBHostObject() override; |
| 176 | + |
| 177 | + private: |
| 178 | +diff --git a/cpp/bindings.cpp b/cpp/bindings.cpp |
| 179 | +index 5e1c1de234e7bdb131769728fc862d389f9995a5..dc21c6503ffe18f3ae1cf99f327e8aa1fc587b71 100644 |
| 180 | +--- a/cpp/bindings.cpp |
| 181 | ++++ b/cpp/bindings.cpp |
| 182 | +@@ -36,6 +36,13 @@ void invalidate() { |
| 183 | + dbs.clear(); |
| 184 | + } |
| 185 | + |
| 186 | ++bool deleteAllDbs() { |
| 187 | ++ for(const auto &db : dbs) { |
| 188 | ++ db->drop(); |
| 189 | ++ } |
| 190 | ++ return true; |
| 191 | ++} |
| 192 | ++ |
| 193 | + void install(jsi::Runtime &rt, |
| 194 | + const std::shared_ptr<react::CallInvoker> &invoker, |
| 195 | + const char *base_path, const char *crsqlite_path, |
| 196 | +diff --git a/op-sqlite.podspec b/op-sqlite.podspec |
| 197 | +index 375cc3ef0838a3cffb87ec970f636880a8676bb3..e6fce21630ed00aa863f2baae7b3d04de783dcb0 100644 |
| 198 | +--- a/op-sqlite.podspec |
| 199 | ++++ b/op-sqlite.podspec |
| 200 | +@@ -1,4 +1,3 @@ |
| 201 | +-require "json" |
| 202 | + require_relative "./generate_tokenizers_header_file" |
| 203 | + |
| 204 | + log_message = lambda do |message| |
| 205 | +@@ -39,11 +38,10 @@ else |
| 206 | + app_package = JSON.parse(File.read(File.join(__dir__, "example", "package.json"))) |
| 207 | + end |
| 208 | + |
| 209 | +-op_sqlite_config = app_package["op-sqlite"] |
| 210 | +-use_sqlcipher = false |
| 211 | ++use_sqlcipher = true |
| 212 | + use_crsqlite = false |
| 213 | + use_libsql = false |
| 214 | +-performance_mode = false |
| 215 | ++performance_mode = true |
| 216 | + phone_version = false |
| 217 | + sqlite_flags = "" |
| 218 | + fts5 = false |
| 219 | +@@ -51,37 +49,6 @@ rtree = false |
| 220 | + use_sqlite_vec = false |
| 221 | + tokenizers = [] |
| 222 | + |
| 223 | +-if(op_sqlite_config != nil) |
| 224 | +- use_sqlcipher = op_sqlite_config["sqlcipher"] == true |
| 225 | +- use_crsqlite = op_sqlite_config["crsqlite"] == true |
| 226 | +- use_libsql = op_sqlite_config["libsql"] == true |
| 227 | +- performance_mode = op_sqlite_config["performanceMode"] || false |
| 228 | +- phone_version = op_sqlite_config["iosSqlite"] == true |
| 229 | +- sqlite_flags = op_sqlite_config["sqliteFlags"] || "" |
| 230 | +- fts5 = op_sqlite_config["fts5"] == true |
| 231 | +- rtree = op_sqlite_config["rtree"] == true |
| 232 | +- use_sqlite_vec = op_sqlite_config["sqliteVec"] == true |
| 233 | +- tokenizers = op_sqlite_config["tokenizers"] || [] |
| 234 | +-end |
| 235 | +- |
| 236 | +-if phone_version then |
| 237 | +- if use_sqlcipher then |
| 238 | +- raise "SQLCipher is not supported with phone version" |
| 239 | +- end |
| 240 | +- |
| 241 | +- if use_crsqlite then |
| 242 | +- raise "CRSQLite is not supported with phone version" |
| 243 | +- end |
| 244 | +- |
| 245 | +- if rtree then |
| 246 | +- raise "RTree is not supported with phone version" |
| 247 | +- end |
| 248 | +- |
| 249 | +- if use_sqlite_vec then |
| 250 | +- raise "SQLite Vec is not supported with phone version" |
| 251 | +- end |
| 252 | +-end |
| 253 | +- |
| 254 | + Pod::Spec.new do |s| |
| 255 | + s.name = "op-sqlite" |
| 256 | + s.version = package["version"] |
0 commit comments