moved query parts from intermediates declaration to definition file.
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user