111 lines
4.3 KiB
C++
111 lines
4.3 KiB
C++
#ifndef CRITERIA_CRITERIA_OPERATORS_HPP
|
|
#define CRITERIA_CRITERIA_OPERATORS_HPP
|
|
|
|
#include "matador/query/criteria/binary_criteria.hpp"
|
|
#include "matador/query/criteria/collection_criteria.hpp"
|
|
#include "matador/query/intermediates/fetchable_query.hpp"
|
|
|
|
#include "matador/utils/placeholder.hpp"
|
|
#include "matador/utils/value.hpp"
|
|
|
|
namespace matador::utils {
|
|
class identifier;
|
|
}
|
|
namespace matador::sql {
|
|
struct query_context;
|
|
}
|
|
namespace matador::query {
|
|
class table_column;
|
|
|
|
template<class Type>
|
|
std::enable_if_t<!std::is_base_of_v<fetchable_query, std::decay_t<Type>>, criteria_ptr>
|
|
operator==(const table_column &col, Type val) {
|
|
return std::make_unique<binary_criteria>(col, binary_operator::EQUALS, utils::value(val));
|
|
}
|
|
|
|
template<class Type>
|
|
std::enable_if_t<!std::is_base_of_v<fetchable_query, std::decay_t<Type>>, criteria_ptr>
|
|
operator!=(const table_column &col, Type val) {
|
|
return std::make_unique<binary_criteria>(col, binary_operator::NOT_EQUALS, utils::value(val));
|
|
}
|
|
|
|
template<class Type>
|
|
criteria_ptr operator>(const table_column &col, Type val) {
|
|
return std::make_unique<binary_criteria>(col, binary_operator::GREATER_THAN, utils::value(val));
|
|
}
|
|
|
|
template<class Type>
|
|
criteria_ptr operator>=(const table_column &col, Type val) {
|
|
return std::make_unique<binary_criteria>(col, binary_operator::GREATER_THAN_OR_EQUAL, utils::value(val));
|
|
}
|
|
|
|
template<class Type>
|
|
criteria_ptr operator<(const table_column &col, Type val) {
|
|
return std::make_unique<binary_criteria>(col, binary_operator::LESS_THAN, utils::value(val));
|
|
}
|
|
|
|
template<class Type>
|
|
criteria_ptr operator<=(const table_column &col, Type val) {
|
|
return std::make_unique<binary_criteria>(col, binary_operator::LESS_THAN_OR_EQUAL, utils::value(val));
|
|
}
|
|
|
|
criteria_ptr operator==(const table_column &col_left, const table_column &col_right);
|
|
criteria_ptr operator!=(const table_column &col_left, const table_column &col_right);
|
|
criteria_ptr operator>(const table_column &col_left, const table_column &col_right);
|
|
criteria_ptr operator>=(const table_column &col_left, const table_column &col_right);
|
|
criteria_ptr operator<(const table_column &col_left, const table_column &col_right);
|
|
criteria_ptr operator<=(const table_column &col_left, const table_column &col_right);
|
|
|
|
criteria_ptr operator==(const table_column &col, utils::placeholder p);
|
|
criteria_ptr operator!=(const table_column &col, utils::placeholder p);
|
|
criteria_ptr operator>(const table_column &col, utils::placeholder p);
|
|
criteria_ptr operator>=(const table_column &col, utils::placeholder p);
|
|
criteria_ptr operator<(const table_column &col, utils::placeholder p);
|
|
criteria_ptr operator<=(const table_column &col, utils::placeholder p);
|
|
|
|
criteria_ptr operator==(const table_column &col, const utils::identifier &id);
|
|
criteria_ptr operator!=(const table_column &col, const utils::identifier &id);
|
|
|
|
criteria_ptr operator&&(criteria_ptr left, criteria_ptr right);
|
|
|
|
criteria_ptr operator||(criteria_ptr left, criteria_ptr right);
|
|
|
|
criteria_ptr operator!(criteria_ptr clause);
|
|
|
|
template < class Type >
|
|
criteria_ptr in(const table_column &col, std::initializer_list<Type> args) {
|
|
std::vector<criteria_value> values;
|
|
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));
|
|
}
|
|
|
|
template <>
|
|
criteria_ptr in(const table_column &col, std::initializer_list<utils::placeholder> args);
|
|
|
|
criteria_ptr in(const table_column &col, fetchable_query &&q);
|
|
|
|
template < class Type >
|
|
criteria_ptr out(const table_column &col, std::initializer_list<Type> args) {
|
|
std::vector<criteria_value> values;
|
|
for ( auto &&arg : args ) {
|
|
values.emplace_back(utils::value{std::move(arg)});
|
|
}
|
|
return std::make_unique<collection_criteria>(col, collection_operator::Out, values);
|
|
}
|
|
|
|
template <>
|
|
criteria_ptr out(const table_column &col, std::initializer_list<utils::placeholder> args);
|
|
criteria_ptr out(const table_column &col, fetchable_query &&q);
|
|
|
|
criteria_ptr between(const table_column &col, int64_t min, int64_t max);
|
|
criteria_ptr between(const table_column &col, utils::placeholder min, utils::placeholder max);
|
|
|
|
criteria_ptr like(const table_column &col, const std::string &pattern);
|
|
|
|
criteria_ptr is_null(const table_column &col);
|
|
criteria_ptr is_not_null(const table_column &col);
|
|
|
|
}
|
|
#endif //CRITERIA_CRITERIA_OPERATORS_HPP
|