diff --git a/modules/database/database.h b/modules/database/database.h index a3cc47cd6..d450a873e 100644 --- a/modules/database/database.h +++ b/modules/database/database.h @@ -1,7 +1,7 @@ #ifndef DATABASE_H #define DATABASE_H -#include "core/string.h" +#include "core/ustring.h" #include #include "core/reference.h" @@ -12,19 +12,6 @@ class QueryResult; class Database { public: - //probably needs refcount, depending on what db engines do, todo - //virtual QueryResult *query(const String &sql); - //virtual QueryResult *query_async(const String &sql); - //or - //virtual QueryErrorCode query(QueryResult *result, const String &sql); - //virtual QueryErrorCode query_async(QueryResult *result, const String &sql); - - //also - //virtual QueryResult *query_prepared(const String &sql, param1, param2, ...); - - //query interface (codeigniter 3 style) - //virtual void where(""); etc - virtual void connect(const String &connection_str); virtual Ref query(const String &query); virtual void query_run(const String &query); @@ -37,9 +24,6 @@ public: Database(); ~Database(); - -private: - //std::vector _builders; }; -#endif \ No newline at end of file +#endif diff --git a/modules/database/database_manager.cpp b/modules/database/database_manager.cpp index 2e04459c7..a035d060f 100644 --- a/modules/database/database_manager.cpp +++ b/modules/database/database_manager.cpp @@ -2,68 +2,21 @@ void DatabaseManager::load() { //go thourgh settings, and create all the defined db backends + //add them to ProjectSettings } -uint32_t DatabaseManager::create_database(const String &name) { - Database *db = _create_database(name); - - if (!db) { - RLOG_MSG("(DatabaseManager) create_database: " + name + ", returned db is null!"); - return -1; - } - - RLOG_MSG("(DatabaseManager) Database " + name + " successfully created!"); - - databases.push_back(db); - - if (ddb == nullptr) { - RLOG_MSG("(DatabaseManager) Database " + name + " has been set as the default database!"); - ddb = db; - } - - return databases.size() - 1; -} DatabaseManager *DatabaseManager::get_singleton() { return _instance; } -void DatabaseManager::_register_db_creation_func(const String &name, std::function func) { - ERR_FAIL_COND_MSG(!func, "_register_db_creation_func: " + name + ", func is wrong!"); - - _db_creation_func_map[name] = func; -} - -void DatabaseManager::_unregister_db_creation_func(const String &name) { - _db_creation_func_map.erase(name); -} - -Database *DatabaseManager::_create_database(const String &name) { - std::function func = _db_creation_func_map[name]; - - ERR_FAIL_COND_V_MSG(!func, nullptr, "_create_database: " + name + ", func is wrong!"); - - Database *db = func(); - - ERR_FAIL_COND_V_MSG(!db, nullptr, "_create_database: " + name + ", returned db is null!"); - - return db; -} - DatabaseManager::DatabaseManager() { _instance = this; - - ddb = nullptr; } DatabaseManager::~DatabaseManager() { _instance = nullptr; - - for (uint32_t i = 0; i < databases.size(); ++i) { - delete databases[i]; - } } DatabaseManager *DatabaseManager::_instance = nullptr; -std::map > DatabaseManager::_db_creation_func_map; \ No newline at end of file diff --git a/modules/database/database_manager.h b/modules/database/database_manager.h index 65d99f4ac..eedba6db9 100644 --- a/modules/database/database_manager.h +++ b/modules/database/database_manager.h @@ -1,42 +1,33 @@ #ifndef DATABASE_MANAGER_H #define DATABASE_MANAGER_H -#include "core/string.h" - -#include -#include -#include +#include "core/reference.h" +#include "core/ustring.h" #include "core/object.h" -#include "database.h" +class Database; class DatabaseManager : public Object { - RCPP_OBJECT(DatabaseManager, Object); + GDCLASS(DatabaseManager, Object); public: - std::vector databases; - Database *ddb; + Ref get_ddb(); + void set_ddb(const Ref &db); - void load(); + void load(); - static DatabaseManager *get_singleton(); + static DatabaseManager *get_singleton(); - //note: not threadsafe, create these at the start of your program! - uint32_t create_database(const String &name); + DatabaseManager(); + ~DatabaseManager(); - static void _register_db_creation_func(const String &name, std::function func); - static void _unregister_db_creation_func(const String &name); - - static Database *_create_database(const String &name); - - DatabaseManager(); - ~DatabaseManager(); +protected: + Vector> _databases; + Ref _ddb; private: - static DatabaseManager * _instance; - - static std::map > _db_creation_func_map; + static DatabaseManager *_instance; }; -#endif \ No newline at end of file +#endif