diff --git a/cpp/bindings.cpp b/cpp/bindings.cpp index f75d285..1c15f1a 100644 --- a/cpp/bindings.cpp +++ b/cpp/bindings.cpp @@ -90,7 +90,7 @@ void install(jsi::Runtime &rt, return false; #endif }); - + auto is_ios_embedded = HOST_STATIC_FN("isIOSEmbedded") { #ifdef OP_SQLITE_USE_PHONE_VERSION return true; diff --git a/cpp/bridge.cpp b/cpp/bridge.cpp index 2eaf98c..cc52f97 100644 --- a/cpp/bridge.cpp +++ b/cpp/bridge.cpp @@ -67,14 +67,15 @@ std::string opsqlite_get_db_path(std::string const &db_name, if (location == ":memory:") { return location; } - char resolved_location[PATH_MAX]; - realpath(location.c_str(), resolved_location); - std::string resolved_location_string = std::string(resolved_location); // Will return false if the directory already exists, no need to check - std::filesystem::create_directories(resolved_location); + std::filesystem::create_directories(location); - return resolved_location_string + "/" + db_name; + if (!location.empty() && location.back() != '/') { + return location + "/" + db_name; + } + + return location + db_name; } #ifdef OP_SQLITE_USE_SQLCIPHER diff --git a/cpp/libsql/bridge.cpp b/cpp/libsql/bridge.cpp index cbbb233..213ecd1 100644 --- a/cpp/libsql/bridge.cpp +++ b/cpp/libsql/bridge.cpp @@ -26,14 +26,14 @@ std::string opsqlite_get_db_path(std::string const &db_name, return location; } - char resolved_location[PATH_MAX]; - realpath(location.c_str(), resolved_location); - std::string resolved_location_string = std::string(resolved_location); - // Will return false if the directory already exists, no need to check - std::filesystem::create_directories(resolved_location); + std::filesystem::create_directories(location); + + if (!location.empty() && location.back() != '/') { + return location + "/" + db_name; + } - return resolved_location_string + "/" + db_name; + return location + db_name; } DB opsqlite_libsql_open_sync(std::string const &name, diff --git a/example/src/tests/dbsetup.spec.ts b/example/src/tests/dbsetup.spec.ts index c4ad1b8..734b838 100644 --- a/example/src/tests/dbsetup.spec.ts +++ b/example/src/tests/dbsetup.spec.ts @@ -122,6 +122,16 @@ export function dbSetupTests() { db.delete(); }); + it('Should create db in custom folder', async () => { + let db = open({ + name: 'customFolderTest.sqlite', + encryptionKey: 'test', + location: 'myFolder', + }); + + db.delete(); + }); + it('Moves assets database simple', async () => { const copied = await moveAssetsDatabase({filename: 'sample.sqlite'});