removed condition classes, functions and operators
This commit is contained in:
parent
6fa56b2019
commit
93785a6bc2
|
|
@ -4,7 +4,7 @@
|
|||
#include "matador/orm/error_code.hpp"
|
||||
#include "matador/orm/session_query_builder.hpp"
|
||||
|
||||
#include "matador/query/condition.hpp"
|
||||
#include "matador/query/criteria.hpp"
|
||||
#include "matador/query/query.hpp"
|
||||
|
||||
#include "matador/sql/column_generator.hpp"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "matador/orm/query_builder_exception.hpp"
|
||||
|
||||
#include "matador/query/condition.hpp"
|
||||
#include "matador/query/criteria.hpp"
|
||||
#include "matador/query/query_intermediates.hpp"
|
||||
|
||||
#include "matador/object/repository.hpp"
|
||||
|
|
@ -14,8 +14,8 @@
|
|||
namespace matador::orm {
|
||||
struct entity_insert_data {
|
||||
sql::table table;
|
||||
std::vector<std::string> columns;
|
||||
std::vector<utils::database_type> values;
|
||||
std::vector<std::string> columns{};
|
||||
std::vector<utils::database_type> values{};
|
||||
};
|
||||
|
||||
enum class insert_build_error : std::uint8_t {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "matador/orm/query_builder_exception.hpp"
|
||||
|
||||
#include "matador/query/condition.hpp"
|
||||
#include "matador/query/criteria.hpp"
|
||||
#include "matador/query/query.hpp"
|
||||
|
||||
#include "matador/sql/executor.hpp"
|
||||
|
|
@ -27,7 +27,7 @@ struct entity_query_data {
|
|||
std::vector<sql::column> columns{};
|
||||
std::unordered_map<std::string, sql::statement> lazy_loading_statements{};
|
||||
std::vector<query::join_data> joins{};
|
||||
std::unique_ptr<query::basic_condition> where_clause{};
|
||||
query::criteria_ptr where_clause;
|
||||
};
|
||||
|
||||
class session_query_builder final {
|
||||
|
|
@ -87,8 +87,9 @@ public:
|
|||
}
|
||||
entity_query_data_.pk_column_name = id;
|
||||
if (!pk_.is_null()) {
|
||||
auto c = sql::column{table_info_stack_.top().table, id, ""};
|
||||
auto co = std::make_unique<query::condition<sql::column, utils::placeholder>>(c, query::basic_condition::operand_type::EQUAL, utils::_);
|
||||
const auto c = sql::column{table_info_stack_.top().table, id, ""};
|
||||
using namespace matador::query;
|
||||
auto co = c == utils::_;
|
||||
entity_query_data_.where_clause = std::move(co);
|
||||
}
|
||||
}
|
||||
|
|
@ -240,13 +241,13 @@ private:
|
|||
std::shared_ptr<sql::table> table;
|
||||
};
|
||||
|
||||
std::stack<table_info> table_info_stack_;
|
||||
std::unordered_map<std::string, std::shared_ptr<sql::table>> processed_tables_;
|
||||
std::stack<table_info> table_info_stack_{};
|
||||
std::unordered_map<std::string, std::shared_ptr<sql::table>> processed_tables_{};
|
||||
const object::repository &schema_;
|
||||
entity_query_data entity_query_data_;
|
||||
entity_query_data entity_query_data_{};
|
||||
unsigned int column_index{0};
|
||||
unsigned int table_index{0};
|
||||
object::join_columns_collector join_columns_collector_;
|
||||
object::join_columns_collector join_columns_collector_{};
|
||||
sql::executor &executor_;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ public:
|
|||
void accept(criteria_visitor& visitor) const override;
|
||||
|
||||
[[nodiscard]] const sql::column& column() const;
|
||||
[[nodiscard]] const criteria_value &min() const;
|
||||
[[nodiscard]] const criteria_value &max() const;
|
||||
[[nodiscard]] const criteria_value &minimum() const;
|
||||
[[nodiscard]] const criteria_value &maximum() const;
|
||||
|
||||
private:
|
||||
sql::column column_;
|
||||
|
|
|
|||
|
|
@ -32,5 +32,22 @@ private:
|
|||
binary_operator operator_{};
|
||||
criteria_value value_;
|
||||
};
|
||||
|
||||
class binary_column_criteria final : public abstract_criteria {
|
||||
public:
|
||||
binary_column_criteria() = delete;
|
||||
binary_column_criteria(sql::column left_column, binary_operator operand, sql::column right_column);
|
||||
|
||||
void accept(criteria_visitor& visitor) const override;
|
||||
|
||||
[[nodiscard]] const sql::column& left_column() const;
|
||||
[[nodiscard]] binary_operator operand() const;
|
||||
[[nodiscard]] const sql::column& right_column() const;
|
||||
|
||||
private:
|
||||
sql::column left_column_;
|
||||
binary_operator operator_{};
|
||||
sql::column right_column_;
|
||||
};
|
||||
}
|
||||
#endif //CRITERIA_BINARY_CRITERIA_NODE_HPP
|
||||
|
|
@ -9,13 +9,33 @@
|
|||
|
||||
namespace matador::query {
|
||||
enum class collection_operator {
|
||||
IN,
|
||||
OUT
|
||||
In,
|
||||
Out
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Criteria class representing an IN condition
|
||||
*
|
||||
* This class represents a query IN condition and evaluates to
|
||||
* this condition based on the current database d
|
||||
*
|
||||
* @code
|
||||
* WHERE age IN (29,34,56)
|
||||
* @endcode
|
||||
*/
|
||||
class collection_criteria final : public abstract_criteria {
|
||||
public:
|
||||
collection_criteria() = delete;
|
||||
/**
|
||||
* @brief Creates an IN condition
|
||||
*
|
||||
* Creates an IN or OUT criteria for the given sql::column and
|
||||
* the given list of arguments.
|
||||
*
|
||||
* @param col Column for the IN condition
|
||||
* @param operand_ Operator to use
|
||||
* @param values List of values
|
||||
*/
|
||||
collection_criteria(sql::column col, collection_operator operand_, std::vector<criteria_value> values);
|
||||
collection_criteria(sql::column col, collection_operator operand_, std::initializer_list<criteria_value> values);
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ criteria_ptr operator==(const sql::column &col, Type val) {
|
|||
return std::make_unique<binary_criteria>(col, binary_operator::EQUALS, utils::value(val));
|
||||
}
|
||||
|
||||
criteria_ptr operator==(const sql::column &col_left, const sql::column &col_right);
|
||||
|
||||
template<class Type>
|
||||
criteria_ptr operator!=(const sql::column &col, Type val) {
|
||||
return std::make_unique<binary_criteria>(col, binary_operator::NOT_EQUALS, utils::value(val));
|
||||
|
|
@ -63,7 +65,7 @@ criteria_ptr in(const sql::column &col, std::initializer_list<Type> args) {
|
|||
for ( auto &&arg : args ) {
|
||||
values.emplace_back(utils::value{std::move(arg)});
|
||||
}
|
||||
return std::make_unique<collection_criteria>(col, collection_operator::IN, std::move(values));
|
||||
return std::make_unique<collection_criteria>(col, collection_operator::In, std::move(values));
|
||||
}
|
||||
|
||||
template <>
|
||||
|
|
@ -77,7 +79,7 @@ criteria_ptr out(const sql::column &col, std::initializer_list<Type> args) {
|
|||
for ( auto &&arg : args ) {
|
||||
values.emplace_back(utils::value{std::move(arg)});
|
||||
}
|
||||
return std::make_unique<collection_criteria>(col, collection_operator::OUT, values);
|
||||
return std::make_unique<collection_criteria>(col, collection_operator::Out, values);
|
||||
}
|
||||
|
||||
template <>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
namespace matador::query {
|
||||
class between_criteria;
|
||||
class binary_criteria;
|
||||
class binary_column_criteria;
|
||||
class like_criteria;
|
||||
class logical_criteria;
|
||||
class not_criteria;
|
||||
|
|
@ -16,6 +17,7 @@ public:
|
|||
|
||||
virtual void visit(const between_criteria &node) = 0;
|
||||
virtual void visit(const binary_criteria &node) = 0;
|
||||
virtual void visit(const binary_column_criteria &node) = 0;
|
||||
virtual void visit(const collection_criteria &node) = 0;
|
||||
virtual void visit(const collection_query_criteria &node) = 0;
|
||||
virtual void visit(const like_criteria &node) = 0;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ public:
|
|||
|
||||
void visit(const between_criteria &node) override;
|
||||
void visit(const binary_criteria &node) override;
|
||||
void visit(const binary_column_criteria &node) override;
|
||||
void visit(const collection_criteria &node) override;
|
||||
void visit(const collection_query_criteria &node) override;
|
||||
void visit(const like_criteria &node) override;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "matador/query/intermediates/executable_query.hpp"
|
||||
|
||||
#include "matador/query/basic_condition.hpp"
|
||||
#include "matador/query/criteria/abstract_criteria.hpp"
|
||||
|
||||
#include "matador/query/intermediates/query_execute_where_intermediate.hpp"
|
||||
|
||||
|
|
@ -14,14 +14,10 @@ class query_delete_from_intermediate : public executable_query
|
|||
public:
|
||||
using executable_query::executable_query;
|
||||
|
||||
template<class Condition>
|
||||
query_execute_where_intermediate where(const Condition &cond)
|
||||
{
|
||||
return where_clause(std::make_unique<Condition>(std::move(cond)));
|
||||
}
|
||||
query_execute_where_intermediate where(std::unique_ptr<abstract_criteria> cond);
|
||||
|
||||
private:
|
||||
query_execute_where_intermediate where_clause(std::unique_ptr<basic_condition> &&cond);
|
||||
query_execute_where_intermediate where_clause(std::unique_ptr<abstract_criteria> &&cond);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,20 +19,17 @@ public:
|
|||
query_from_intermediate join_left(join_data &data);
|
||||
query_from_intermediate join_left(std::vector<join_data> &data_vector);
|
||||
|
||||
template<class Condition>
|
||||
query_where_intermediate where(const Condition &cond)
|
||||
{
|
||||
return where_clause(std::make_unique<Condition>(std::move(cond)));
|
||||
}
|
||||
query_where_intermediate where(std::unique_ptr<basic_condition> &&cond)
|
||||
{
|
||||
return where_clause(std::move(cond));
|
||||
}
|
||||
// template<class Condition>
|
||||
// query_where_intermediate where(const Condition &cond)
|
||||
// {
|
||||
// return where_clause(std::make_unique<Condition>(std::move(cond)));
|
||||
// }
|
||||
query_where_intermediate where(std::unique_ptr<abstract_criteria> &&cond);
|
||||
query_group_by_intermediate group_by(const sql::column &col);
|
||||
query_order_by_intermediate order_by(const sql::column &col);
|
||||
|
||||
private:
|
||||
query_where_intermediate where_clause(std::unique_ptr<basic_condition> &&cond);
|
||||
query_where_intermediate where_clause(std::unique_ptr<abstract_criteria> &&cond);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,18 +13,15 @@ class query_join_intermediate : public query_intermediate
|
|||
public:
|
||||
using query_intermediate::query_intermediate;
|
||||
|
||||
template<class Condition>
|
||||
query_on_intermediate on(const Condition &cond)
|
||||
{
|
||||
return on_clause(std::make_unique<Condition>(std::move(cond)));
|
||||
}
|
||||
query_on_intermediate on(std::unique_ptr<basic_condition> &&cond)
|
||||
{
|
||||
return on_clause(std::move(cond));
|
||||
}
|
||||
// template<class Condition>
|
||||
// query_on_intermediate on(const Condition &cond)
|
||||
// {
|
||||
// return on_clause(std::make_unique<Condition>(std::move(cond)));
|
||||
// }
|
||||
query_on_intermediate on(std::unique_ptr<abstract_criteria> &&cond);
|
||||
|
||||
private:
|
||||
query_on_intermediate on_clause(std::unique_ptr<basic_condition> &&cond);
|
||||
query_on_intermediate on_clause(std::unique_ptr<abstract_criteria> &&cond);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "matador/query/intermediates/executable_query.hpp"
|
||||
|
||||
#include "matador/query/basic_condition.hpp"
|
||||
#include "matador/query/criteria/abstract_criteria.hpp"
|
||||
|
||||
#include "matador/query/intermediates/query_execute_where_intermediate.hpp"
|
||||
|
||||
|
|
@ -14,14 +14,12 @@ class query_set_intermediate : public executable_query
|
|||
public:
|
||||
using executable_query::executable_query;
|
||||
|
||||
template<class Condition>
|
||||
query_execute_where_intermediate where(const Condition &cond)
|
||||
{
|
||||
return where_clause(std::make_unique<Condition>(std::move(cond)));
|
||||
query_execute_where_intermediate where(std::unique_ptr<abstract_criteria> cond) {
|
||||
return where_clause(std::move(cond));
|
||||
}
|
||||
|
||||
private:
|
||||
query_execute_where_intermediate where_clause(std::unique_ptr<basic_condition> &&cond);
|
||||
query_execute_where_intermediate where_clause(std::unique_ptr<abstract_criteria> &&cond);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define QUERY_QUERY_PARTS_HPP
|
||||
|
||||
#include "matador/query/query_part_visitor.hpp"
|
||||
#include "matador/query/basic_condition.hpp"
|
||||
#include "matador/query/criteria.hpp"
|
||||
|
||||
#include "matador/query/internal/key_value_pair.hpp"
|
||||
#include "matador/query/query_part.hpp"
|
||||
|
|
@ -70,15 +70,15 @@ public:
|
|||
explicit query_on_part(const Condition &cond)
|
||||
: query_part(sql::dialect_token::On)
|
||||
, condition_(new Condition(cond)) {}
|
||||
explicit query_on_part(std::unique_ptr<basic_condition> &&cond);
|
||||
explicit query_on_part(std::unique_ptr<abstract_criteria> &&cond);
|
||||
|
||||
[[nodiscard]] const basic_condition& condition() const;
|
||||
[[nodiscard]] const abstract_criteria& condition() const;
|
||||
|
||||
private:
|
||||
void accept(query_part_visitor &visitor) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<basic_condition> condition_;
|
||||
std::unique_ptr<abstract_criteria> condition_;
|
||||
};
|
||||
|
||||
class query_where_part final : public query_part
|
||||
|
|
@ -88,15 +88,15 @@ public:
|
|||
explicit query_where_part(const Condition &cond)
|
||||
: query_part(sql::dialect_token::Where)
|
||||
, condition_(new Condition(cond)) {}
|
||||
explicit query_where_part(std::unique_ptr<basic_condition> &&cond);
|
||||
explicit query_where_part(std::unique_ptr<abstract_criteria> &&cond);
|
||||
|
||||
[[nodiscard]] const basic_condition& condition() const;
|
||||
[[nodiscard]] const abstract_criteria& condition() const;
|
||||
|
||||
private:
|
||||
void accept(query_part_visitor &visitor) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<basic_condition> condition_;
|
||||
std::unique_ptr<abstract_criteria> condition_;
|
||||
};
|
||||
|
||||
class query_table_name_part : public query_part
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef JOIN_DATA_HPP
|
||||
#define JOIN_DATA_HPP
|
||||
|
||||
#include "matador/query/basic_condition.hpp"
|
||||
#include "matador/query/criteria/abstract_criteria.hpp"
|
||||
|
||||
#include "matador/sql/table.hpp"
|
||||
|
||||
|
|
@ -9,10 +9,9 @@
|
|||
|
||||
namespace matador::query {
|
||||
|
||||
struct join_data
|
||||
{
|
||||
struct join_data {
|
||||
std::shared_ptr<sql::table> join_table;
|
||||
std::unique_ptr<basic_condition> condition;
|
||||
std::unique_ptr<abstract_criteria> condition;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ add_library(matador-orm STATIC
|
|||
../../include/matador/orm/session_insert_builder.hpp
|
||||
../../include/matador/orm/session_query_builder.hpp
|
||||
../../include/matador/query/attribute_string_writer.hpp
|
||||
../../include/matador/query/basic_condition.hpp
|
||||
../../include/matador/query/criteria/abstract_criteria.hpp
|
||||
../../include/matador/query/criteria/between_criteria.hpp
|
||||
../../include/matador/query/criteria/collection_criteria.hpp
|
||||
|
|
@ -14,7 +13,6 @@ add_library(matador-orm STATIC
|
|||
../../include/matador/query/criteria/criteria_visitor.hpp
|
||||
../../include/matador/query/criteria/like_criteria.hpp
|
||||
../../include/matador/query/criteria/logical_criteria.hpp
|
||||
../../include/matador/query/condition.hpp
|
||||
../../include/matador/query/fk_value_extractor.hpp
|
||||
../../include/matador/query/intermediates/executable_query.hpp
|
||||
../../include/matador/query/intermediates/fetchable_query.hpp
|
||||
|
|
@ -85,7 +83,6 @@ add_library(matador-orm STATIC
|
|||
orm/session_insert_builder.cpp
|
||||
orm/session_query_builder.cpp
|
||||
query/attribute_string_writer.cpp
|
||||
query/basic_condition.cpp
|
||||
query/criteria/between_criteria.cpp
|
||||
query/criteria/binary_criteria.cpp
|
||||
query/criteria/collection_criteria.cpp
|
||||
|
|
@ -93,7 +90,6 @@ add_library(matador-orm STATIC
|
|||
query/criteria/like_criteria.cpp
|
||||
query/criteria/logical_criteria.cpp
|
||||
query/criteria/not_criteria.cpp
|
||||
query/condition.cpp
|
||||
query/intermediates/executable_query.cpp
|
||||
query/intermediates/fetchable_query.cpp
|
||||
query/intermediates/query_create_intermediate.cpp
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
#include "matador/orm/session.hpp"
|
||||
|
||||
#include "matador/sql/backend_provider.hpp"
|
||||
#include "matador/sql/dialect.hpp"
|
||||
|
||||
#include "matador/query/query.hpp"
|
||||
|
||||
#include <queue>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace matador::orm {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ void session_query_builder::append_join(const sql::column &left, const sql::colu
|
|||
using namespace matador::query;
|
||||
entity_query_data_.joins.push_back({
|
||||
{right.table_},
|
||||
make_condition(left == right)
|
||||
left == right
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ const sql::column & between_criteria::column() const {
|
|||
return column_;
|
||||
}
|
||||
|
||||
const criteria_value &between_criteria::min() const {
|
||||
const criteria_value &between_criteria::minimum() const {
|
||||
return min_;
|
||||
}
|
||||
|
||||
const criteria_value &between_criteria::max() const {
|
||||
const criteria_value &between_criteria::maximum() const {
|
||||
return max_;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,4 +24,25 @@ binary_operator binary_criteria::operand() const {
|
|||
const criteria_value& binary_criteria::value() const {
|
||||
return value_;
|
||||
}
|
||||
|
||||
binary_column_criteria::binary_column_criteria( sql::column left_column, binary_operator operand, sql::column right_column )
|
||||
: left_column_(std::move(left_column))
|
||||
, operator_(operand)
|
||||
, right_column_(std::move(right_column)){}
|
||||
|
||||
void binary_column_criteria::accept(criteria_visitor& visitor) const {
|
||||
visitor.visit(*this);
|
||||
}
|
||||
|
||||
const sql::column& binary_column_criteria::left_column() const {
|
||||
return left_column_;
|
||||
}
|
||||
|
||||
binary_operator binary_column_criteria::operand() const {
|
||||
return operator_;
|
||||
}
|
||||
|
||||
const sql::column& binary_column_criteria::right_column() const {
|
||||
return right_column_;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@
|
|||
#include "matador/query/criteria/not_criteria.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
criteria_ptr operator==( const sql::column& col_left, const sql::column& col_right ) {
|
||||
return std::make_unique<binary_column_criteria>(col_left, binary_operator::EQUALS, col_right);
|
||||
}
|
||||
|
||||
criteria_ptr operator==(const sql::column &col, utils::placeholder p) {
|
||||
return std::make_unique<binary_criteria>(col, binary_operator::EQUALS, p);
|
||||
}
|
||||
|
|
@ -49,11 +53,11 @@ criteria_ptr in(const sql::column &col, const std::initializer_list<utils::place
|
|||
for ( auto &&arg : args ) {
|
||||
values.emplace_back(arg);
|
||||
}
|
||||
return std::make_unique<collection_criteria>(col, collection_operator::IN, std::move(values));
|
||||
return std::make_unique<collection_criteria>(col, collection_operator::In, std::move(values));
|
||||
}
|
||||
|
||||
criteria_ptr in(const sql::column &col, sql::query_context &&ctx) {
|
||||
return std::make_unique<collection_query_criteria>(col, collection_operator::IN, std::move(ctx));
|
||||
return std::make_unique<collection_query_criteria>(col, collection_operator::In, std::move(ctx));
|
||||
}
|
||||
|
||||
template <>
|
||||
|
|
@ -62,11 +66,11 @@ criteria_ptr out(const sql::column &col, const std::initializer_list<utils::plac
|
|||
for ( auto &&arg : args ) {
|
||||
values.emplace_back(arg);
|
||||
}
|
||||
return std::make_unique<collection_criteria>(col, collection_operator::OUT, values);
|
||||
return std::make_unique<collection_criteria>(col, collection_operator::Out, values);
|
||||
}
|
||||
|
||||
criteria_ptr out(const sql::column &col, sql::query_context &&ctx) {
|
||||
return std::make_unique<collection_query_criteria>(col, collection_operator::IN, std::move(ctx));
|
||||
return std::make_unique<collection_query_criteria>(col, collection_operator::In, std::move(ctx));
|
||||
}
|
||||
|
||||
criteria_ptr between(const sql::column &col, const int64_t min, const int64_t max) {
|
||||
|
|
|
|||
|
|
@ -41,9 +41,9 @@ void criteria_evaluator::visit(const between_criteria &node) {
|
|||
query_.bind_vars.emplace_back(node.column().name);
|
||||
query_.bind_vars.emplace_back(node.column().name);
|
||||
clause_ += dialect_.prepare_identifier(node.column()) + " " + dialect_.token_at(sql::dialect_token::Between) + " ";
|
||||
evaluate_value(node.min());
|
||||
evaluate_value(node.minimum());
|
||||
clause_ += " " + dialect_.token_at(sql::dialect_token::And) + " ";
|
||||
evaluate_value(node.max());
|
||||
evaluate_value(node.maximum());
|
||||
}
|
||||
|
||||
template<class... Ts> struct overload : Ts... { using Ts::operator()...; };
|
||||
|
|
@ -55,6 +55,10 @@ void criteria_evaluator::visit(const binary_criteria &node) {
|
|||
evaluate_value(node.value());
|
||||
}
|
||||
|
||||
void criteria_evaluator::visit( const binary_column_criteria& node ) {
|
||||
clause_ += dialect_.prepare_condition(node.left_column()) + " " + detail::BinaryOperatorEnum.to_string(node.operand()) + " " + dialect_.prepare_condition(node.right_column());
|
||||
}
|
||||
|
||||
void criteria_evaluator::visit(const collection_criteria &node) {
|
||||
const auto count = node.values().size();
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
|
|
@ -62,7 +66,7 @@ void criteria_evaluator::visit(const collection_criteria &node) {
|
|||
}
|
||||
|
||||
clause_ += dialect_.prepare_identifier(node.column()) +
|
||||
(node.operand() == collection_operator::OUT ? " " + dialect_.token_at(sql::dialect_token::Not) + " " : " ") +
|
||||
(node.operand() == collection_operator::Out ? " " + dialect_.token_at(sql::dialect_token::Not) + " " : " ") +
|
||||
dialect_.token_at(sql::dialect_token::In) + " (";
|
||||
if (node.values().size() < 2) {
|
||||
for (const auto &val: node.values()) {
|
||||
|
|
@ -81,7 +85,7 @@ void criteria_evaluator::visit(const collection_criteria &node) {
|
|||
|
||||
void criteria_evaluator::visit(const collection_query_criteria &node) {
|
||||
clause_ += dialect_.prepare_identifier(node.column()) +
|
||||
(node.operand() == collection_operator::OUT ? " " + dialect_.token_at(sql::dialect_token::Not) + " " : " ") +
|
||||
(node.operand() == collection_operator::Out ? " " + dialect_.token_at(sql::dialect_token::Not) + " " : " ") +
|
||||
dialect_.token_at(sql::dialect_token::In) + " (" +node.context().sql + ")";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@
|
|||
|
||||
namespace matador::query {
|
||||
|
||||
query_execute_where_intermediate query_delete_from_intermediate::where_clause(std::unique_ptr<basic_condition> &&cond)
|
||||
{
|
||||
query_execute_where_intermediate query_delete_from_intermediate::where_clause(std::unique_ptr<abstract_criteria> &&cond) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_where_part>(std::move(cond)));
|
||||
return {context_};
|
||||
}
|
||||
|
||||
query_execute_where_intermediate query_delete_from_intermediate::where( std::unique_ptr<abstract_criteria> cond ) {
|
||||
return where_clause(std::move(cond));
|
||||
}
|
||||
}
|
||||
|
|
@ -8,44 +8,42 @@
|
|||
|
||||
namespace matador::query {
|
||||
|
||||
query_join_intermediate query_from_intermediate::join_left(const sql::table &t)
|
||||
{
|
||||
query_join_intermediate query_from_intermediate::join_left(const sql::table &t) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_join_part>(t));
|
||||
return {context_};
|
||||
}
|
||||
|
||||
query_from_intermediate query_from_intermediate::join_left(join_data &data)
|
||||
{
|
||||
query_from_intermediate query_from_intermediate::join_left(join_data &data) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_join_part>(*data.join_table));
|
||||
context_->parts.push_back(std::make_unique<internal::query_on_part>(std::move(data.condition)));
|
||||
return {context_};
|
||||
}
|
||||
|
||||
query_from_intermediate query_from_intermediate::join_left(std::vector<join_data> &data_vector)
|
||||
{
|
||||
for (auto &data : data_vector) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_join_part>(*data.join_table));
|
||||
context_->parts.push_back(std::make_unique<internal::query_on_part>(std::move(data.condition)));
|
||||
query_from_intermediate query_from_intermediate::join_left(std::vector<join_data> &data_vector) {
|
||||
for (auto &[join_table, condition] : data_vector) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_join_part>(*join_table));
|
||||
context_->parts.push_back(std::make_unique<internal::query_on_part>(std::move(condition)));
|
||||
}
|
||||
return {context_};
|
||||
}
|
||||
|
||||
query_where_intermediate query_from_intermediate::where_clause(std::unique_ptr<basic_condition> &&cond)
|
||||
{
|
||||
query_where_intermediate query_from_intermediate::where( std::unique_ptr<abstract_criteria>&& cond ) {
|
||||
return where_clause(std::move(cond));
|
||||
}
|
||||
|
||||
query_where_intermediate query_from_intermediate::where_clause(std::unique_ptr<abstract_criteria> &&cond) {
|
||||
if (cond) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_where_part>(std::move(cond)));
|
||||
}
|
||||
return {context_};
|
||||
}
|
||||
|
||||
query_group_by_intermediate query_from_intermediate::group_by(const sql::column &col)
|
||||
{
|
||||
query_group_by_intermediate query_from_intermediate::group_by(const sql::column &col) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_group_by_part>(col));
|
||||
return {context_};
|
||||
}
|
||||
|
||||
query_order_by_intermediate query_from_intermediate::order_by(const sql::column &col)
|
||||
{
|
||||
query_order_by_intermediate query_from_intermediate::order_by(const sql::column &col) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_order_by_part>(col));
|
||||
return {context_};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,11 @@
|
|||
|
||||
namespace matador::query {
|
||||
|
||||
query_on_intermediate query_join_intermediate::on_clause(std::unique_ptr<basic_condition> &&cond)
|
||||
{
|
||||
query_on_intermediate query_join_intermediate::on( std::unique_ptr<abstract_criteria>&& cond ) {
|
||||
return on_clause(std::move(cond));
|
||||
}
|
||||
|
||||
query_on_intermediate query_join_intermediate::on_clause(std::unique_ptr<abstract_criteria> &&cond) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_on_part>(std::move(cond)));
|
||||
return {context_};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace matador::query {
|
||||
|
||||
query_execute_where_intermediate query_set_intermediate::where_clause(std::unique_ptr<basic_condition> &&cond)
|
||||
query_execute_where_intermediate query_set_intermediate::where_clause(std::unique_ptr<abstract_criteria> &&cond)
|
||||
{
|
||||
context_->parts.push_back(std::make_unique<internal::query_where_part>(std::move(cond)));
|
||||
return {context_};
|
||||
|
|
|
|||
|
|
@ -46,11 +46,11 @@ 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_on_part::query_on_part(std::unique_ptr<abstract_criteria> &&cond)
|
||||
: query_part(sql::dialect_token::On)
|
||||
, condition_(std::move(cond)) {}
|
||||
|
||||
const basic_condition &query_on_part::condition() const
|
||||
const abstract_criteria &query_on_part::condition() const
|
||||
{
|
||||
return *condition_;
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ 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_where_part::query_where_part(std::unique_ptr<abstract_criteria> &&cond)
|
||||
: query_part(sql::dialect_token::Where)
|
||||
, condition_(std::move(cond)) {}
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ void query_where_part::accept(query_part_visitor &visitor)
|
|||
visitor.visit(*this);
|
||||
}
|
||||
|
||||
const basic_condition &query_where_part::condition() const
|
||||
const abstract_criteria &query_where_part::condition() const
|
||||
{
|
||||
return *condition_;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "matador/query/attribute_string_writer.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
#include "matador/query/criteria_evaluator.hpp"
|
||||
|
||||
#include "matador/query/internal/basic_type_to_string_visitor.hpp"
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
|
|
@ -16,7 +17,7 @@ namespace matador::query {
|
|||
|
||||
sql::query_context query_compiler::compile(const query_data &data,
|
||||
const sql::dialect &d,
|
||||
std::optional<std::reference_wrapper<const sql::connection_impl>> conn)
|
||||
const std::optional<std::reference_wrapper<const sql::connection_impl>> conn)
|
||||
{
|
||||
data_ = &data;
|
||||
dialect_ = &d;
|
||||
|
|
@ -86,20 +87,19 @@ void query_compiler::visit(internal::query_join_part &join_part)
|
|||
query_.sql += " " + query_compiler::build_table_name(join_part.token(), *dialect_, join_part.table());
|
||||
}
|
||||
|
||||
void query_compiler::visit(internal::query_on_part &on_part)
|
||||
{
|
||||
void query_compiler::visit(internal::query_on_part &on_part) {
|
||||
criteria_evaluator evaluator(*dialect_, query_);
|
||||
query_.sql += " " + dialect_->token_at(sql::dialect_token::On) +
|
||||
" " + on_part.condition().evaluate(*dialect_, query_);
|
||||
" " + evaluator.evaluate(on_part.condition());
|
||||
}
|
||||
|
||||
void query_compiler::visit(internal::query_where_part &where_part)
|
||||
{
|
||||
void query_compiler::visit(internal::query_where_part &where_part) {
|
||||
criteria_evaluator evaluator(*dialect_, query_);
|
||||
query_.sql += " " + dialect_->token_at(sql::dialect_token::Where) +
|
||||
" " + where_part.condition().evaluate(*dialect_, query_);
|
||||
" " + evaluator.evaluate(where_part.condition());
|
||||
}
|
||||
|
||||
void query_compiler::visit(internal::query_group_by_part &group_by_part)
|
||||
{
|
||||
void query_compiler::visit(internal::query_group_by_part &group_by_part) {
|
||||
query_.sql += " " + dialect_->token_at(sql::dialect_token::GroupBy) + " " + dialect_->prepare_identifier(group_by_part.column());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ add_executable(OrmTests
|
|||
backend/test_statement.hpp
|
||||
orm/SessionInsertBuilderTest.cpp
|
||||
orm/SessionQueryBuilderTest.cpp
|
||||
query/ConditionTests.cpp
|
||||
query/QueryBuilderTest.cpp
|
||||
query/QueryFixture.cpp
|
||||
query/QueryFixture.hpp
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "matador/sql/column.hpp"
|
||||
#include "matador/sql/table.hpp"
|
||||
|
||||
#include "matador/query/criteria_evaluator.hpp"
|
||||
#include "matador/query/query.hpp"
|
||||
|
||||
#include "matador/orm/session_query_builder.hpp"
|
||||
|
|
@ -62,15 +63,16 @@ TEST_CASE("Create sql query data for entity with eager has one", "[query][entity
|
|||
|
||||
query_context qc;
|
||||
size_t index{0};
|
||||
for (const auto &jd : data->joins) {
|
||||
REQUIRE(jd.join_table->name == expected_join_data[index].first);
|
||||
REQUIRE(jd.condition->evaluate(db.dialect(), qc) == expected_join_data[index].second);
|
||||
criteria_evaluator evaluator(db.dialect(), qc);
|
||||
for (const auto &[join_table, condition] : data->joins) {
|
||||
REQUIRE(join_table->name == expected_join_data[index].first);
|
||||
REQUIRE(evaluator.evaluate(*condition) == expected_join_data[index].second);
|
||||
++index;
|
||||
}
|
||||
|
||||
REQUIRE(data->where_clause);
|
||||
auto cond = data->where_clause->evaluate(db.dialect(), qc);
|
||||
REQUIRE(cond == R"("t01"."id" = 17)");
|
||||
REQUIRE(data->where_clause.get());
|
||||
auto cond = evaluator.evaluate(*data->where_clause);
|
||||
REQUIRE(cond == R"("t01"."id" = ?)");
|
||||
}
|
||||
|
||||
TEST_CASE("Create sql query data for entity with eager belongs to", "[query][entity][builder]") {
|
||||
|
|
@ -111,15 +113,16 @@ TEST_CASE("Create sql query data for entity with eager belongs to", "[query][ent
|
|||
|
||||
query_context qc;
|
||||
size_t index{0};
|
||||
criteria_evaluator evaluator(db.dialect(), qc);
|
||||
for (const auto &jd : data->joins) {
|
||||
REQUIRE(jd.join_table->name == expected_join_data[index].first);
|
||||
REQUIRE(jd.condition->evaluate(db.dialect(), qc) == expected_join_data[index].second);
|
||||
REQUIRE(evaluator.evaluate(*jd.condition) == expected_join_data[index].second);
|
||||
++index;
|
||||
}
|
||||
|
||||
REQUIRE(data->where_clause);
|
||||
auto cond = data->where_clause->evaluate(db.dialect(), qc);
|
||||
REQUIRE(cond == R"("t01"."id" = 17)");
|
||||
REQUIRE(data->where_clause.get());
|
||||
auto cond = evaluator.evaluate(*data->where_clause);
|
||||
REQUIRE(cond == R"("t01"."id" = ?)");
|
||||
|
||||
auto q = matador::query::query::select(data->columns)
|
||||
.from(data->root_table->name);
|
||||
|
|
@ -180,15 +183,16 @@ TEST_CASE("Create sql query data for entity with eager has many belongs to", "[q
|
|||
|
||||
query_context qc;
|
||||
size_t index{0};
|
||||
criteria_evaluator evaluator(db.dialect(), qc);
|
||||
for (const auto &jd : data->joins) {
|
||||
REQUIRE(jd.join_table->name == expected_join_data[index].first);
|
||||
REQUIRE(jd.condition->evaluate(db.dialect(), qc) == expected_join_data[index].second);
|
||||
REQUIRE(evaluator.evaluate(*jd.condition) == expected_join_data[index].second);
|
||||
++index;
|
||||
}
|
||||
|
||||
REQUIRE(data->where_clause);
|
||||
auto cond = data->where_clause->evaluate(db.dialect(), qc);
|
||||
REQUIRE(cond == R"("t01"."order_id" = 17)");
|
||||
REQUIRE(data->where_clause.get());
|
||||
auto cond = evaluator.evaluate(*data->where_clause);
|
||||
REQUIRE(cond == R"("t01"."order_id" = ?)");
|
||||
}
|
||||
|
||||
TEST_CASE("Create sql query data for entity with eager many to many", "[query][entity][builder]") {
|
||||
|
|
@ -225,15 +229,16 @@ TEST_CASE("Create sql query data for entity with eager many to many", "[query][e
|
|||
|
||||
query_context qc;
|
||||
size_t index{0};
|
||||
criteria_evaluator evaluator(db.dialect(), qc);
|
||||
for (const auto &jd : data->joins) {
|
||||
REQUIRE(jd.join_table->name == expected_join_data[index].first);
|
||||
REQUIRE(jd.condition->evaluate(db.dialect(), qc) == expected_join_data[index].second);
|
||||
REQUIRE(evaluator.evaluate(*jd.condition) == expected_join_data[index].second);
|
||||
++index;
|
||||
}
|
||||
|
||||
REQUIRE(data->where_clause);
|
||||
auto cond = data->where_clause->evaluate(db.dialect(), qc);
|
||||
REQUIRE(cond == R"("t01"."id" = 17)");
|
||||
REQUIRE(data->where_clause.get());
|
||||
auto cond = evaluator.evaluate(*data->where_clause);
|
||||
REQUIRE(cond == R"("t01"."id" = ?)");
|
||||
}
|
||||
|
||||
TEST_CASE("Create sql query data for entity with eager many to many (inverse part)", "[query][entity][builder]") {
|
||||
|
|
@ -270,15 +275,16 @@ TEST_CASE("Create sql query data for entity with eager many to many (inverse par
|
|||
|
||||
query_context qc;
|
||||
size_t index{0};
|
||||
criteria_evaluator evaluator(db.dialect(), qc);
|
||||
for (const auto &jd : data->joins) {
|
||||
REQUIRE(jd.join_table->name == expected_join_data[index].first);
|
||||
REQUIRE(jd.condition->evaluate(db.dialect(), qc) == expected_join_data[index].second);
|
||||
REQUIRE(evaluator.evaluate(*jd.condition) == expected_join_data[index].second);
|
||||
++index;
|
||||
}
|
||||
|
||||
REQUIRE(data->where_clause);
|
||||
auto cond = data->where_clause->evaluate(db.dialect(), qc);
|
||||
REQUIRE(cond == R"("t01"."id" = 17)");
|
||||
REQUIRE(data->where_clause.get());
|
||||
auto cond = evaluator.evaluate(*data->where_clause);
|
||||
REQUIRE(cond == R"("t01"."id" = ?)");
|
||||
}
|
||||
|
||||
TEST_CASE("Test eager relationship", "[session][eager]") {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "QueryFixture.hpp"
|
||||
|
||||
#include <matador/query/condition.hpp>
|
||||
#include <matador/query/criteria.hpp>
|
||||
#include <matador/query/query.hpp>
|
||||
|
||||
#include "matador/object/attribute_definition_generator.hpp"
|
||||
|
|
|
|||
Loading…
Reference in New Issue