From b26ad4cab9ba466ddddb97e1dd197a308de93a5d Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 6 Jul 2022 09:17:49 +0200 Subject: [PATCH] Cleaned up and added bindings for Database. --- modules/database/database.cpp | 18 +++++++++++++----- modules/database/database.h | 12 ++++++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/modules/database/database.cpp b/modules/database/database.cpp index d3f7d529a..ca38a94a8 100644 --- a/modules/database/database.cpp +++ b/modules/database/database.cpp @@ -1,8 +1,8 @@ #include "database.h" #include "query_builder.h" -#include "table_builder.h" #include "query_result.h" +#include "table_builder.h" void Database::connect(const String &connection_str) { } @@ -21,16 +21,24 @@ Ref Database::get_table_builder() { return Ref(new TableBuilder()); } -String Database::escape(const String str) { +String Database::escape(const String &str) { return String(); } -void Database::escape(const String str, String *to) { - +void Database::escape_to(const String &str, String *to) { } Database::Database() { } Database::~Database() { -} \ No newline at end of file +} + +void Database::_bind_methods() { + ClassDB::bind_method(D_METHOD("connect", "connection_str"), &Database::connect); + ClassDB::bind_method(D_METHOD("query", "query"), &Database::query); + ClassDB::bind_method(D_METHOD("query_run", "query"), &Database::query_run); + ClassDB::bind_method(D_METHOD("get_query_builder"), &Database::get_query_builder); + ClassDB::bind_method(D_METHOD("get_table_builder"), &Database::get_table_builder); + ClassDB::bind_method(D_METHOD("escape", "str"), &Database::escape); +} diff --git a/modules/database/database.h b/modules/database/database.h index d450a873e..9e61e5efd 100644 --- a/modules/database/database.h +++ b/modules/database/database.h @@ -2,7 +2,6 @@ #define DATABASE_H #include "core/ustring.h" -#include #include "core/reference.h" @@ -10,7 +9,9 @@ class QueryBuilder; class TableBuilder; class QueryResult; -class Database { +class Database : public Reference { + GDCLASS(Database, Reference); + public: virtual void connect(const String &connection_str); virtual Ref query(const String &query); @@ -19,11 +20,14 @@ public: virtual Ref get_query_builder(); virtual Ref get_table_builder(); - virtual String escape(const String str); - virtual void escape(const String str, String *to); + virtual String escape(const String &str); + virtual void escape_to(const String &str, String *to); Database(); ~Database(); + +protected: + static void _bind_methods(); }; #endif