Skip to content

Commit

Permalink
Stubs for exposing sync call for remote sync db
Browse files Browse the repository at this point in the history
  • Loading branch information
ospfranco committed Jul 14, 2024
1 parent ce883d1 commit b842314
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cpp/DBHostObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,16 @@ void DBHostObject::create_jsi_functions() {
return promise;
});

#ifdef OP_SQLITE_USE_LIBSQL
auto sync = HOSTFN("sync", 0) {
BridgeResult result = opsqlite_libsql_sync(db_name);
if (result.type == SQLiteError) {
throw std::runtime_error(result.message);
}
return {};
});
#endif

#ifndef OP_SQLITE_USE_LIBSQL
auto load_file = HOSTFN("loadFile", 1) {
if (sizeof(args) < 1) {
Expand Down
15 changes: 15 additions & 0 deletions cpp/libsql/bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,21 @@ BridgeResult opsqlite_libsql_detach(std::string const &mainDBName,
};
}

BridgeResult opsqlite_libsql_sync(std::string const &name) {
check_db_open(name);

libsql_connection_t c = db_map[name].c;
const char *err = NULL;

int status = libsql_sync(c, &err);

if (status != 0) {
return {.type = SQLiteError, .message = err};
}

return {.type = SQLiteOk};
}

BridgeResult opsqlite_libsql_remove(std::string const &name,
std::string const &path) {
if (db_map.count(name) == 1) {
Expand Down
2 changes: 2 additions & 0 deletions cpp/libsql/bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ BridgeResult opsqlite_libsql_attach(std::string const &mainDBName,
BridgeResult opsqlite_libsql_detach(std::string const &mainDBName,
std::string const &alias);

BridgeResult opsqlite_libsql_sync(std::string const &name);

BridgeResult opsqlite_libsql_execute(
std::string const &name, std::string const &query,
const std::vector<JSVariant> *params, std::vector<DumbHostObject> *results,
Expand Down

0 comments on commit b842314

Please sign in to comment.