mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-09 12:29:35 +01:00
Re-enabled database support for WebNodes.
This commit is contained in:
parent
25e0c1097a
commit
afef61dabf
@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
|
||||||
|
Ref<Database> DatabaseManager::get_ddb() {
|
||||||
|
return _ddb;
|
||||||
|
}
|
||||||
|
void DatabaseManager::set_ddb(const Ref<Database> &db) {
|
||||||
|
_ddb = db;
|
||||||
|
}
|
||||||
|
|
||||||
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
|
//add them to ProjectSettings
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "core/object.h"
|
#include "core/object.h"
|
||||||
#include "core/print_string.h"
|
#include "core/print_string.h"
|
||||||
#include "http_server_enums.h"
|
#include "http_server_enums.h"
|
||||||
|
#include "modules/database/database_connection.h"
|
||||||
#include "web_server_request.h"
|
#include "web_server_request.h"
|
||||||
|
|
||||||
#if WEB_SETTINGS_ENABLED
|
#if WEB_SETTINGS_ENABLED
|
||||||
@ -15,12 +16,12 @@
|
|||||||
#include "web_permission.h"
|
#include "web_permission.h"
|
||||||
#include "web_server.h"
|
#include "web_server.h"
|
||||||
|
|
||||||
#ifdef DATABASES_ENABLED
|
#ifdef MODULE_DATABASE_ENABLED
|
||||||
#include "database/database.h"
|
#include "../../database/database.h"
|
||||||
#include "database/database_manager.h"
|
#include "../../database/database_manager.h"
|
||||||
#include "database/query_builder.h"
|
#include "../../database/query_builder.h"
|
||||||
#include "database/query_result.h"
|
#include "../../database/query_result.h"
|
||||||
#include "database/table_builder.h"
|
#include "../../database/table_builder.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
String WebNode::get_uri_segment() {
|
String WebNode::get_uri_segment() {
|
||||||
@ -105,38 +106,46 @@ void WebNode::set_routing_enabled(const bool value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DATABASES_ENABLED
|
#ifdef MODULE_DATABASE_ENABLED
|
||||||
|
|
||||||
Database *WebNode::get_database() {
|
Ref<Database> WebNode::get_database() {
|
||||||
if (_database) {
|
if (_database.is_valid()) {
|
||||||
return _database;
|
return _database;
|
||||||
}
|
}
|
||||||
|
|
||||||
return DatabaseManager::get_singleton()->ddb;
|
return DatabaseManager::get_singleton()->get_ddb();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<TableBuilder> WebNode::get_table_builder() {
|
void WebNode::set_database(const Ref<Database> &db) {
|
||||||
Database *db = get_database();
|
|
||||||
|
|
||||||
ERR_FAIL_COND_V(!db, Ref<TableBuilder>());
|
|
||||||
|
|
||||||
return db->get_table_builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref<QueryBuilder> WebNode::get_query_builder() {
|
|
||||||
Database *db = get_database();
|
|
||||||
|
|
||||||
ERR_FAIL_COND_V(!db, Ref<QueryBuilder>());
|
|
||||||
|
|
||||||
return db->get_query_builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebNode::set_database(Database *db) {
|
|
||||||
_database = db;
|
_database = db;
|
||||||
|
|
||||||
// todo send event to children when it's implemented?
|
// todo send event to children when it's implemented?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ref<TableBuilder> WebNode::get_table_builder() {
|
||||||
|
Ref<Database> db = get_database();
|
||||||
|
|
||||||
|
ERR_FAIL_COND_V(!db.is_valid(), Ref<TableBuilder>());
|
||||||
|
|
||||||
|
Ref<DatabaseConnection> conn = db->get_connection();
|
||||||
|
|
||||||
|
ERR_FAIL_COND_V(!conn.is_valid(), Ref<TableBuilder>());
|
||||||
|
|
||||||
|
return conn->get_table_builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<QueryBuilder> WebNode::get_query_builder() {
|
||||||
|
Ref<Database> db = get_database();
|
||||||
|
|
||||||
|
ERR_FAIL_COND_V(!db.is_valid(), Ref<QueryBuilder>());
|
||||||
|
|
||||||
|
Ref<DatabaseConnection> conn = db->get_connection();
|
||||||
|
|
||||||
|
ERR_FAIL_COND_V(!conn.is_valid(), Ref<QueryBuilder>());
|
||||||
|
|
||||||
|
return conn->get_query_builder();
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void WebNode::handle_request_main(Ref<WebServerRequest> request) {
|
void WebNode::handle_request_main(Ref<WebServerRequest> request) {
|
||||||
@ -403,9 +412,9 @@ void WebNode::_notification(const int what) {
|
|||||||
WebNode::WebNode() {
|
WebNode::WebNode() {
|
||||||
// should look this up in parents when parented (and node parenting is implemented)
|
// should look this up in parents when parented (and node parenting is implemented)
|
||||||
// should have an event later when a parent gets one
|
// should have an event later when a parent gets one
|
||||||
#ifdef DATABASES_ENABLED
|
//#ifdef MODULE_DATABASE_ENABLED
|
||||||
_database = nullptr;
|
//_database = nullptr;
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
#if WEB_SETTINGS_ENABLED
|
#if WEB_SETTINGS_ENABLED
|
||||||
// same for this
|
// same for this
|
||||||
@ -440,12 +449,14 @@ void WebNode::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("set_routing_enabled", "val"), &WebNode::set_routing_enabled);
|
ClassDB::bind_method(D_METHOD("set_routing_enabled", "val"), &WebNode::set_routing_enabled);
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "routing_enabled"), "set_routing_enabled", "get_routing_enabled");
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "routing_enabled"), "set_routing_enabled", "get_routing_enabled");
|
||||||
|
|
||||||
//#ifdef DATABASES_ENABLED
|
#ifdef MODULE_DATABASE_ENABLED
|
||||||
// Database *get_database();
|
ClassDB::bind_method(D_METHOD("get_database"), &WebNode::get_database);
|
||||||
// Ref<TableBuilder> get_table_builder();
|
ClassDB::bind_method(D_METHOD("set_database", "val"), &WebNode::set_database);
|
||||||
// Ref<QueryBuilder> get_query_builder();
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "database", PROPERTY_HINT_RESOURCE_TYPE, "Database", 0), "set_database", "get_database");
|
||||||
// void set_database(Database * db);
|
|
||||||
//#endif
|
ClassDB::bind_method(D_METHOD("get_table_builder"), &WebNode::get_table_builder);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_query_builder"), &WebNode::get_query_builder);
|
||||||
|
#endif
|
||||||
|
|
||||||
BIND_VMETHOD(MethodInfo("_handle_request_main", PropertyInfo(Variant::OBJECT, "request", PROPERTY_HINT_RESOURCE_TYPE, "WebServerRequest")));
|
BIND_VMETHOD(MethodInfo("_handle_request_main", PropertyInfo(Variant::OBJECT, "request", PROPERTY_HINT_RESOURCE_TYPE, "WebServerRequest")));
|
||||||
ClassDB::bind_method(D_METHOD("handle_request_main", "request"), &WebNode::handle_request_main);
|
ClassDB::bind_method(D_METHOD("handle_request_main", "request"), &WebNode::handle_request_main);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef WEB_NODE_H
|
#ifndef WEB_NODE_H
|
||||||
#define WEB_NODE_H
|
#define WEB_NODE_H
|
||||||
|
|
||||||
|
#include "../../modules_enabled.gen.h"
|
||||||
#include "core/hash_map.h"
|
#include "core/hash_map.h"
|
||||||
#include "core/os/rw_lock.h"
|
#include "core/os/rw_lock.h"
|
||||||
#include "core/reference.h"
|
#include "core/reference.h"
|
||||||
@ -14,8 +15,8 @@ class Settings;
|
|||||||
class WebServer;
|
class WebServer;
|
||||||
class WebPermission;
|
class WebPermission;
|
||||||
|
|
||||||
#ifdef DATABASES_ENABLED
|
#ifdef MODULE_DATABASE_ENABLED
|
||||||
class DataBase;
|
class Database;
|
||||||
class TableBuilder;
|
class TableBuilder;
|
||||||
class QueryBuilder;
|
class QueryBuilder;
|
||||||
#endif
|
#endif
|
||||||
@ -49,11 +50,11 @@ public:
|
|||||||
bool get_routing_enabled();
|
bool get_routing_enabled();
|
||||||
void set_routing_enabled(const bool value);
|
void set_routing_enabled(const bool value);
|
||||||
|
|
||||||
#ifdef DATABASES_ENABLED
|
#ifdef MODULE_DATABASE_ENABLED
|
||||||
Database *get_database();
|
Ref<Database> get_database();
|
||||||
|
void set_database(const Ref<Database> &db);
|
||||||
Ref<TableBuilder> get_table_builder();
|
Ref<TableBuilder> get_table_builder();
|
||||||
Ref<QueryBuilder> get_query_builder();
|
Ref<QueryBuilder> get_query_builder();
|
||||||
void set_database(Database *db);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void handle_request_main(Ref<WebServerRequest> request);
|
void handle_request_main(Ref<WebServerRequest> request);
|
||||||
@ -116,8 +117,8 @@ protected:
|
|||||||
Settings *_settings;
|
Settings *_settings;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DATABASES_ENABLED
|
#ifdef MODULE_DATABASE_ENABLED
|
||||||
Database *_database;
|
Ref<Database> _database;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool _routing_enabled;
|
bool _routing_enabled;
|
||||||
|
Loading…
Reference in New Issue
Block a user