Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compound statements with variable number of select statements #1241

Merged
merged 20 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d5f7bcc
Compound select with more than two simple select statements
trueqbit Oct 21, 2023
c324ad9
Simplified partial node tuple specializations
trueqbit Oct 21, 2023
09a9de8
Merge branch 'alias_column_operators' into multi-compound
trueqbit Oct 21, 2023
cb00848
Merge branch 'alias_column_operators' into multi-compound
trueqbit Oct 22, 2023
0be1c5f
Merge remote-tracking branch 'upstream/dev' into multi-compound
trueqbit Oct 22, 2023
791b506
Merge branch 'update-static-assert2' into multi-compound
trueqbit Oct 24, 2023
1fc26c2
Added unit tests for invocation of "metafunction operation"
trueqbit Oct 24, 2023
7fa9582
Turned `node_tuple_for` into an alias template
trueqbit Oct 24, 2023
3050a49
Merge remote-tracking branch 'upstream/dev' into multi-compound
trueqbit Oct 25, 2023
dc3b164
Allow compound statements to return a common type
trueqbit Oct 25, 2023
fdf9ab8
Runner-up: Allow compound statements to return a common type
trueqbit Oct 25, 2023
a226d23
A few more unit tests for tuple transformation
trueqbit Oct 25, 2023
9813ec1
Runner-up: A few more unit tests for tuple transformation
trueqbit Oct 25, 2023
0990d61
A couple of static unit tests for tuple transformation
trueqbit Oct 28, 2023
65fb0e3
Quoted metafunctions
trueqbit Oct 28, 2023
45db8d8
Updated metafunction programming
trueqbit Nov 8, 2023
63d1978
Updated tuple iteration for uninstantiated tuples with C++14
trueqbit Nov 8, 2023
205977b
`std::invoke` has only been constexpr since C++20.
trueqbit Nov 8, 2023
5736c26
Fixed an 'utf-8' codec that was not recognized by the linter
trueqbit Nov 8, 2023
505b85c
Worked around problems with legacy compilers
trueqbit Nov 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>>>...> {};
trueqbit marked this conversation as resolved.
Show resolved Hide resolved

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