mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-23 04:16:50 +01:00
More cleanups.
This commit is contained in:
parent
134d94af5f
commit
d5f5e9fec9
@ -1,7 +1,7 @@
|
|||||||
#ifndef DATABASE_H
|
#ifndef DATABASE_H
|
||||||
#define DATABASE_H
|
#define DATABASE_H
|
||||||
|
|
||||||
#include "core/string.h"
|
#include "core/ustring.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "core/reference.h"
|
#include "core/reference.h"
|
||||||
@ -12,19 +12,6 @@ class QueryResult;
|
|||||||
|
|
||||||
class Database {
|
class Database {
|
||||||
public:
|
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 void connect(const String &connection_str);
|
||||||
virtual Ref<QueryResult> query(const String &query);
|
virtual Ref<QueryResult> query(const String &query);
|
||||||
virtual void query_run(const String &query);
|
virtual void query_run(const String &query);
|
||||||
@ -37,9 +24,6 @@ public:
|
|||||||
|
|
||||||
Database();
|
Database();
|
||||||
~Database();
|
~Database();
|
||||||
|
|
||||||
private:
|
|
||||||
//std::vector<QueryBuilder *> _builders;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,68 +2,21 @@
|
|||||||
|
|
||||||
void DatabaseManager::load() {
|
void DatabaseManager::load() {
|
||||||
//go thourgh settings, and create all the defined db backends
|
//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() {
|
DatabaseManager *DatabaseManager::get_singleton() {
|
||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseManager::_register_db_creation_func(const String &name, std::function<Database *()> 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<Database *()> 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() {
|
DatabaseManager::DatabaseManager() {
|
||||||
_instance = this;
|
_instance = this;
|
||||||
|
|
||||||
ddb = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseManager::~DatabaseManager() {
|
DatabaseManager::~DatabaseManager() {
|
||||||
_instance = nullptr;
|
_instance = nullptr;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < databases.size(); ++i) {
|
|
||||||
delete databases[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseManager *DatabaseManager::_instance = nullptr;
|
DatabaseManager *DatabaseManager::_instance = nullptr;
|
||||||
|
|
||||||
std::map<String, std::function<Database *()> > DatabaseManager::_db_creation_func_map;
|
|
@ -1,42 +1,33 @@
|
|||||||
#ifndef DATABASE_MANAGER_H
|
#ifndef DATABASE_MANAGER_H
|
||||||
#define DATABASE_MANAGER_H
|
#define DATABASE_MANAGER_H
|
||||||
|
|
||||||
#include "core/string.h"
|
#include "core/reference.h"
|
||||||
|
#include "core/ustring.h"
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
#include "core/object.h"
|
#include "core/object.h"
|
||||||
|
|
||||||
#include "database.h"
|
class Database;
|
||||||
|
|
||||||
class DatabaseManager : public Object {
|
class DatabaseManager : public Object {
|
||||||
RCPP_OBJECT(DatabaseManager, Object);
|
GDCLASS(DatabaseManager, Object);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<Database *> databases;
|
Ref<Database> get_ddb();
|
||||||
Database *ddb;
|
void set_ddb(const Ref<Database> &db);
|
||||||
|
|
||||||
void load();
|
void load();
|
||||||
|
|
||||||
static DatabaseManager *get_singleton();
|
static DatabaseManager *get_singleton();
|
||||||
|
|
||||||
//note: not threadsafe, create these at the start of your program!
|
DatabaseManager();
|
||||||
uint32_t create_database(const String &name);
|
~DatabaseManager();
|
||||||
|
|
||||||
static void _register_db_creation_func(const String &name, std::function<Database*()> func);
|
protected:
|
||||||
static void _unregister_db_creation_func(const String &name);
|
Vector<Ref<Database>> _databases;
|
||||||
|
Ref<Database> _ddb;
|
||||||
static Database *_create_database(const String &name);
|
|
||||||
|
|
||||||
DatabaseManager();
|
|
||||||
~DatabaseManager();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static DatabaseManager * _instance;
|
static DatabaseManager *_instance;
|
||||||
|
|
||||||
static std::map<String, std::function<Database *()> > _db_creation_func_map;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user