startet with connection query intermediates
This commit is contained in:
@@ -4,11 +4,14 @@
|
||||
#include "matador/sql/basic_condition.hpp"
|
||||
#include "matador/sql/dialect.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
struct placeholder {};
|
||||
|
||||
const placeholder _;
|
||||
|
||||
/**
|
||||
* @class condition
|
||||
* @brief Represents a sql query condition
|
||||
@@ -29,6 +32,17 @@ class query;
|
||||
template<class L, class R, class Enabled = void>
|
||||
class condition;
|
||||
|
||||
template<>
|
||||
class condition<column, placeholder, typename std::enable_if<true>::type> : public basic_column_condition
|
||||
{
|
||||
public:
|
||||
condition(const column &fld, basic_condition::operand_t op, const placeholder &val);
|
||||
|
||||
placeholder value;
|
||||
|
||||
std::string evaluate(dialect &d) const override;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class condition<column, T, typename std::enable_if<
|
||||
std::is_scalar<T>::value &&
|
||||
@@ -46,13 +60,7 @@ public:
|
||||
std::string evaluate(dialect &d) const override
|
||||
{
|
||||
d.add_host_var(field_.name());
|
||||
std::stringstream str;
|
||||
if (d.compile_type() == dialect::compile_type_t::DIRECT) {
|
||||
str << d.prepare_identifier(field_.name()) << " " << operand << " " << value;
|
||||
} else {
|
||||
str << d.prepare_identifier(field_.name()) << " " << operand << " " << d.next_placeholder();
|
||||
}
|
||||
return str.str();
|
||||
return d.prepare_identifier(field_.name()) + " " + operand + " " + std::to_string(value);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -72,13 +80,7 @@ public:
|
||||
std::string evaluate(dialect &d) const override
|
||||
{
|
||||
d.add_host_var(field_.name());
|
||||
std::stringstream str;
|
||||
if (d.compile_type() == dialect::compile_type_t::DIRECT) {
|
||||
str << d.prepare_identifier(field_.name()) << " " << operand << " '" << value << "'";
|
||||
} else {
|
||||
str << d.prepare_identifier(field_.name()) << " " << operand << " " << d.next_placeholder();
|
||||
}
|
||||
return str.str();
|
||||
return d.prepare_identifier(field_.name()) + " " + operand + " '" + value + "'";
|
||||
}
|
||||
};
|
||||
|
||||
@@ -98,9 +100,7 @@ public:
|
||||
|
||||
std::string evaluate(dialect &d) const override
|
||||
{
|
||||
std::stringstream str;
|
||||
str << value << " " << operand << " " << d.prepare_identifier(field_.name());
|
||||
return str.str();
|
||||
return std::to_string(value) + " " + operand + " " + d.prepare_identifier(field_.name());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -119,9 +119,7 @@ public:
|
||||
|
||||
std::string evaluate(dialect &d) const override
|
||||
{
|
||||
std::stringstream str;
|
||||
str << "'" << value << "' " << operand << " " << d.prepare_identifier(field_.name());
|
||||
return str.str();
|
||||
return "'" + std::to_string(value) + "' " + operand + " " + d.prepare_identifier(field_.name());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -138,74 +136,62 @@ public:
|
||||
* @endcode
|
||||
*/
|
||||
template < class V >
|
||||
class condition<column, std::initializer_list<V>> : public basic_in_condition
|
||||
{
|
||||
class condition<column, std::initializer_list<V>> : public basic_in_condition {
|
||||
public:
|
||||
/**
|
||||
* @brief Creates an IN condition
|
||||
*
|
||||
* Creates an IN condition for the given column and
|
||||
* the given list of arguments.
|
||||
*
|
||||
* @param col Column for the IN condition
|
||||
* @param args List of arguments
|
||||
*/
|
||||
condition(const column &col, const std::initializer_list<V> &args)
|
||||
: basic_in_condition(col)
|
||||
, args_(args)
|
||||
{}
|
||||
/**
|
||||
* @brief Creates an IN condition
|
||||
*
|
||||
* Creates an IN condition for the given column and
|
||||
* the given list of arguments.
|
||||
*
|
||||
* @param col Column for the IN condition
|
||||
* @param args List of arguments
|
||||
*/
|
||||
condition(const column &col, const std::initializer_list<V> &args)
|
||||
: basic_in_condition(col), args_(args) {}
|
||||
|
||||
/**
|
||||
* @brief Evaluates the condition
|
||||
*
|
||||
* Evaluates the condition to a part of the
|
||||
* query string based on the given compile type
|
||||
*
|
||||
* @param d The d used to evaluate
|
||||
* @return A condition IN part of the query
|
||||
*/
|
||||
std::string evaluate(dialect &d) const override
|
||||
{
|
||||
auto count = size();
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
d.add_host_var(field_.name());
|
||||
}
|
||||
std::stringstream str;
|
||||
str << d.prepare_identifier(field_.name()) << " IN (";
|
||||
if (args_.size() > 1) {
|
||||
auto first = args_.begin();
|
||||
auto last = args_.end() - 1;
|
||||
while (first != last) {
|
||||
if (d.compile_type() == dialect::compile_type_t::DIRECT) {
|
||||
str << *first++ << ",";
|
||||
} else {
|
||||
++first;
|
||||
str << d.next_placeholder() << ",";
|
||||
/**
|
||||
* @brief Evaluates the condition
|
||||
*
|
||||
* Evaluates the condition to a part of the
|
||||
* query string based on the given compile type
|
||||
*
|
||||
* @param d The d used to evaluate
|
||||
* @return A condition IN part of the query
|
||||
*/
|
||||
std::string evaluate(dialect &d) const override {
|
||||
auto count = size();
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
d.add_host_var(field_.name());
|
||||
}
|
||||
|
||||
|
||||
std::string result = d.prepare_identifier(field_.name()) + " IN (";
|
||||
if (args_.size() < 2) {
|
||||
for (const auto &val : args_) {
|
||||
result.append(std::to_string(val));
|
||||
}
|
||||
} else {
|
||||
auto it = args_.begin();
|
||||
result.append(std::to_string(*it++));
|
||||
for(; it != args_.end(); ++it) {
|
||||
result.append(", " + std::to_string(*it));
|
||||
}
|
||||
}
|
||||
result += ")";
|
||||
return result;
|
||||
}
|
||||
if (!args_.empty()) {
|
||||
if (d.compile_type() == dialect::compile_type_t::DIRECT) {
|
||||
str << args_.back();
|
||||
} else {
|
||||
str << d.next_placeholder();
|
||||
}
|
||||
}
|
||||
str << ")";
|
||||
return str.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the number of arguments in the list
|
||||
* @return The number of arguments in the list
|
||||
*/
|
||||
size_t size() const override
|
||||
{
|
||||
return args_.size();
|
||||
}
|
||||
/**
|
||||
* @brief Returns the number of arguments in the list
|
||||
* @return The number of arguments in the list
|
||||
*/
|
||||
[[nodiscard]] size_t size() const override {
|
||||
return args_.size();
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<V> args_;
|
||||
std::vector<V> args_;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -244,23 +230,12 @@ public:
|
||||
* @param d The d used to evaluate
|
||||
* @return A condition IN part of the query
|
||||
*/
|
||||
std::string evaluate(dialect &d) const override
|
||||
{
|
||||
std::string result(d.prepare_identifier(field_.name()) + " " + operand + " (");
|
||||
// result += d.continue_build(const_cast<query&>(query_), d.compile_type());
|
||||
result += (")");
|
||||
return result;
|
||||
}
|
||||
std::string evaluate(dialect &d) const override;
|
||||
|
||||
private:
|
||||
query &query_;
|
||||
};
|
||||
|
||||
condition<column, query>::condition(column col, basic_condition::operand_t op, query &q)
|
||||
: basic_column_condition(std::move(col), op)
|
||||
, query_(q)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief Between condition.
|
||||
*
|
||||
@@ -270,43 +245,35 @@ condition<column, query>::condition(column col, basic_condition::operand_t op, q
|
||||
* @tparam T The type of the boundary values
|
||||
*/
|
||||
template < class T >
|
||||
class condition<column, std::pair<T, T>> : public basic_condition
|
||||
{
|
||||
class condition<column, std::pair<T, T>> : public basic_condition {
|
||||
public:
|
||||
/**
|
||||
* @brief Create a new between condition
|
||||
*
|
||||
* @param col The column for the range check
|
||||
* @param range The boundary values defining the range
|
||||
*/
|
||||
condition(column col, const std::pair<T, T> &range)
|
||||
: field_(std::move(col)), range_(range) { }
|
||||
/**
|
||||
* @brief Create a new between condition
|
||||
*
|
||||
* @param col The column for the range check
|
||||
* @param range The boundary values defining the range
|
||||
*/
|
||||
condition(column col, const std::pair<T, T> &range)
|
||||
: field_(std::move(col)), range_(range) {}
|
||||
|
||||
/**
|
||||
* @brief Evaluates the condition
|
||||
*
|
||||
* Evaluates the condition to a between part
|
||||
* based on the given compile type
|
||||
*
|
||||
* @param d The d used to evaluate
|
||||
* @return A condition BETWEEN part of the query
|
||||
*/
|
||||
std::string evaluate(dialect &d) const override
|
||||
{
|
||||
d.add_host_var(field_.name());
|
||||
d.add_host_var(field_.name());
|
||||
std::stringstream str;
|
||||
if (d.compile_type() == dialect::compile_type_t::DIRECT) {
|
||||
str << d.prepare_identifier(field_.name()) << " BETWEEN " << range_.first << " AND " << range_.second;
|
||||
} else {
|
||||
str << d.prepare_identifier(field_.name()) << " BETWEEN " << d.next_placeholder() << " AND " << d.next_placeholder();
|
||||
}
|
||||
return str.str();
|
||||
}
|
||||
/**
|
||||
* @brief Evaluates the condition
|
||||
*
|
||||
* Evaluates the condition to a between part
|
||||
* based on the given compile type
|
||||
*
|
||||
* @param d The d used to evaluate
|
||||
* @return A condition BETWEEN part of the query
|
||||
*/
|
||||
std::string evaluate(dialect &d) const override {
|
||||
d.add_host_var(field_.name());
|
||||
d.add_host_var(field_.name());
|
||||
return d.prepare_identifier(field_.name()) + " BETWEEN " + std::to_string(range_.first) + " AND " + std::to_string(range_.second);
|
||||
}
|
||||
|
||||
private:
|
||||
column field_;
|
||||
std::pair<T, T> range_;
|
||||
column field_;
|
||||
std::pair<T, T> range_;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -331,7 +298,6 @@ public:
|
||||
* @param r right hand operator of the condition
|
||||
* @param op The operand (AND or OR)
|
||||
*/
|
||||
// condition(const condition<L1, R1> &l, const condition<L2, R2> &r, basic_condition::operand_t op)
|
||||
condition(condition<L1, R1> &&l, condition<L2, R2> &&r, basic_condition::operand_t op)
|
||||
: left(std::move(l)), right(std::move(r)), operand(op) { }
|
||||
|
||||
@@ -343,16 +309,14 @@ public:
|
||||
*/
|
||||
std::string evaluate(dialect &d) const override
|
||||
{
|
||||
std::stringstream str;
|
||||
// ensure the numbering order for host vars
|
||||
auto cl = left.evaluate(d);
|
||||
auto cr = right.evaluate(d);
|
||||
if (operand == basic_condition::operand_t::AND) {
|
||||
str << "(" << cl << " " << basic_condition::operands[operand] << " " << cr << ")";
|
||||
return "(" + cl + " " + basic_condition::operands[operand] + " " + cr + ")";
|
||||
} else {
|
||||
str << cl << " " << basic_condition::operands[operand] << " " << cr;
|
||||
return cl + " " + basic_condition::operands[operand] + " " + cr;
|
||||
}
|
||||
return str.str();
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -388,9 +352,7 @@ public:
|
||||
*/
|
||||
std::string evaluate(dialect &d) const override
|
||||
{
|
||||
std::stringstream str;
|
||||
str << operand << " (" << cond.evaluate(d) << ")";
|
||||
return str.str();
|
||||
return operand + " (" + cond.evaluate(d) + ")";
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -466,7 +428,6 @@ condition<column, std::pair<T, T>> between(const column &col, T low, T high)
|
||||
* @return The like condition object
|
||||
*/
|
||||
condition<column, std::string> like(const column &col, const std::string &val);
|
||||
//OOS_SQL_API condition<column, std::string> like(const matador::column &col, const std::string &val);
|
||||
|
||||
/**
|
||||
* @brief Condition equality operator for a column and a value
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef QUERY_CONNECTION_HPP
|
||||
#define QUERY_CONNECTION_HPP
|
||||
|
||||
#include "matador/sql/connection_intermediates.hpp"
|
||||
#include "matador/sql/dialect.hpp"
|
||||
#include "matador/sql/query_builder.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
class connection
|
||||
{
|
||||
public:
|
||||
connection();
|
||||
query_select_intermediate select(std::initializer_list<std::string> column_names);
|
||||
|
||||
result execute(const std::string &sql);
|
||||
|
||||
private:
|
||||
dialect dialect_;
|
||||
query_builder query_;
|
||||
};
|
||||
|
||||
}
|
||||
#endif //QUERY_CONNECTION_HPP
|
||||
@@ -0,0 +1,73 @@
|
||||
#ifndef QUERY_CONNECTION_INTERMEDIATES_HPP
|
||||
#define QUERY_CONNECTION_INTERMEDIATES_HPP
|
||||
|
||||
#include "matador/sql/result.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
class basic_condition;
|
||||
class connection;
|
||||
class query_builder;
|
||||
|
||||
struct query_intermediate
|
||||
{
|
||||
query_intermediate(connection &db, query_builder &query);
|
||||
|
||||
connection &db;
|
||||
query_builder &query;
|
||||
};
|
||||
|
||||
struct query_finish : query_intermediate
|
||||
{
|
||||
using query_intermediate::query_intermediate;
|
||||
|
||||
result fetch_all();
|
||||
result fetch_one();
|
||||
result fetch_value();
|
||||
};
|
||||
|
||||
struct query_order_direction_intermediate : query_finish
|
||||
{
|
||||
using query_finish::query_finish;
|
||||
};
|
||||
|
||||
struct query_group_by_intermediate : query_finish
|
||||
{
|
||||
using query_finish::query_finish;
|
||||
|
||||
|
||||
};
|
||||
struct query_order_by_intermediate : query_intermediate
|
||||
{
|
||||
using query_intermediate::query_intermediate;
|
||||
query_order_direction_intermediate asc();
|
||||
query_order_direction_intermediate desc();
|
||||
|
||||
};
|
||||
|
||||
struct query_where_intermediate : query_finish
|
||||
{
|
||||
using query_finish::query_finish;
|
||||
};
|
||||
|
||||
struct query_from_intermediate : query_finish
|
||||
{
|
||||
using query_finish::query_finish;
|
||||
|
||||
query_where_intermediate where(const basic_condition &cond);
|
||||
query_group_by_intermediate group_by(const std::string &name);
|
||||
query_order_by_intermediate order_by(const std::string &name);
|
||||
};
|
||||
|
||||
struct query_select_intermediate : query_intermediate
|
||||
{
|
||||
using query_intermediate::query_intermediate;
|
||||
|
||||
query_from_intermediate from(const std::string &table, const std::string &as = "");
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif //QUERY_CONNECTION_INTERMEDIATES_HPP
|
||||
@@ -23,7 +23,6 @@ public:
|
||||
SELECT,
|
||||
TABLE,
|
||||
VALUES,
|
||||
VALUE,
|
||||
COLUMNS,
|
||||
COLUMN,
|
||||
FROM,
|
||||
@@ -36,11 +35,10 @@ public:
|
||||
GROUP_BY,
|
||||
ASC,
|
||||
DESC,
|
||||
TOP,
|
||||
LIMIT,
|
||||
AS,
|
||||
OFFSET,
|
||||
DISTINCT,
|
||||
CONDITION,
|
||||
SET,
|
||||
NOT_NULL,
|
||||
PRIMARY_KEY,
|
||||
@@ -53,14 +51,6 @@ public:
|
||||
NONE
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enum representing the compile type
|
||||
*/
|
||||
enum class compile_type_t : uint8_t {
|
||||
PREPARED, /**< Compile type for prepared statements */
|
||||
DIRECT /**< Compile type for direct execute statements */
|
||||
};
|
||||
|
||||
/**
|
||||
* Holding enums concerning escaping identifiers
|
||||
*/
|
||||
@@ -127,7 +117,6 @@ public:
|
||||
*/
|
||||
virtual std::string next_placeholder() const;
|
||||
|
||||
compile_type_t compile_type() const;
|
||||
void add_host_var(const std::string &host_var);
|
||||
void add_column(const std::string &column);
|
||||
|
||||
@@ -137,41 +126,41 @@ public:
|
||||
private:
|
||||
using token_to_string_map = std::unordered_map<token_t, std::string>;
|
||||
|
||||
compile_type_t compile_type_ = compile_type_t::DIRECT;
|
||||
std::vector<std::string> host_vars_;
|
||||
std::vector<std::string> columns_;
|
||||
|
||||
token_to_string_map tokens_ {
|
||||
{token_t::CREATE, "CREATE"},
|
||||
{token_t::DROP, "DROP"},
|
||||
{token_t::REMOVE, "DELETE"},
|
||||
{token_t::INSERT, "INSERT"},
|
||||
{token_t::TABLE, "TABLE"},
|
||||
{token_t::INTO, "INTO"},
|
||||
{token_t::VALUES, "VALUES"},
|
||||
{token_t::UPDATE, "UPDATE"},
|
||||
{token_t::SELECT, "SELECT"},
|
||||
{token_t::COLUMNS, "COLUMNS"},
|
||||
{token_t::COLUMN, "COLUMN"},
|
||||
{token_t::FROM, "FROM"},
|
||||
{token_t::WHERE, "WHERE"},
|
||||
{token_t::AND, "AND"},
|
||||
{token_t::OR, "OR"},
|
||||
{token_t::LIKE, "LIKE"},
|
||||
{token_t::ORDER_BY, "ORDER BY"},
|
||||
{token_t::GROUP_BY, "GROUP BY"},
|
||||
{token_t::ASC, "ASC"},
|
||||
{token_t::DESC, "DESC"},
|
||||
{token_t::TOP, "LIMIT"},
|
||||
{token_t::AS, "AS"},
|
||||
{token_t::OFFSET, "OFFSET"},
|
||||
{token_t::DISTINCT, "DISTINCT"},
|
||||
{token_t::SET, "SET"},
|
||||
{token_t::NOT_NULL, "NOT NULL"},
|
||||
{token_t::CREATE, "CREATE"},
|
||||
{token_t::DROP, "DROP"},
|
||||
{token_t::REMOVE, "DELETE"},
|
||||
{token_t::INSERT, "INSERT"},
|
||||
{token_t::TABLE, "TABLE"},
|
||||
{token_t::INTO, "INTO"},
|
||||
{token_t::VALUES, "VALUES"},
|
||||
{token_t::UPDATE, "UPDATE"},
|
||||
{token_t::SELECT, "SELECT"},
|
||||
{token_t::COLUMNS, "COLUMNS"},
|
||||
{token_t::COLUMN, "COLUMN"},
|
||||
{token_t::FROM, "FROM"},
|
||||
{token_t::WHERE, "WHERE"},
|
||||
{token_t::AND, "AND"},
|
||||
{token_t::OR, "OR"},
|
||||
{token_t::LIKE, "LIKE"},
|
||||
{token_t::ORDER_BY, "ORDER BY"},
|
||||
{token_t::GROUP_BY, "GROUP BY"},
|
||||
{token_t::ASC, "ASC"},
|
||||
{token_t::DESC, "DESC"},
|
||||
{token_t::OFFSET, "OFFSET"},
|
||||
{token_t::LIMIT, "LIMIT"},
|
||||
{token_t::AS, "AS"},
|
||||
{token_t::OFFSET, "OFFSET"},
|
||||
{token_t::DISTINCT, "DISTINCT"},
|
||||
{token_t::SET, "SET"},
|
||||
{token_t::NOT_NULL, "NOT NULL"},
|
||||
{token_t::PRIMARY_KEY, "PRIMARY KEY"},
|
||||
{token_t::BEGIN, "BEGIN TRANSACTION"},
|
||||
{token_t::COMMIT, "COMMIT TRANSACTION"},
|
||||
{token_t::ROLLBACK, "ROLLBACK TRANSACTION"},
|
||||
{token_t::BEGIN, "BEGIN TRANSACTION"},
|
||||
{token_t::COMMIT, "COMMIT TRANSACTION"},
|
||||
{token_t::ROLLBACK, "ROLLBACK TRANSACTION"},
|
||||
{token_t::START_QUOTE, "\""},
|
||||
{token_t::END_QUOTE, "\""},
|
||||
{token_t::STRING_QUOTE, "'"},
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
@startuml
|
||||
|
||||
scale 800 width
|
||||
state Query
|
||||
|
||||
state Create
|
||||
Create : Create database table
|
||||
state Drop
|
||||
Drop : Drop database table
|
||||
state Select
|
||||
Select: Query rows
|
||||
Select: Add columns
|
||||
state Insert
|
||||
Insert: Insert rows
|
||||
state Update
|
||||
Update: Update rows
|
||||
Update: Set table name
|
||||
state Delete
|
||||
Delete: Delete items from table
|
||||
|
||||
state Table
|
||||
Table: Set table name
|
||||
state Into
|
||||
Into: Set table name
|
||||
Into: Add columns
|
||||
state From
|
||||
From: Set table name
|
||||
|
||||
state Join
|
||||
Join: Set table
|
||||
Join: Set join type (inner left, right, outer)
|
||||
state Where
|
||||
Where: Add where clause
|
||||
state Set
|
||||
Set: Set column value pairs
|
||||
state Values
|
||||
Values: Set values
|
||||
|
||||
state On:
|
||||
On: Set Expression
|
||||
|
||||
state GroupBy
|
||||
GroupBy: Add column names
|
||||
state OrderBy
|
||||
OrderBy: Add expression
|
||||
state Limit
|
||||
Limit: Add number of max result elements
|
||||
|
||||
[*] --> Query
|
||||
Query --> Create
|
||||
Query --> Drop
|
||||
Query --> Select
|
||||
Query --> Insert
|
||||
Query --> Update
|
||||
Query --> Delete
|
||||
|
||||
Create --> Table
|
||||
Drop --> Table
|
||||
Select --> From
|
||||
Insert --> Into
|
||||
Delete --> From
|
||||
|
||||
Into --> Values
|
||||
Update --> Set
|
||||
Set -> Where
|
||||
From --> Where
|
||||
From --> OrderBy
|
||||
From --> GroupBy
|
||||
From --> Join
|
||||
Join --> On
|
||||
On --> Where
|
||||
|
||||
Where --> GroupBy
|
||||
Where --> OrderBy
|
||||
Where --> Limit
|
||||
|
||||
GroupBy --> OrderBy
|
||||
OrderBy --> Limit
|
||||
|
||||
Table --> [*]
|
||||
Values ---> [*]
|
||||
Where --> [*]
|
||||
Set --> [*]
|
||||
From --> [*]
|
||||
Limit --> [*]
|
||||
OrderBy --> [*]
|
||||
GroupBy --> [*]
|
||||
|
||||
@enduml
|
||||
@@ -17,7 +17,7 @@ class dialect;
|
||||
namespace detail {
|
||||
struct any_type_to_string_visitor
|
||||
{
|
||||
any_type_to_string_visitor(const dialect &d) : d(d) {}
|
||||
explicit any_type_to_string_visitor(const dialect &d) : d(d) {}
|
||||
|
||||
void operator()(char &x) { to_string(x); }
|
||||
void operator()(short &x) { to_string(x); }
|
||||
@@ -49,6 +49,10 @@ struct any_type_to_string_visitor
|
||||
|
||||
}
|
||||
|
||||
enum class join_type_t {
|
||||
INNER, OUTER, LEFT, RIGHT
|
||||
};
|
||||
|
||||
class query_builder
|
||||
{
|
||||
private:
|
||||
@@ -70,6 +74,7 @@ private:
|
||||
QUERY_ORDER_BY,
|
||||
QUERY_ORDER_DIRECTION,
|
||||
QUERY_GROUP_BY,
|
||||
QUERY_OFFSET,
|
||||
QUERY_LIMIT,
|
||||
QUERY_FINISH
|
||||
};
|
||||
@@ -87,20 +92,28 @@ private:
|
||||
public:
|
||||
explicit query_builder(const dialect &d);
|
||||
|
||||
query_builder create();
|
||||
query_builder drop();
|
||||
query_builder select(std::initializer_list<std::string> column_names);
|
||||
query_builder insert();
|
||||
query_builder update(const std::string &table);
|
||||
query_builder remove();
|
||||
query_builder& create();
|
||||
query_builder& drop();
|
||||
query_builder& select(std::initializer_list<std::string> column_names);
|
||||
query_builder& insert();
|
||||
query_builder& update(const std::string &table);
|
||||
query_builder& remove();
|
||||
|
||||
query_builder& table(const std::string &table, std::initializer_list<column> columns);
|
||||
query_builder& table(const std::string &table);
|
||||
query_builder& into(const std::string &table, std::initializer_list<std::string> column_names);
|
||||
query_builder& values(std::initializer_list<any_type> values);
|
||||
query_builder& from(const std::string &table, const std::string &as = "");
|
||||
query_builder& join(const std::string &table, join_type_t);
|
||||
query_builder& on(const std::string &column, const std::string &join_column);
|
||||
query_builder& set(std::initializer_list<key_value_pair> key_values);
|
||||
query_builder& where(const basic_condition &cond);
|
||||
query_builder& order_by(const std::string &column);
|
||||
query_builder& group_by(const std::string &column);
|
||||
query_builder& asc();
|
||||
query_builder& desc();
|
||||
query_builder& offset(size_t count);
|
||||
query_builder& limit(size_t count);
|
||||
|
||||
std::string compile();
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef QUERY_RESULT_HPP
|
||||
#define QUERY_RESULT_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
struct result
|
||||
{
|
||||
std::string sql;
|
||||
};
|
||||
|
||||
}
|
||||
#endif //QUERY_RESULT_HPP
|
||||
Reference in New Issue
Block a user