Added the QueryBuilder class, and started working on it's api.

This commit is contained in:
Relintai 2020-12-01 21:48:13 +01:00
parent 663ddb5bc9
commit 8b4efc530d
9 changed files with 137 additions and 2 deletions

View File

@ -1,12 +1,14 @@
#include "database.h"
void Database::connect(const std::string &connection_str) {
}
void Database::query(const std::string &query) {
}
/*
std::shared_ptr<QueryBuilder> Database::get_builder() {
return std::shared_ptr<QueryBuilder>();
}*/
Database::Database() {
}

View File

@ -2,6 +2,9 @@
#define DATABASE_H
#include <string>
#include <memory>
#include "query_builder.h"
enum QueryErrorCode {
OK,
@ -34,8 +37,13 @@ public:
virtual void connect(const std::string &connection_str);
virtual void query(const std::string &query);
//virtual std::shared_ptr<QueryBuilder> get_builder();
Database();
~Database();
private:
//std::vector<QueryBuilder *> _builders;
};
#endif

28
core/query_builder.cpp Normal file
View File

@ -0,0 +1,28 @@
#include "query_builder.h"
/*
QueryBuilder *QueryBuilder::select(const std::string &params) {
return this;
}
QueryBuilder *QueryBuilder::where(const std::string &params) {
return this;
}
QueryBuilder *QueryBuilder::from(const std::string &params) {
return this;
}
QueryBuilder *QueryBuilder::limit(const int min, const int max) {
return this;
}
QueryBuilder *QueryBuilder::insert(const std::string &table_name, const std::string &params_str) {
return this;
}
*/
QueryBuilder::QueryBuilder() {
}
QueryBuilder::~QueryBuilder() {
}

21
core/query_builder.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef QUERY_BUILDER_H
#define QUERY_BUILDER_H
#include <string>
class QueryBuilder {
public:
/*
virtual QueryBuilder *select(const std::string &params);
virtual QueryBuilder *where(const std::string &params);
virtual QueryBuilder *from(const std::string &params);
virtual QueryBuilder *limit(const int min, const int max);
virtual QueryBuilder *insert(const std::string &table_name, const std::string &params_str);
*/
QueryBuilder();
virtual ~QueryBuilder();
std::string query_result;
};
#endif

View File

@ -4,6 +4,7 @@
#include "core/database_manager.h"
void MysqlDatabase::connect(const std::string &connection_str) {
mysql = mysql_init(mysql);
mysql_options(mysql, MYSQL_OPT_NONBLOCK, 0);
@ -51,6 +52,12 @@ void MysqlDatabase::query(const std::string &query) {
mysql_free_result(result);
}
/*
std::shared_ptr<QueryBuilder> MysqlDatabase::get_builder() {
//return std::make_shared<MysqlQueryBuilder>();
return nullptr;
}
*/
MysqlDatabase::MysqlDatabase() :
Database() {

View File

@ -3,6 +3,8 @@
#include "core/database.h"
#include <memory>
//Brynet has it aswell, and because of using namespace it is defined here aswell
//later this will be fixed better
#ifdef IS_NUM
@ -16,6 +18,8 @@ public:
void connect(const std::string &connection_str);
void query(const std::string &query);
//virtual std::shared_ptr<QueryBuilder> get_builder();
static Database *_creation_func();
static void _register();
static void _unregister();

View File

@ -0,0 +1,36 @@
//#include "mysql_query_builder.h"
/*
QueryBuilder *QueryBuilder::select(const std::string &params) {
query_result += "SELECT " + params;
return this;
}
QueryBuilder *MysqlQueryBuilder::where(const std::string &params) {
query_result += " WHERE " + params;
return this;
}
QueryBuilder *MysqlQueryBuilder::from(const std::string &params) {
query_result += " FROM " + params;
return this;
}
QueryBuilder *MysqlQueryBuilder::limit(const int min, const int max) {
return this;
}
QueryBuilder *MysqlQueryBuilder::insert(const std::string &table_name, const std::string &params_str) {
return this;
}*/
/*
MysqlQueryBuilder::MysqlQueryBuilder() {
}
MysqlQueryBuilder::~MysqlQueryBuilder() {
}*/

View File

@ -0,0 +1,22 @@
#ifndef MYSQL_QUERY_BUILDER_H
#define MYSQL_QUERY_BUILDER_H
#include "core/query_builder.h"
#include <memory>
#include <string>
class MysqlQueryBuilder : public QueryBuilder {
public:
/*
QueryBuilder *select(const std::string &params);
QueryBuilder *where(const std::string &params);
QueryBuilder *from(const std::string &params);
QueryBuilder *limit(const int min, const int max);
QueryBuilder *insert(const std::string &table_name, const std::string &params_str);
*/
MysqlQueryBuilder();
~MysqlQueryBuilder();
};
#endif

View File

@ -11,6 +11,8 @@
#include "database/db_init.h"
//#include "database/mysql/mysql_query_builder.h"
#define MAIN_CLASS RDNApplication
int main(int argc, char **argv) {
@ -24,8 +26,13 @@ int main(int argc, char **argv) {
uint32_t index = dbm->create_database("mysql");
Database *db = dbm->databases[0];
//db->_builder_creation_func = MysqlQueryBuilder::create;
db->connect("");
//MysqlQueryBuilder * b = new MysqlQueryBuilder();
Application *app = new MAIN_CLASS();
app->setup_routes();