moved query parts from intermediates declaration to definition file.
This commit is contained in:
parent
2d9a4f3866
commit
b9709d14c2
|
|
@ -21,6 +21,7 @@ public:
|
|||
template < class Type >
|
||||
query_select_intermediate select(std::initializer_list<column> columns);
|
||||
query_select_intermediate select(std::initializer_list<column> columns);
|
||||
query_select_intermediate select(const std::vector<column>& columns);
|
||||
query_insert_intermediate insert();
|
||||
query_update_intermediate update(const sql::table &table);
|
||||
query_delete_intermediate remove();
|
||||
|
|
@ -33,7 +34,7 @@ private:
|
|||
template<class Type>
|
||||
query_select_intermediate query::select()
|
||||
{
|
||||
return query_select_intermediate{connection_, schema_, column_name_generator::generate<Type>(*schema_)};
|
||||
return select(column_name_generator::generate<Type>(*schema_));
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
|
|
@ -41,7 +42,7 @@ query_select_intermediate query::select(std::initializer_list<column> columns)
|
|||
{
|
||||
auto cols = column_name_generator::generate<Type>(*schema_);
|
||||
cols.insert(cols.end(), columns);
|
||||
return query_select_intermediate{connection_, schema_, cols};
|
||||
return select(cols);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef QUERY_QUERY_DATA_HPP
|
||||
#define QUERY_QUERY_DATA_HPP
|
||||
|
||||
#include "matador/sql/query_parts.hpp"
|
||||
#include "matador/sql/query_part.hpp"
|
||||
#include "matador/sql/table.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
|
|
|||
|
|
@ -143,11 +143,13 @@ public:
|
|||
template<class Condition>
|
||||
query_where_intermediate where(const Condition &cond)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_where_part>(cond));
|
||||
return {connection_, schema_, data_};
|
||||
return where_clause(std::make_unique<Condition>(std::move(cond)));
|
||||
}
|
||||
query_group_by_intermediate group_by(const column &col);
|
||||
query_order_by_intermediate order_by(const column &col);
|
||||
|
||||
private:
|
||||
query_where_intermediate where_clause(std::unique_ptr<basic_condition> &&cond);
|
||||
};
|
||||
|
||||
class query_join_intermediate : public query_intermediate
|
||||
|
|
@ -158,9 +160,11 @@ public:
|
|||
template<class Condition>
|
||||
query_on_intermediate on(const Condition &cond)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_on_part>(cond));
|
||||
return {connection_, schema_, data_};
|
||||
return on_clause(std::make_unique<Condition>(std::move(cond)));
|
||||
}
|
||||
|
||||
private:
|
||||
query_on_intermediate on_clause(std::unique_ptr<basic_condition> &&cond);
|
||||
};
|
||||
|
||||
class query_from_intermediate : public query_select_finish
|
||||
|
|
@ -172,11 +176,13 @@ public:
|
|||
template<class Condition>
|
||||
query_where_intermediate where(const Condition &cond)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_where_part>(cond));
|
||||
return {connection_, schema_, data_};
|
||||
return where_clause(std::make_unique<Condition>(std::move(cond)));
|
||||
}
|
||||
query_group_by_intermediate group_by(const column &col);
|
||||
query_order_by_intermediate order_by(const column &col);
|
||||
|
||||
private:
|
||||
query_where_intermediate where_clause(std::unique_ptr<basic_condition> &&cond);
|
||||
};
|
||||
|
||||
class query_start_intermediate : public basic_query_intermediate
|
||||
|
|
@ -211,19 +217,17 @@ public:
|
|||
using query_intermediate::query_intermediate;
|
||||
|
||||
query_execute_finish values(std::initializer_list<any_type> values);
|
||||
query_execute_finish values(const std::vector<any_type>& values);
|
||||
query_execute_finish values(std::vector<any_type> &&values);
|
||||
template<class Type>
|
||||
query_execute_finish values()
|
||||
{
|
||||
Type obj;
|
||||
data_.parts.push_back(std::make_unique<query_values_part>(as_placeholder(obj)));
|
||||
return {connection_, schema_, data_};
|
||||
return values(std::move(as_placeholder(obj)));
|
||||
}
|
||||
template<class Type>
|
||||
query_execute_finish values(const Type &obj)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_values_part>(value_extractor::extract(obj)));
|
||||
return {connection_, schema_, data_};
|
||||
return values(std::move(value_extractor::extract(obj)));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -258,11 +262,11 @@ public:
|
|||
explicit query_insert_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema);
|
||||
|
||||
query_into_intermediate into(const sql::table &table, std::initializer_list<column> column_names);
|
||||
query_into_intermediate into(const sql::table &table, std::vector<column> &&column_names);
|
||||
template<class Type>
|
||||
query_into_intermediate into(const sql::table &table)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_into_part>(table, column_name_generator::generate<Type>(*schema_)));
|
||||
return {connection_, schema_, data_};
|
||||
return into(table, column_name_generator::generate<Type>(*schema_));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -282,9 +286,11 @@ public:
|
|||
template<class Condition>
|
||||
query_execute_where_intermediate where(const Condition &cond)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_where_part>(cond));
|
||||
return {connection_, schema_, data_};
|
||||
return where_clause(std::make_unique<Condition>(std::move(cond)));
|
||||
}
|
||||
|
||||
private:
|
||||
query_execute_where_intermediate where_clause(std::unique_ptr<basic_condition> &&cond);
|
||||
};
|
||||
|
||||
class query_update_intermediate : public query_start_intermediate
|
||||
|
|
@ -293,11 +299,11 @@ public:
|
|||
query_update_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema, const sql::table& table);
|
||||
|
||||
query_set_intermediate set(std::initializer_list<key_value_pair> columns);
|
||||
query_set_intermediate set(std::vector<key_value_pair> &&columns);
|
||||
template<class Type>
|
||||
query_set_intermediate set(const Type &obj)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_set_part>(key_value_generator::generate(obj)));
|
||||
return {connection_, schema_, data_};
|
||||
return set(key_value_generator::generate(obj));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -309,9 +315,11 @@ public:
|
|||
template<class Condition>
|
||||
query_execute_where_intermediate where(const Condition &cond)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_where_part>(cond));
|
||||
return {connection_, schema_, data_};
|
||||
return where_clause(std::make_unique<Condition>(std::move(cond)));
|
||||
}
|
||||
|
||||
private:
|
||||
query_execute_where_intermediate where_clause(std::unique_ptr<basic_condition> &&cond);
|
||||
};
|
||||
|
||||
class query_delete_intermediate : public query_start_intermediate
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
#ifndef QUERY_QUERY_PART_HPP
|
||||
#define QUERY_QUERY_PART_HPP
|
||||
|
||||
#include "matador/sql/dialect.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
class query_part_visitor;
|
||||
|
||||
class query_part
|
||||
{
|
||||
protected:
|
||||
explicit query_part(sql::dialect::token_t token);
|
||||
|
||||
public:
|
||||
virtual ~query_part() = default;
|
||||
virtual void accept(query_part_visitor &visitor) = 0;
|
||||
|
||||
protected:
|
||||
sql::dialect::token_t token_;
|
||||
};
|
||||
|
||||
}
|
||||
#endif //QUERY_QUERY_PART_HPP
|
||||
|
|
@ -5,8 +5,8 @@
|
|||
#include "matador/sql/query_part_visitor.hpp"
|
||||
#include "matador/sql/column.hpp"
|
||||
#include "matador/sql/column_definition.hpp"
|
||||
#include "matador/sql/dialect.hpp"
|
||||
#include "matador/sql/key_value_pair.hpp"
|
||||
#include "matador/sql/query_part.hpp"
|
||||
#include "matador/sql/table.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
|
@ -15,19 +15,6 @@ namespace matador::sql {
|
|||
|
||||
class basic_condition;
|
||||
|
||||
class query_part
|
||||
{
|
||||
protected:
|
||||
explicit query_part(sql::dialect::token_t token);
|
||||
|
||||
public:
|
||||
virtual ~query_part() = default;
|
||||
virtual void accept(query_part_visitor &visitor) = 0;
|
||||
|
||||
protected:
|
||||
sql::dialect::token_t token_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents the SQL SELECT part
|
||||
*/
|
||||
|
|
@ -81,8 +68,9 @@ public:
|
|||
explicit query_on_part(const Condition &cond)
|
||||
: query_part(dialect::token_t::ON)
|
||||
, condition_(new Condition(cond)) {}
|
||||
explicit query_on_part(std::unique_ptr<basic_condition> &&cond);
|
||||
|
||||
const basic_condition& condition() const;
|
||||
[[nodiscard]] const basic_condition& condition() const;
|
||||
|
||||
private:
|
||||
void accept(query_part_visitor &visitor) override;
|
||||
|
|
@ -98,6 +86,7 @@ public:
|
|||
explicit query_where_part(const Condition &cond)
|
||||
: query_part(dialect::token_t::WHERE)
|
||||
, condition_(new Condition(cond)) {}
|
||||
explicit query_where_part(std::unique_ptr<basic_condition> &&cond);
|
||||
|
||||
[[nodiscard]] const basic_condition& condition() const;
|
||||
|
||||
|
|
@ -221,7 +210,7 @@ private:
|
|||
class query_values_part : public query_part
|
||||
{
|
||||
public:
|
||||
query_values_part(std::vector<any_type> values);
|
||||
query_values_part(std::vector<any_type> &&values);
|
||||
|
||||
[[nodiscard]] const std::vector<any_type>& values() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
#ifndef QUERY_QUERY_RESULT_HPP
|
||||
#define QUERY_QUERY_RESULT_HPP
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "matador/sql/query_result_impl.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace matador::sql {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ set(SQL_SOURCES
|
|||
sql/query_parts.cpp
|
||||
sql/query_compiler.cpp
|
||||
sql/noop_connection.cpp
|
||||
sql/query_part.cpp
|
||||
)
|
||||
|
||||
set(SQL_HEADER
|
||||
|
|
@ -81,6 +82,7 @@ set(SQL_HEADER
|
|||
../include/matador/sql/query_data.hpp
|
||||
../include/matador/sql/table.hpp
|
||||
../include/matador/sql/noop_connection.hpp
|
||||
../include/matador/sql/query_part.hpp
|
||||
)
|
||||
|
||||
set(QUERY_SOURCES
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ query_drop_intermediate query::drop()
|
|||
}
|
||||
|
||||
query_select_intermediate query::select(std::initializer_list<column> columns)
|
||||
{
|
||||
return select(std::vector<column>{columns});
|
||||
}
|
||||
|
||||
query_select_intermediate query::select(const std::vector<column>& columns)
|
||||
{
|
||||
return {connection_, schema_, columns};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,6 +77,12 @@ query_order_direction_intermediate query_order_by_intermediate::desc()
|
|||
return {connection_, schema_, data_};
|
||||
}
|
||||
|
||||
query_where_intermediate query_from_intermediate::where_clause(std::unique_ptr<basic_condition> &&cond)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_where_part>(std::move(cond)));
|
||||
return {connection_, schema_, data_};
|
||||
}
|
||||
|
||||
query_group_by_intermediate query_from_intermediate::group_by(const column &col)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_group_by_part>(col));
|
||||
|
|
@ -107,6 +113,12 @@ query_join_intermediate query_on_intermediate::join_left(const table &t)
|
|||
return {connection_, schema_, data_};
|
||||
}
|
||||
|
||||
query_where_intermediate query_on_intermediate::where_clause(std::unique_ptr<basic_condition> &&cond)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_where_part>(std::move(cond)));
|
||||
return {connection_, schema_, data_};
|
||||
}
|
||||
|
||||
query_group_by_intermediate query_on_intermediate::group_by(const column &col)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_group_by_part>(col));
|
||||
|
|
@ -119,6 +131,12 @@ query_order_by_intermediate query_on_intermediate::order_by(const column &col)
|
|||
return {connection_, schema_, data_};
|
||||
}
|
||||
|
||||
query_on_intermediate query_join_intermediate::on_clause(std::unique_ptr<basic_condition> &&cond)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_on_part>(std::move(cond)));
|
||||
return {connection_, schema_, data_};
|
||||
}
|
||||
|
||||
query_join_intermediate query_from_intermediate::join_left(const table &t)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_join_part>(t));
|
||||
|
|
@ -144,6 +162,11 @@ query_insert_intermediate::query_insert_intermediate(connection &db, const std::
|
|||
}
|
||||
|
||||
query_into_intermediate query_insert_intermediate::into(const sql::table &table, std::initializer_list<column> column_names)
|
||||
{
|
||||
return into(table, std::move(std::vector<column>{column_names}));
|
||||
}
|
||||
|
||||
query_into_intermediate query_insert_intermediate::into(const table &table, std::vector<column> &&column_names)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_into_part>(table, column_names));
|
||||
return {connection_, schema_, data_};
|
||||
|
|
@ -172,9 +195,9 @@ query_execute_finish query_into_intermediate::values(std::initializer_list<any_t
|
|||
return this->values(std::vector<any_type>(values));
|
||||
}
|
||||
|
||||
query_execute_finish query_into_intermediate::values(const std::vector<any_type> &values)
|
||||
query_execute_finish query_into_intermediate::values(std::vector<any_type> &&values)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_values_part>(values));
|
||||
data_.parts.push_back(std::make_unique<query_values_part>(std::move(values)));
|
||||
return {connection_, schema_, data_};
|
||||
}
|
||||
|
||||
|
|
@ -212,6 +235,12 @@ query_execute_finish query_execute_where_intermediate::limit(int limit)
|
|||
// return {connection_, builder_.limit(limit)};
|
||||
}
|
||||
|
||||
query_execute_where_intermediate query_set_intermediate::where_clause(std::unique_ptr<basic_condition> &&cond)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_where_part>(std::move(cond)));
|
||||
return {connection_, schema_, data_};
|
||||
}
|
||||
|
||||
query_update_intermediate::query_update_intermediate(connection &db, const std::shared_ptr<sql::schema> &schema, const sql::table& table)
|
||||
: query_start_intermediate(db, schema)
|
||||
{
|
||||
|
|
@ -220,7 +249,19 @@ query_update_intermediate::query_update_intermediate(connection &db, const std::
|
|||
|
||||
query_set_intermediate query_update_intermediate::set(std::initializer_list<key_value_pair> columns)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_set_part>(columns));
|
||||
return set(std::vector<key_value_pair>{columns});
|
||||
}
|
||||
|
||||
query_set_intermediate query_update_intermediate::set(std::vector<key_value_pair> &&columns)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_set_part>(std::move(columns)));
|
||||
return {connection_, schema_, data_};
|
||||
|
||||
}
|
||||
|
||||
query_execute_where_intermediate query_delete_from_intermediate::where_clause(std::unique_ptr<basic_condition> &&cond)
|
||||
{
|
||||
data_.parts.push_back(std::make_unique<query_where_part>(std::move(cond)));
|
||||
return {connection_, schema_, data_};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
#include "matador/sql/query_part.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
query_part::query_part(sql::dialect::token_t token)
|
||||
: token_(token) {}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -5,9 +5,6 @@
|
|||
|
||||
namespace matador::sql {
|
||||
|
||||
query_part::query_part(sql::dialect::token_t token)
|
||||
: token_(token) {}
|
||||
|
||||
query_select_part::query_select_part(std::vector<column> columns)
|
||||
: query_part(sql::dialect::token_t::SELECT)
|
||||
, columns_(std::move(columns)) {}
|
||||
|
|
@ -50,6 +47,10 @@ void query_join_part::accept(query_part_visitor &visitor)
|
|||
visitor.visit(*this);
|
||||
}
|
||||
|
||||
query_on_part::query_on_part(std::unique_ptr<basic_condition> &&cond)
|
||||
: query_part(dialect::token_t::ON)
|
||||
, condition_(std::move(cond)) {}
|
||||
|
||||
const basic_condition &query_on_part::condition() const
|
||||
{
|
||||
return *condition_;
|
||||
|
|
@ -60,6 +61,10 @@ void query_on_part::accept(query_part_visitor &visitor)
|
|||
visitor.visit(*this);
|
||||
}
|
||||
|
||||
query_where_part::query_where_part(std::unique_ptr<basic_condition> &&cond)
|
||||
: query_part(dialect::token_t::WHERE)
|
||||
, condition_(std::move(cond)) {}
|
||||
|
||||
void query_where_part::accept(query_part_visitor &visitor)
|
||||
{
|
||||
visitor.visit(*this);
|
||||
|
|
@ -178,7 +183,7 @@ void query_into_part::accept(query_part_visitor &visitor)
|
|||
visitor.visit(*this);
|
||||
}
|
||||
|
||||
query_values_part::query_values_part(std::vector<any_type> values)
|
||||
query_values_part::query_values_part(std::vector<any_type> &&values)
|
||||
: query_part(sql::dialect::token_t::VALUES)
|
||||
, values_(std::move(values)) {}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@
|
|||
namespace matador::test {
|
||||
struct coordinate
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
int x{};
|
||||
int y{};
|
||||
int z{};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ enum class Color : uint8_t {
|
|||
|
||||
struct location
|
||||
{
|
||||
unsigned long id;
|
||||
unsigned long id{};
|
||||
std::string name;
|
||||
coordinate coord;
|
||||
Color color;
|
||||
Color color{Color::Green};
|
||||
|
||||
template < class Operator >
|
||||
void process(Operator &op)
|
||||
|
|
|
|||
Loading…
Reference in New Issue