Now the mysql query builder is usable.

This commit is contained in:
Relintai 2020-12-01 22:23:28 +01:00
parent 8b4efc530d
commit 7a81053ebb
10 changed files with 40 additions and 32 deletions

View File

@ -5,10 +5,10 @@ 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>();
}*/
QueryBuilder *Database::get_builder() {
return new QueryBuilder();
}
Database::Database() {
}

View File

@ -37,7 +37,7 @@ public:
virtual void connect(const std::string &connection_str);
virtual void query(const std::string &query);
//virtual std::shared_ptr<QueryBuilder> get_builder();
virtual QueryBuilder *get_builder();
Database();
~Database();

View File

@ -1,6 +1,5 @@
#include "query_builder.h"
/*
QueryBuilder *QueryBuilder::select(const std::string &params) {
return this;
}
@ -20,7 +19,10 @@ QueryBuilder *QueryBuilder::limit(const int min, const int max) {
QueryBuilder *QueryBuilder::insert(const std::string &table_name, const std::string &params_str) {
return this;
}
*/
void QueryBuilder::finalize() {
}
QueryBuilder::QueryBuilder() {
}

View File

@ -5,13 +5,13 @@
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);
*/
virtual void finalize();
QueryBuilder();
virtual ~QueryBuilder();

View File

@ -4,6 +4,7 @@
#include "core/database_manager.h"
#include "mysql_query_builder.h"
void MysqlDatabase::connect(const std::string &connection_str) {
mysql = mysql_init(mysql);
@ -52,16 +53,14 @@ 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;
QueryBuilder *MysqlDatabase::get_builder() {
return new MysqlQueryBuilder();
}
*/
MysqlDatabase::MysqlDatabase() :
Database() {
//mysql = new MYSQL();
mysql = nullptr;
}

View File

@ -18,7 +18,7 @@ public:
void connect(const std::string &connection_str);
void query(const std::string &query);
//virtual std::shared_ptr<QueryBuilder> get_builder();
QueryBuilder *get_builder();
static Database *_creation_func();
static void _register();

View File

@ -1,7 +1,7 @@
//#include "mysql_query_builder.h"
#include "mysql_query_builder.h"
/*
QueryBuilder *QueryBuilder::select(const std::string &params) {
QueryBuilder *MysqlQueryBuilder::select(const std::string &params) {
query_result += "SELECT " + params;
return this;
@ -25,12 +25,15 @@ QueryBuilder *MysqlQueryBuilder::limit(const int min, const int max) {
QueryBuilder *MysqlQueryBuilder::insert(const std::string &table_name, const std::string &params_str) {
return this;
}*/
}
void MysqlQueryBuilder::finalize() {
query_result += ";";
}
/*
MysqlQueryBuilder::MysqlQueryBuilder() {
}
MysqlQueryBuilder::~MysqlQueryBuilder() {
}*/
}

View File

@ -1,20 +1,20 @@
#ifndef MYSQL_QUERY_BUILDER_H
#define MYSQL_QUERY_BUILDER_H
#include "core/query_builder.h"
#include <memory>
#include <string>
#include "core/query_builder.h"
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);
*/
void finalize();
MysqlQueryBuilder();
~MysqlQueryBuilder();
};

View File

@ -11,8 +11,6 @@
#include "database/db_init.h"
//#include "database/mysql/mysql_query_builder.h"
#define MAIN_CLASS RDNApplication
int main(int argc, char **argv) {
@ -29,10 +27,6 @@ int main(int argc, char **argv) {
//db->_builder_creation_func = MysqlQueryBuilder::create;
db->connect("");
//MysqlQueryBuilder * b = new MysqlQueryBuilder();
Application *app = new MAIN_CLASS();
app->setup_routes();

View File

@ -2,10 +2,20 @@
#include "core/database.h"
#include "core/query_builder.h"
void MessagePage::index(Request *request) {
QueryBuilder *b = db->get_builder();
b->select("*")->from("tutorials_tbl")->finalize();
db->query(b->query_result);
/*
db->query("show databases;");
db->query("show tables;");
db->query("SELECT * FROM tutorials_tbl;");
*/
std::string r = "<html><body>";