Skip to content

Commit

Permalink
Merge pull request #1241 from FireDaemon/multi-compound
Browse files Browse the repository at this point in the history
Compound statements with variable number of select statements
  • Loading branch information
fnc12 authored Nov 9, 2023
2 parents 4374014 + 505b85c commit 79f1117
Show file tree
Hide file tree
Showing 29 changed files with 998 additions and 985 deletions.
9 changes: 4 additions & 5 deletions dev/ast_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ namespace sqlite_orm {
}
};

template<class L, class R, class... Ds>
struct ast_iterator<binary_operator<L, R, Ds...>, void> {
using node_type = binary_operator<L, R, Ds...>;
template<class T>
struct ast_iterator<T, match_if<is_binary_operator, T>> {
using node_type = T;

template<class C>
void operator()(const node_type& node, C& lambda) const {
Expand Down Expand Up @@ -241,8 +241,7 @@ namespace sqlite_orm {

template<class L>
void operator()(const node_type& c, L& lambda) const {
iterate_ast(c.left, lambda);
iterate_ast(c.right, lambda);
iterate_ast(c.compound, lambda);
}
};

Expand Down
4 changes: 2 additions & 2 deletions dev/column_names_getter.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ namespace sqlite_orm {
(*this)(colExpr, context);
});
// note: `capacity() > size()` can occur in case `asterisk_t<>` does spell out the columns in defined order
if(mpl::instantiate<check_if_tuple_has_template<asterisk_t>,
typename columns_t<Args...>::columns_type>::value &&
if(mpl::invoke_t<check_if_tuple_has_template<asterisk_t>,
typename columns_t<Args...>::columns_type>::value &&
collectedExpressions.capacity() > collectedExpressions.size()) {
collectedExpressions.shrink_to_fit();
}
Expand Down
25 changes: 15 additions & 10 deletions dev/column_result.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#pragma once

#include <type_traits> // std::enable_if, std::is_same, std::decay, std::is_arithmetic, std::is_base_of
#include <tuple> // std::tuple
#include <functional> // std::reference_wrapper

#include "functional/cxx_universal.h"
#include "functional/cxx_universal.h" // ::nullptr_t
#include "functional/cxx_type_traits_polyfill.h"
#include "functional/mpl.h"
#include "tuple_helper/tuple_traits.h"
#include "tuple_helper/tuple_fy.h"
#include "tuple_helper/tuple_filter.h"
#include "tuple_helper/tuple_transformer.h"
#include "tuple_helper/same_or_void.h"
#include "type_traits.h"
#include "member_traits/member_traits.h"
#include "mapped_type_proxy.h"
Expand Down Expand Up @@ -42,6 +45,10 @@ namespace sqlite_orm {
template<class DBOs, class T>
using column_result_of_t = typename column_result_t<DBOs, T>::type;

template<class DBOs, class Tpl>
using column_result_for_tuple_t =
transform_tuple_t<Tpl, mpl::bind_front_fn<column_result_of_t, DBOs>::template fn>;

#ifdef SQLITE_ORM_OPTIONAL_SUPPORTED
template<class DBOs, class T>
struct column_result_t<DBOs, as_optional_t<T>, void> {
Expand Down Expand Up @@ -220,20 +227,18 @@ namespace sqlite_orm {
struct column_result_t<DBOs, column_pointer<T, F>, void> : column_result_t<DBOs, F> {};

template<class DBOs, class... Args>
struct column_result_t<DBOs, columns_t<Args...>, void> {
using type = tuple_cat_t<tuplify_t<column_result_of_t<DBOs, std::decay_t<Args>>>...>;
};
struct column_result_t<DBOs, columns_t<Args...>, void>
: conc_tuple<tuplify_t<column_result_of_t<DBOs, std::decay_t<Args>>>...> {};

template<class DBOs, class T, class... Args>
struct column_result_t<DBOs, select_t<T, Args...>> : column_result_t<DBOs, T> {};

template<class DBOs, class T>
struct column_result_t<DBOs, T, match_if<is_compound_operator, T>> {
using left_result = column_result_of_t<DBOs, typename T::left_type>;
using right_result = column_result_of_t<DBOs, typename T::right_type>;
static_assert(std::is_same<left_result, right_result>::value,
"Compound subselect queries must return same types");
using type = left_result;
using type =
polyfill::detected_t<common_type_of_t, column_result_for_tuple_t<DBOs, typename T::expressions_tuple>>;
static_assert(!std::is_same<type, polyfill::nonesuch>::value,
"Compound select statements must return a common type");
};

template<class DBOs, class T>
Expand Down
30 changes: 15 additions & 15 deletions dev/constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,12 @@ namespace sqlite_orm {
/**
* Holds obect type of all referenced columns.
*/
using target_type = typename same_or_void<table_type_of_t<Rs>...>::type;
using target_type = same_or_void_t<table_type_of_t<Rs>...>;

/**
* Holds obect type of all source columns.
*/
using source_type = typename same_or_void<table_type_of_t<Cs>...>::type;
using source_type = same_or_void_t<table_type_of_t<Cs>...>;

columns_type columns;
references_type references;
Expand Down Expand Up @@ -458,25 +458,25 @@ namespace sqlite_orm {
template<typename T>
struct is_primary_key_insertable
: polyfill::disjunction<
mpl::instantiate<mpl::disjunction<check_if_tuple_has_template<default_t>,
check_if_tuple_has_template<primary_key_with_autoincrement>>,
constraints_type_t<T>>,
mpl::invoke_t<mpl::disjunction<check_if_tuple_has_template<default_t>,
check_if_tuple_has_template<primary_key_with_autoincrement>>,
constraints_type_t<T>>,
std::is_base_of<integer_printer, type_printer<field_type_t<T>>>> {

static_assert(tuple_has<is_primary_key, constraints_type_t<T>>::value, "an unexpected type was passed");
};

template<class T>
using is_constraint = mpl::instantiate<mpl::disjunction<check_if<is_primary_key>,
check_if<is_foreign_key>,
check_if_is_type<null_t>,
check_if_is_type<not_null_t>,
check_if_is_template<unique_t>,
check_if_is_template<default_t>,
check_if_is_template<check_t>,
check_if_is_type<collate_constraint_t>,
check_if<is_generated_always>>,
T>;
using is_constraint = mpl::invoke_t<mpl::disjunction<check_if<is_primary_key>,
check_if<is_foreign_key>,
check_if_is_type<null_t>,
check_if_is_type<not_null_t>,
check_if_is_template<unique_t>,
check_if_is_template<default_t>,
check_if_is_template<check_t>,
check_if_is_type<collate_constraint_t>,
check_if<is_generated_always>>,
T>;
}

#if SQLITE_VERSION_NUMBER >= 3031000
Expand Down
6 changes: 6 additions & 0 deletions dev/functional/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
#define SQLITE_ORM_INLINE_VAR
#endif

#if __cpp_lib_constexpr_functional >= 201907L
#define SQLITE_ORM_CONSTEXPR_CPP20 constexpr
#else
#define SQLITE_ORM_CONSTEXPR_CPP20
#endif

#if SQLITE_ORM_HAS_CPP_ATTRIBUTE(no_unique_address) >= 201803L
#define SQLITE_ORM_NOUNIQUEADDRESS [[no_unique_address]]
#else
Expand Down
Loading

0 comments on commit 79f1117

Please sign in to comment.