From c950144206a4adebfcd856c8d8319f119abafa67 Mon Sep 17 00:00:00 2001 From: Oscar Franco Date: Sun, 15 Dec 2024 13:49:38 +0100 Subject: [PATCH] Simplify detach --- cpp/DBHostObject.cpp | 8 ++------ cpp/bridge.cpp | 12 +++--------- cpp/bridge.h | 2 +- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/cpp/DBHostObject.cpp b/cpp/DBHostObject.cpp index 9e1d3d9..18a552d 100644 --- a/cpp/DBHostObject.cpp +++ b/cpp/DBHostObject.cpp @@ -241,15 +241,11 @@ void DBHostObject::create_jsi_functions() { std::string dbName = args[0].asString(rt).utf8(rt); std::string alias = args[1].asString(rt).utf8(rt); #ifdef OP_SQLITE_USE_LIBSQL - BridgeResult result = opsqlite_libsql_detach(dbName, alias); + opsqlite_libsql_detach(dbName, alias); #else - BridgeResult result = opsqlite_detach(db, dbName, alias); + opsqlite_detach(db, dbName, alias); #endif - if (result.type == SQLiteError) { - throw jsi::JSError(rt, result.message.c_str()); - } - return {}; }); diff --git a/cpp/bridge.cpp b/cpp/bridge.cpp index e3ee672..4eb1919 100644 --- a/cpp/bridge.cpp +++ b/cpp/bridge.cpp @@ -149,20 +149,14 @@ void opsqlite_attach(sqlite3 *db, std::string const &main_db_name, } } -BridgeResult opsqlite_detach(sqlite3 *db, std::string const &mainDBName, +void opsqlite_detach(sqlite3 *db, std::string const &main_db_name, std::string const &alias) { std::string statement = "DETACH DATABASE " + alias; BridgeResult result = opsqlite_execute(db, statement, nullptr); if (result.type == SQLiteError) { - return BridgeResult{ - .type = SQLiteError, - .message = mainDBName + "was unable to detach database: " + - std::string(result.message), - }; + throw std::runtime_error(main_db_name + "was unable to detach database: " + + std::string(result.message)); } - return BridgeResult{ - .type = SQLiteOk, - }; } void opsqlite_remove(sqlite3 *db, std::string const &name, diff --git a/cpp/bridge.h b/cpp/bridge.h index e7cec22..e08da34 100644 --- a/cpp/bridge.h +++ b/cpp/bridge.h @@ -43,7 +43,7 @@ void opsqlite_attach(sqlite3 *db, std::string const &main_db_name, std::string const &secondary_db_name, std::string const &alias); -BridgeResult opsqlite_detach(sqlite3 *db, std::string const &mainDBName, +void opsqlite_detach(sqlite3 *db, std::string const &main_db_name, std::string const &alias); BridgeResult opsqlite_execute(sqlite3 *db, std::string const &query,