94 lines
3.3 KiB
C++
94 lines
3.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/sql/column.hpp"
|
|
|
|
#include "matador/utils/placeholder.hpp"
|
|
#include "matador/utils/value.hpp"
|
|
|
|
namespace matador::sql {
|
|
struct query_context;
|
|
}
|
|
namespace matador::query {
|
|
|
|
template<class Type>
|
|
criteria_ptr operator==(const sql::column &col, Type val) {
|
|
return std::make_unique<binary_criteria>(col, binary_operator::EQUALS, utils::value(val));
|
|
}
|
|
|
|
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));
|
|
}
|
|
|
|
template<class Type>
|
|
criteria_ptr operator>(const sql::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 sql::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 sql::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 sql::column &col, Type val) {
|
|
return std::make_unique<binary_criteria>(col, binary_operator::LESS_THAN_OR_EQUAL, utils::value(val));
|
|
}
|
|
|
|
criteria_ptr operator==(const sql::column &col, utils::placeholder p);
|
|
criteria_ptr operator!=(const sql::column &col, utils::placeholder p);
|
|
criteria_ptr operator>(const sql::column &col, utils::placeholder p);
|
|
criteria_ptr operator>=(const sql::column &col, utils::placeholder p);
|
|
criteria_ptr operator<(const sql::column &col, utils::placeholder p);
|
|
criteria_ptr operator<=(const sql::column &col, utils::placeholder p);
|
|
|
|
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 sql::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 sql::column &col, std::initializer_list<utils::placeholder> args);
|
|
|
|
criteria_ptr in(const sql::column &col, sql::query_context &&ctx);
|
|
|
|
template < class Type >
|
|
criteria_ptr out(const sql::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 sql::column &col, std::initializer_list<utils::placeholder> args);
|
|
|
|
criteria_ptr out(const sql::column &col, sql::query_context &&ctx);
|
|
|
|
criteria_ptr between(const sql::column &col, int64_t min, int64_t max);
|
|
criteria_ptr between(const sql::column &col, utils::placeholder min, utils::placeholder max);
|
|
|
|
criteria_ptr like(const sql::column &col, const std::string &pattern);
|
|
|
|
}
|
|
#endif //CRITERIA_CRITERIA_OPERATORS_HPP
|