mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
Added the QueryBuilder class, and started working on it's api.
This commit is contained in:
parent
663ddb5bc9
commit
8b4efc530d
@ -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() {
|
||||
}
|
||||
|
@ -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
28
core/query_builder.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include "query_builder.h"
|
||||
|
||||
/*
|
||||
QueryBuilder *QueryBuilder::select(const std::string ¶ms) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::where(const std::string ¶ms) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::from(const std::string ¶ms) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::limit(const int min, const int max) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::insert(const std::string &table_name, const std::string ¶ms_str) {
|
||||
return this;
|
||||
}
|
||||
*/
|
||||
QueryBuilder::QueryBuilder() {
|
||||
}
|
||||
|
||||
QueryBuilder::~QueryBuilder() {
|
||||
}
|
21
core/query_builder.h
Normal file
21
core/query_builder.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef QUERY_BUILDER_H
|
||||
#define QUERY_BUILDER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class QueryBuilder {
|
||||
public:
|
||||
/*
|
||||
virtual QueryBuilder *select(const std::string ¶ms);
|
||||
virtual QueryBuilder *where(const std::string ¶ms);
|
||||
virtual QueryBuilder *from(const std::string ¶ms);
|
||||
virtual QueryBuilder *limit(const int min, const int max);
|
||||
virtual QueryBuilder *insert(const std::string &table_name, const std::string ¶ms_str);
|
||||
*/
|
||||
QueryBuilder();
|
||||
virtual ~QueryBuilder();
|
||||
|
||||
std::string query_result;
|
||||
};
|
||||
|
||||
#endif
|
@ -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() {
|
||||
|
||||
|
@ -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();
|
||||
|
36
database/mysql/mysql_query_builder.cpp
Normal file
36
database/mysql/mysql_query_builder.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
//#include "mysql_query_builder.h"
|
||||
|
||||
/*
|
||||
QueryBuilder *QueryBuilder::select(const std::string ¶ms) {
|
||||
query_result += "SELECT " + params;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *MysqlQueryBuilder::where(const std::string ¶ms) {
|
||||
query_result += " WHERE " + params;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *MysqlQueryBuilder::from(const std::string ¶ms) {
|
||||
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 ¶ms_str) {
|
||||
return this;
|
||||
}*/
|
||||
|
||||
/*
|
||||
MysqlQueryBuilder::MysqlQueryBuilder() {
|
||||
|
||||
}
|
||||
MysqlQueryBuilder::~MysqlQueryBuilder() {
|
||||
|
||||
}*/
|
22
database/mysql/mysql_query_builder.h
Normal file
22
database/mysql/mysql_query_builder.h
Normal 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 ¶ms);
|
||||
QueryBuilder *where(const std::string ¶ms);
|
||||
QueryBuilder *from(const std::string ¶ms);
|
||||
QueryBuilder *limit(const int min, const int max);
|
||||
QueryBuilder *insert(const std::string &table_name, const std::string ¶ms_str);
|
||||
*/
|
||||
MysqlQueryBuilder();
|
||||
~MysqlQueryBuilder();
|
||||
};
|
||||
|
||||
#endif
|
7
main.cpp
7
main.cpp
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user