Skip to content

Commit

Permalink
Merge pull request #228 from OP-Engineering/oscar/fix-location-in-and…
Browse files Browse the repository at this point in the history
…roid
  • Loading branch information
ospfranco authored Jan 22, 2025
2 parents caf91de + e471c19 commit b78875a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions cpp/bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions cpp/libsql/bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions example/src/tests/dbsetup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'});

Expand Down

0 comments on commit b78875a

Please sign in to comment.