criteria progress
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#include "matador/query/criteria/check_null_criteria.hpp"
|
||||
|
||||
#include "matador/query/criteria/criteria_visitor.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
check_null_criteria::check_null_criteria(const table_column& col, const check_null_operator op)
|
||||
: abstract_column_criteria(col)
|
||||
, operator_{op} {}
|
||||
|
||||
void check_null_criteria::accept(criteria_visitor& visitor) const {
|
||||
visitor.visit(*this);
|
||||
}
|
||||
check_null_operator check_null_criteria::operand() const {
|
||||
return operator_;
|
||||
}
|
||||
} // namespace matador::query
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "matador/query/criteria/criteria_operators.hpp"
|
||||
|
||||
#include "matador/query/criteria/between_criteria.hpp"
|
||||
#include "matador/query/criteria/check_null_criteria.hpp"
|
||||
#include "matador/query/criteria/like_criteria.hpp"
|
||||
#include "matador/query/criteria/logical_criteria.hpp"
|
||||
#include "matador/query/criteria/not_criteria.hpp"
|
||||
@@ -118,4 +119,11 @@ criteria_ptr between(const table_column &col, utils::placeholder min, utils::pla
|
||||
criteria_ptr like(const table_column &col, const std::string &pattern) {
|
||||
return std::make_unique<like_criteria>(col, pattern);
|
||||
}
|
||||
|
||||
criteria_ptr is_null(const table_column &col) {
|
||||
return std::make_unique<check_null_criteria>(col, check_null_operator::IsNull);
|
||||
}
|
||||
criteria_ptr is_not_null(const table_column &col) {
|
||||
return std::make_unique<check_null_criteria>(col, check_null_operator::IsNotNull);
|
||||
}
|
||||
} // namespace matador::query
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
#include "matador/query/criteria_evaluator.hpp"
|
||||
|
||||
#include "matador/query/query_utils.hpp"
|
||||
#include "matador/query/criteria/between_criteria.hpp"
|
||||
#include "matador/query/criteria/binary_criteria.hpp"
|
||||
#include "matador/query/criteria/check_null_criteria.hpp"
|
||||
#include "matador/query/criteria/collection_criteria.hpp"
|
||||
#include "matador/query/criteria/like_criteria.hpp"
|
||||
#include "matador/query/criteria/logical_criteria.hpp"
|
||||
#include "matador/query/criteria/not_criteria.hpp"
|
||||
|
||||
#include "matador/query/query_utils.hpp"
|
||||
#include "matador/sql/dialect.hpp"
|
||||
#include "matador/sql/query_context.hpp"
|
||||
|
||||
#include "matador/utils/value.hpp"
|
||||
#include "matador/utils/enum_mapper.hpp"
|
||||
#include "matador/utils/value.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
namespace detail {
|
||||
@@ -61,6 +60,14 @@ void criteria_evaluator::visit( const binary_column_criteria& node ) {
|
||||
clause_ += prepare_criteria(dialect_, node.left_column()) + " " + detail::BinaryOperatorEnum.to_string(node.operand()) + " " + prepare_criteria(dialect_, node.right_column());
|
||||
}
|
||||
|
||||
void criteria_evaluator::visit(const check_null_criteria &node) {
|
||||
clause_ += prepare_identifier(dialect_, node.col()) + " ";
|
||||
if (node.operand() == check_null_operator::IsNull)
|
||||
clause_ += dialect_.is_null();
|
||||
else
|
||||
clause_ += dialect_.is_not_null();
|
||||
}
|
||||
|
||||
void criteria_evaluator::visit(const collection_criteria &node) {
|
||||
const auto count = node.values().size();
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
|
||||
@@ -10,19 +10,24 @@
|
||||
namespace matador::query {
|
||||
|
||||
query_join_intermediate query_from_intermediate::join_left(const table &t) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_join_part>(t));
|
||||
context_->parts.push_back(std::make_unique<internal::query_join_table_part>(t));
|
||||
return {context_};
|
||||
}
|
||||
|
||||
query_join_intermediate query_from_intermediate::join_left(const fetchable_query &q) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_join_query_part>(q));
|
||||
return {context_};
|
||||
}
|
||||
|
||||
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_join_table_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 &[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_join_table_part>(*join_table));
|
||||
context_->parts.push_back(std::make_unique<internal::query_on_part>(std::move(condition)));
|
||||
}
|
||||
return {context_};
|
||||
|
||||
@@ -147,16 +147,29 @@ void query_from_part::accept(query_part_visitor &visitor) {
|
||||
visitor.visit(*this);
|
||||
}
|
||||
|
||||
query_join_part::query_join_part(class table tab)
|
||||
query_join_table_part::query_join_table_part(class table tab)
|
||||
: query_part(sql::dialect_token::Join)
|
||||
, table_(std::move(tab)) {
|
||||
}
|
||||
|
||||
const table &query_join_part::table() const {
|
||||
const table &query_join_table_part::table() const {
|
||||
return table_;
|
||||
}
|
||||
|
||||
void query_join_part::accept(query_part_visitor &visitor) {
|
||||
void query_join_table_part::accept(query_part_visitor &visitor) {
|
||||
visitor.visit(*this);
|
||||
}
|
||||
|
||||
query_join_query_part::query_join_query_part(fetchable_query q)
|
||||
: query_part(sql::dialect_token::Join)
|
||||
, query_(std::move(q))
|
||||
{}
|
||||
|
||||
const fetchable_query &query_join_query_part::query() const {
|
||||
return query_;
|
||||
}
|
||||
|
||||
void query_join_query_part::accept(query_part_visitor &visitor) {
|
||||
visitor.visit(*this);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,6 @@
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
table_column alias(const std::string &column, const std::string &as) {
|
||||
return {column, as};
|
||||
}
|
||||
|
||||
table_column alias(table_column &&col, const std::string &as) {
|
||||
col.as(as);
|
||||
return col;
|
||||
}
|
||||
|
||||
table_column count(const std::string &column) {
|
||||
return {sql::sql_function_t::Count, column};
|
||||
}
|
||||
@@ -18,6 +9,18 @@ table_column count(const std::string &column) {
|
||||
table_column count_all() {
|
||||
return count("*");
|
||||
}
|
||||
table_column sum(const std::string& column) {
|
||||
return {sql::sql_function_t::Sum, column};
|
||||
}
|
||||
table_column avg(const std::string& column) {
|
||||
return {sql::sql_function_t::Avg, column};
|
||||
}
|
||||
table_column max(const std::string& column) {
|
||||
return {sql::sql_function_t::Max, column};
|
||||
}
|
||||
table_column min(const std::string& column) {
|
||||
return {sql::sql_function_t::Min, column};
|
||||
}
|
||||
|
||||
query_create_intermediate query::create()
|
||||
{
|
||||
|
||||
@@ -15,6 +15,10 @@ void criteria_transformer::visit( const binary_criteria& node ) {
|
||||
|
||||
void criteria_transformer::visit( const binary_column_criteria& /*node*/ ) {}
|
||||
|
||||
void criteria_transformer::visit(const check_null_criteria& node) {
|
||||
update_criteria_column(node);
|
||||
}
|
||||
|
||||
void criteria_transformer::visit( const collection_criteria& node ) {
|
||||
update_criteria_column(node);
|
||||
}
|
||||
|
||||
@@ -174,10 +174,14 @@ void query_compiler::visit(internal::query_from_part &part) {
|
||||
}
|
||||
}
|
||||
|
||||
void query_compiler::visit(internal::query_join_part &part) {
|
||||
void query_compiler::visit(internal::query_join_table_part &part) {
|
||||
query_.sql += " " + build_table_name(part.token(), *dialect_, part.table());
|
||||
}
|
||||
|
||||
void query_compiler::visit(internal::query_join_query_part &part) {
|
||||
query_.sql += " " + dialect_->join() + " (" + part.query().str(*dialect_) + ")";
|
||||
}
|
||||
|
||||
void query_compiler::visit(internal::query_on_part &part) {
|
||||
criteria_evaluator evaluator(*dialect_, query_);
|
||||
query_.sql += " " + dialect_->on() +
|
||||
|
||||
@@ -91,9 +91,8 @@ bool table_column::equals(const table_column &x) const {
|
||||
function_ == x.function_;
|
||||
}
|
||||
|
||||
table_column table_column::as(std::string a) {
|
||||
alias_ = std::move(a);
|
||||
return {table_, name_, alias_, type_, attributes_, function_};
|
||||
table_column table_column::as(const std::string& alias) const {
|
||||
return {table_, name_, alias, type_, attributes_, function_};
|
||||
}
|
||||
|
||||
const std::string& table_column::name() const {
|
||||
|
||||
Reference in New Issue
Block a user