mirror of
https://github.com/getml/sqlgen.git
synced 2026-01-07 18:09:32 -06:00
Continued implementing the conditions
This commit is contained in:
@@ -11,8 +11,8 @@ namespace sqlgen::dynamic {
|
||||
|
||||
struct Condition {
|
||||
struct And {
|
||||
Ref<Condition> op1;
|
||||
Ref<Condition> op2;
|
||||
Ref<Condition> cond1;
|
||||
Ref<Condition> cond2;
|
||||
};
|
||||
|
||||
struct Equals {
|
||||
@@ -46,15 +46,15 @@ struct Condition {
|
||||
};
|
||||
|
||||
struct Or {
|
||||
Ref<Condition> op1;
|
||||
Ref<Condition> op2;
|
||||
Ref<Condition> cond1;
|
||||
Ref<Condition> cond2;
|
||||
};
|
||||
|
||||
using ReflectionType =
|
||||
rfl::TaggedUnion<"what", And, Equals, GreaterEqual, GreaterThan,
|
||||
NotEquals, LesserEqual, LesserThan, Or>;
|
||||
|
||||
ReflectionType reflection() const { return val; }
|
||||
const ReflectionType& reflection() const { return val; }
|
||||
|
||||
ReflectionType val;
|
||||
};
|
||||
|
||||
30
include/sqlgen/transpilation/Condition.hpp
Normal file
30
include/sqlgen/transpilation/Condition.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef SQLGEN_TRANSPILATION_CONDITION_HPP_
|
||||
#define SQLGEN_TRANSPILATION_CONDITION_HPP_
|
||||
|
||||
#include "conditions.hpp"
|
||||
|
||||
namespace sqlgen::transpilation {
|
||||
|
||||
template <class _ConditionType>
|
||||
struct Condition {
|
||||
using ConditionType = _ConditionType;
|
||||
ConditionType condition;
|
||||
};
|
||||
|
||||
template <class C1, class C2>
|
||||
auto operator&&(const Condition<C1>& _lhs, const Condition<C2>& _rhs) {
|
||||
return Condition<conditions::And<C1, C2>>{
|
||||
.condition = conditions::And<C1, C2>{.lhs = _lhs.condition,
|
||||
.rhs = _rhs.condition}};
|
||||
}
|
||||
|
||||
template <class C1, class C2>
|
||||
auto operator||(const Condition<C1>& _lhs, const Condition<C2>& _rhs) {
|
||||
return Condition<conditions::Or<C1, C2>>{
|
||||
.condition =
|
||||
conditions::Or<C1, C2>{.lhs = _lhs.condition, .rhs = _rhs.condition}};
|
||||
}
|
||||
|
||||
} // namespace sqlgen::transpilation
|
||||
|
||||
#endif
|
||||
13
include/sqlgen/transpilation/Value.hpp
Normal file
13
include/sqlgen/transpilation/Value.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef SQLGEN_TRANSPILATION_VALUE_HPP_
|
||||
#define SQLGEN_TRANSPILATION_VALUE_HPP_
|
||||
|
||||
namespace sqlgen::transpilation {
|
||||
|
||||
template <class T>
|
||||
struct Value {
|
||||
T val;
|
||||
};
|
||||
|
||||
} // namespace sqlgen::transpilation
|
||||
|
||||
#endif
|
||||
56
include/sqlgen/transpilation/conditions.hpp
Normal file
56
include/sqlgen/transpilation/conditions.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef SQLGEN_TRANSPILATION_CONDITIONS_HPP_
|
||||
#define SQLGEN_TRANSPILATION_CONDITIONS_HPP_
|
||||
|
||||
namespace sqlgen::transpilation::conditions {
|
||||
|
||||
template <class CondType1, class CondType2>
|
||||
struct And {
|
||||
CondType1 cond1;
|
||||
CondType2 cond2;
|
||||
};
|
||||
|
||||
template <class OpType1, class OpType2>
|
||||
struct Equals {
|
||||
OpType1 op1;
|
||||
OpType2 op2;
|
||||
};
|
||||
|
||||
template <class OpType1, class OpType2>
|
||||
struct GreaterEqual {
|
||||
OpType1 op1;
|
||||
OpType2 op2;
|
||||
};
|
||||
|
||||
template <class OpType1, class OpType2>
|
||||
struct GreaterThan {
|
||||
OpType1 op1;
|
||||
OpType2 op2;
|
||||
};
|
||||
|
||||
template <class OpType1, class OpType2>
|
||||
struct NotEquals {
|
||||
OpType1 op1;
|
||||
OpType2 op2;
|
||||
};
|
||||
|
||||
template <class OpType1, class OpType2>
|
||||
struct LesserEqual {
|
||||
OpType1 op1;
|
||||
OpType2 op2;
|
||||
};
|
||||
|
||||
template <class OpType1, class OpType2>
|
||||
struct LesserThan {
|
||||
OpType1 op1;
|
||||
OpType2 op2;
|
||||
};
|
||||
|
||||
template <class CondType1, class CondType2>
|
||||
struct Or {
|
||||
CondType1 cond1;
|
||||
CondType2 cond2;
|
||||
};
|
||||
|
||||
} // namespace sqlgen::transpilation::conditions
|
||||
|
||||
#endif
|
||||
60
include/sqlgen/transpilation/to_condition.hpp
Normal file
60
include/sqlgen/transpilation/to_condition.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#ifndef SQLGEN_TRANSPILATION_TO_CONDITION_HPP_
|
||||
#define SQLGEN_TRANSPILATION_TO_CONDITION_HPP_
|
||||
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "../Ref.hpp"
|
||||
#include "../Result.hpp"
|
||||
#include "../dynamic/Condition.hpp"
|
||||
#include "Condition.hpp"
|
||||
#include "conditions.hpp"
|
||||
|
||||
namespace sqlgen::transpilation {
|
||||
|
||||
template <class T, class ConditionType>
|
||||
struct ToCondition;
|
||||
|
||||
template <class T, class CondType>
|
||||
struct ToCondition<T, Condition<CondType>> {
|
||||
dynamic::Condition operator()(const Condition<CondType>& _cond) const {
|
||||
return ToCondition<T, std::remove_cvref_t<CondType>>{}(_cond.condition);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class CondType1, class CondType2>
|
||||
struct ToCondition<T, conditions::And<CondType1, CondType2>> {
|
||||
dynamic::Condition operator()(
|
||||
const conditions::And<CondType1, CondType2>& _cond) const {
|
||||
return dynamic::Condition{
|
||||
.val = dynamic::Condition::And{
|
||||
.cond1 = Ref<dynamic::Condition>::make(
|
||||
ToCondition<T, std::remove_cvref_t<CondType1>>{}(_cond.lhs)),
|
||||
.cond2 = Ref<dynamic::Condition>::make(
|
||||
ToCondition<T, std::remove_cvref_t<CondType2>>{}(_cond.rhs)),
|
||||
}};
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class CondType1, class CondType2>
|
||||
struct ToCondition<T, conditions::Or<CondType1, CondType2>> {
|
||||
dynamic::Condition operator()(
|
||||
const conditions::Or<CondType1, CondType2>& _cond) const {
|
||||
return dynamic::Condition{
|
||||
.val = dynamic::Condition::Or{
|
||||
.cond1 = Ref<dynamic::Condition>::make(
|
||||
ToCondition<T, std::remove_cvref_t<CondType1>>{}(_cond.lhs)),
|
||||
.cond2 = Ref<dynamic::Condition>::make(
|
||||
ToCondition<T, std::remove_cvref_t<CondType2>>{}(_cond.rhs)),
|
||||
}};
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class ConditionType>
|
||||
dynamic::Condition to_condition(const ConditionType& _cond) {
|
||||
return ToCondition<T, std::remove_cvref_t<ConditionType>>{}(_cond);
|
||||
}
|
||||
|
||||
} // namespace sqlgen::transpilation
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user