Skip to content

Commit

Permalink
Merge pull request #1338 from fnc12/amend-cte
Browse files Browse the repository at this point in the history
CTEs for the rest of CRUD statements
  • Loading branch information
trueqbit authored Jul 24, 2024
2 parents 37c2ac6 + 0d3e1f7 commit 662f4e0
Show file tree
Hide file tree
Showing 17 changed files with 319 additions and 178 deletions.
3 changes: 2 additions & 1 deletion dev/ast/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ namespace sqlite_orm {
void push_back(assign_t<L, R> assign) {
auto newContext = this->context;
newContext.skip_table_name = true;
iterate_ast(assign, this->collector);
// note: we are only interested in the table name on the left-hand side of the assignment operator expression
iterate_ast(assign.lhs, this->collector);
std::stringstream ss;
ss << serialize(assign.lhs, newContext) << ' ' << assign.serialize() << ' '
<< serialize(assign.rhs, context);
Expand Down
4 changes: 2 additions & 2 deletions dev/ast/where.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace sqlite_orm {

expression_type expression;

where_t(expression_type expression_) : expression(std::move(expression_)) {}
constexpr where_t(expression_type expression_) : expression(std::move(expression_)) {}
};

template<class T>
Expand All @@ -46,7 +46,7 @@ namespace sqlite_orm {
* auto rows = storage.select(&Letter::name, where(greater_than(&Letter::id, 3)));
*/
template<class C>
internal::where_t<C> where(C expression) {
constexpr internal::where_t<C> where(C expression) {
return {std::move(expression)};
}
}
56 changes: 28 additions & 28 deletions dev/conditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace sqlite_orm {
struct negated_condition_t : condition_t, negated_condition_string {
C c;

negated_condition_t(C c_) : c(std::move(c_)) {}
constexpr negated_condition_t(C c_) : c(std::move(c_)) {}
};

/**
Expand All @@ -132,9 +132,9 @@ namespace sqlite_orm {
left_type lhs;
right_type rhs;

binary_condition() = default;
constexpr binary_condition() = default;

binary_condition(left_type l_, right_type r_) : lhs(std::move(l_)), rhs(std::move(r_)) {}
constexpr binary_condition(left_type l_, right_type r_) : lhs(std::move(l_)), rhs(std::move(r_)) {}
};

template<class T>
Expand Down Expand Up @@ -849,7 +849,7 @@ namespace sqlite_orm {
class T,
std::enable_if_t<polyfill::disjunction<std::is_base_of<negatable_t, T>, is_operator_argument<T>>::value,
bool> = true>
negated_condition_t<T> operator!(T arg) {
constexpr negated_condition_t<T> operator!(T arg) {
return {std::move(arg)};
}

Expand All @@ -860,7 +860,7 @@ namespace sqlite_orm {
is_operator_argument<L>,
is_operator_argument<R>>::value,
bool> = true>
less_than_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator<(L l, R r) {
constexpr less_than_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator<(L l, R r) {
return {get_from_expression(std::forward<L>(l)), get_from_expression(std::forward<R>(r))};
}

Expand All @@ -871,7 +871,7 @@ namespace sqlite_orm {
is_operator_argument<L>,
is_operator_argument<R>>::value,
bool> = true>
less_or_equal_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator<=(L l, R r) {
constexpr less_or_equal_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator<=(L l, R r) {
return {get_from_expression(std::forward<L>(l)), get_from_expression(std::forward<R>(r))};
}

Expand All @@ -882,7 +882,7 @@ namespace sqlite_orm {
is_operator_argument<L>,
is_operator_argument<R>>::value,
bool> = true>
greater_than_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator>(L l, R r) {
constexpr greater_than_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator>(L l, R r) {
return {get_from_expression(std::forward<L>(l)), get_from_expression(std::forward<R>(r))};
}

Expand All @@ -893,7 +893,7 @@ namespace sqlite_orm {
is_operator_argument<L>,
is_operator_argument<R>>::value,
bool> = true>
greater_or_equal_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator>=(L l, R r) {
constexpr greater_or_equal_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator>=(L l, R r) {
return {get_from_expression(std::forward<L>(l)), get_from_expression(std::forward<R>(r))};
}

Expand All @@ -906,7 +906,7 @@ namespace sqlite_orm {
is_operator_argument<L>,
is_operator_argument<R>>::value,
bool> = true>
is_equal_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator==(L l, R r) {
constexpr is_equal_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator==(L l, R r) {
return {get_from_expression(std::forward<L>(l)), get_from_expression(std::forward<R>(r))};
}

Expand All @@ -919,7 +919,7 @@ namespace sqlite_orm {
is_operator_argument<L>,
is_operator_argument<R>>::value,
bool> = true>
is_not_equal_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator!=(L l, R r) {
constexpr is_not_equal_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator!=(L l, R r) {
return {get_from_expression(std::forward<L>(l)), get_from_expression(std::forward<R>(r))};
}

Expand All @@ -930,7 +930,7 @@ namespace sqlite_orm {
is_operator_argument<L>,
is_operator_argument<R>>::value,
bool> = true>
and_condition_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator&&(L l, R r) {
constexpr and_condition_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator&&(L l, R r) {
return {get_from_expression(std::forward<L>(l)), get_from_expression(std::forward<R>(r))};
}

Expand All @@ -939,7 +939,7 @@ namespace sqlite_orm {
std::enable_if_t<
polyfill::disjunction<std::is_base_of<condition_t, L>, std::is_base_of<condition_t, R>>::value,
bool> = true>
or_condition_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator||(L l, R r) {
constexpr or_condition_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator||(L l, R r) {
return {get_from_expression(std::forward<L>(l)), get_from_expression(std::forward<R>(r))};
}

Expand All @@ -955,7 +955,7 @@ namespace sqlite_orm {
polyfill::negation<polyfill::disjunction<std::is_base_of<condition_t, L>,
std::is_base_of<condition_t, R>>>>::value,
bool> = true>
conc_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator||(L l, R r) {
constexpr conc_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator||(L l, R r) {
return {get_from_expression(std::forward<L>(l)), get_from_expression(std::forward<R>(r))};
}
}
Expand Down Expand Up @@ -1053,14 +1053,14 @@ namespace sqlite_orm {
}

template<class L, class R>
auto and_(L l, R r) {
constexpr auto and_(L l, R r) {
using namespace ::sqlite_orm::internal;
return and_condition_t<unwrap_expression_t<L>, unwrap_expression_t<R>>{get_from_expression(std::forward<L>(l)),
get_from_expression(std::forward<R>(r))};
}

template<class L, class R>
auto or_(L l, R r) {
constexpr auto or_(L l, R r) {
using namespace ::sqlite_orm::internal;
return or_condition_t<unwrap_expression_t<L>, unwrap_expression_t<R>>{get_from_expression(std::forward<L>(l)),
get_from_expression(std::forward<R>(r))};
Expand Down Expand Up @@ -1107,52 +1107,52 @@ namespace sqlite_orm {
}

template<class L, class R>
internal::is_equal_t<L, R> is_equal(L l, R r) {
constexpr internal::is_equal_t<L, R> is_equal(L l, R r) {
return {std::move(l), std::move(r)};
}

template<class L, class R>
internal::is_equal_t<L, R> eq(L l, R r) {
constexpr internal::is_equal_t<L, R> eq(L l, R r) {
return {std::move(l), std::move(r)};
}

template<class L, class R>
internal::is_equal_with_table_t<L, R> is_equal(R rhs) {
constexpr internal::is_equal_with_table_t<L, R> is_equal(R rhs) {
return {std::move(rhs)};
}

template<class L, class R>
internal::is_not_equal_t<L, R> is_not_equal(L l, R r) {
constexpr internal::is_not_equal_t<L, R> is_not_equal(L l, R r) {
return {std::move(l), std::move(r)};
}

template<class L, class R>
internal::is_not_equal_t<L, R> ne(L l, R r) {
constexpr internal::is_not_equal_t<L, R> ne(L l, R r) {
return {std::move(l), std::move(r)};
}

template<class L, class R>
internal::greater_than_t<L, R> greater_than(L l, R r) {
constexpr internal::greater_than_t<L, R> greater_than(L l, R r) {
return {std::move(l), std::move(r)};
}

template<class L, class R>
internal::greater_than_t<L, R> gt(L l, R r) {
constexpr internal::greater_than_t<L, R> gt(L l, R r) {
return {std::move(l), std::move(r)};
}

template<class L, class R>
internal::greater_or_equal_t<L, R> greater_or_equal(L l, R r) {
constexpr internal::greater_or_equal_t<L, R> greater_or_equal(L l, R r) {
return {std::move(l), std::move(r)};
}

template<class L, class R>
internal::greater_or_equal_t<L, R> ge(L l, R r) {
constexpr internal::greater_or_equal_t<L, R> ge(L l, R r) {
return {std::move(l), std::move(r)};
}

template<class L, class R>
internal::less_than_t<L, R> less_than(L l, R r) {
constexpr internal::less_than_t<L, R> less_than(L l, R r) {
return {std::move(l), std::move(r)};
}

Expand All @@ -1166,12 +1166,12 @@ namespace sqlite_orm {
}

template<class L, class R>
internal::less_than_t<L, R> lt(L l, R r) {
constexpr internal::less_than_t<L, R> lt(L l, R r) {
return {std::move(l), std::move(r)};
}

template<class L, class R>
internal::less_or_equal_t<L, R> less_or_equal(L l, R r) {
constexpr internal::less_or_equal_t<L, R> less_or_equal(L l, R r) {
return {std::move(l), std::move(r)};
}

Expand All @@ -1185,7 +1185,7 @@ namespace sqlite_orm {
}

template<class L, class R>
internal::less_or_equal_t<L, R> le(L l, R r) {
constexpr internal::less_or_equal_t<L, R> le(L l, R r) {
return {std::move(l), std::move(r)};
}

Expand Down
10 changes: 5 additions & 5 deletions dev/core_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,7 @@ namespace sqlite_orm {
is_operator_argument<L>,
is_operator_argument<R>>::value,
bool> = true>
add_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator+(L l, R r) {
constexpr add_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator+(L l, R r) {
return {get_from_expression(std::forward<L>(l)), get_from_expression(std::forward<R>(r))};
}

Expand All @@ -2059,7 +2059,7 @@ namespace sqlite_orm {
is_operator_argument<L>,
is_operator_argument<R>>::value,
bool> = true>
sub_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator-(L l, R r) {
constexpr sub_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator-(L l, R r) {
return {get_from_expression(std::forward<L>(l)), get_from_expression(std::forward<R>(r))};
}

Expand All @@ -2070,7 +2070,7 @@ namespace sqlite_orm {
is_operator_argument<L>,
is_operator_argument<R>>::value,
bool> = true>
mul_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator*(L l, R r) {
constexpr mul_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator*(L l, R r) {
return {get_from_expression(std::forward<L>(l)), get_from_expression(std::forward<R>(r))};
}

Expand All @@ -2081,7 +2081,7 @@ namespace sqlite_orm {
is_operator_argument<L>,
is_operator_argument<R>>::value,
bool> = true>
div_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator/(L l, R r) {
constexpr div_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator/(L l, R r) {
return {get_from_expression(std::forward<L>(l)), get_from_expression(std::forward<R>(r))};
}

Expand All @@ -2092,7 +2092,7 @@ namespace sqlite_orm {
is_operator_argument<L>,
is_operator_argument<R>>::value,
bool> = true>
mod_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator%(L l, R r) {
constexpr mod_t<unwrap_expression_t<L>, unwrap_expression_t<R>> operator%(L l, R r) {
return {get_from_expression(std::forward<L>(l)), get_from_expression(std::forward<R>(r))};
}
}
Expand Down
4 changes: 2 additions & 2 deletions dev/cte_moniker.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace sqlite_orm {
std::same_as<ExplicitCols, std::remove_cvref_t<decltype(std::ignore)>> ||
std::convertible_to<ExplicitCols, std::string>) &&
...)
auto operator()(ExplicitCols... explicitColumns) const;
constexpr auto operator()(ExplicitCols... explicitColumns) const;
#else
template<class... ExplicitCols,
std::enable_if_t<polyfill::conjunction_v<polyfill::disjunction<
Expand All @@ -59,7 +59,7 @@ namespace sqlite_orm {
std::is_same<ExplicitCols, polyfill::remove_cvref_t<decltype(std::ignore)>>,
std::is_convertible<ExplicitCols, std::string>>...>,
bool> = true>
auto operator()(ExplicitCols... explicitColumns) const;
constexpr auto operator()(ExplicitCols... explicitColumns) const;
#endif
};
}
Expand Down
6 changes: 3 additions & 3 deletions dev/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ namespace sqlite_orm {
is_operator_argument_v<T, std::enable_if_t<polyfill::is_specialization_of<T, expression_t>::value>> = true;

template<class T>
T get_from_expression(T value) {
constexpr T get_from_expression(T value) {
return std::move(value);
}

template<class T>
T get_from_expression(expression_t<T> expression) {
constexpr T get_from_expression(expression_t<T> expression) {
return std::move(expression.value);
}

Expand All @@ -86,7 +86,7 @@ namespace sqlite_orm {
* `storage.update(set(c(&User::name) = "Dua Lipa"));
*/
template<class T>
internal::expression_t<T> c(T value) {
constexpr internal::expression_t<T> c(T value) {
return {std::move(value)};
}
}
Loading

0 comments on commit 662f4e0

Please sign in to comment.