diff --git a/cpp/DBHostObject.cpp b/cpp/DBHostObject.cpp index cca07d04..1f51ab3a 100644 --- a/cpp/DBHostObject.cpp +++ b/cpp/DBHostObject.cpp @@ -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) { diff --git a/cpp/libsql/bridge.cpp b/cpp/libsql/bridge.cpp index 5cd79841..15f0984b 100644 --- a/cpp/libsql/bridge.cpp +++ b/cpp/libsql/bridge.cpp @@ -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) { diff --git a/cpp/libsql/bridge.h b/cpp/libsql/bridge.h index 2236562e..be354bb5 100644 --- a/cpp/libsql/bridge.h +++ b/cpp/libsql/bridge.h @@ -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 *params, std::vector *results,