mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Moved group_by-methods to group_by classes
This commit is contained in:
parent
a541d8e187
commit
7af13937bf
@ -131,6 +131,7 @@ namespace sqlpp
|
||||
>
|
||||
struct select_t: public detail::select_helper_t<ColumnList, From>::_value_type::template expression_operators<select_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
|
||||
Where::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
|
||||
GroupBy::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
|
||||
Having::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
|
||||
OrderBy::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
|
||||
Limit::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>,
|
||||
@ -236,23 +237,6 @@ namespace sqlpp
|
||||
return { *this, vendor::from_t<_database_t, Args...>{args...} };
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
auto group_by(Args... args)
|
||||
-> _policies_update_t<vendor::no_group_by_t, vendor::group_by_t<void, Args...>>
|
||||
{
|
||||
static_assert(is_noop_t<GroupBy>::value, "cannot call group_by()/dynamic_group_by() twice");
|
||||
return { *this, vendor::group_by_t<void, Args...>{args...} };
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
auto dynamic_group_by(Args... args)
|
||||
-> _policies_update_t<vendor::no_group_by_t, vendor::group_by_t<_database_t, Args...>>
|
||||
{
|
||||
static_assert(is_noop_t<GroupBy>::value, "cannot call group_by()/dynamic_group_by() twice");
|
||||
static_assert(not std::is_same<_database_t, void>::value, "dynamic_group_by must not be called in a static statement");
|
||||
return { *this, vendor::group_by_t<_database_t, Args...>{args...} };
|
||||
}
|
||||
|
||||
// value adding methods
|
||||
template<typename... Args>
|
||||
void add_flag(Args... args)
|
||||
@ -278,14 +262,6 @@ namespace sqlpp
|
||||
return _from.add_from(*this, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void add_group_by(Args... args)
|
||||
{
|
||||
static_assert(is_group_by_t<GroupBy>::value, "cannot call add_group_by() before dynamic_group_by()");
|
||||
static_assert(is_dynamic_t<GroupBy>::value, "cannot call add_group_by() before dynamic_group_by()");
|
||||
return _group_by.add_group_by(*this, args...);
|
||||
}
|
||||
|
||||
// PseudoTable
|
||||
template<typename AliasProvider>
|
||||
struct _pseudo_table_t
|
||||
|
40
include/sqlpp11/vendor/group_by.h
vendored
40
include/sqlpp11/vendor/group_by.h
vendored
@ -46,6 +46,8 @@ namespace sqlpp
|
||||
using _is_group_by = std::true_type;
|
||||
using _is_dynamic = typename std::conditional<std::is_same<Database, void>::value, std::false_type, std::true_type>::type;
|
||||
using _parameter_tuple_t = std::tuple<Expressions...>;
|
||||
#warning Has no parameter_list?
|
||||
using _table_set = typename ::sqlpp::detail::make_joined_set<typename Expressions::_table_set...>::type;
|
||||
|
||||
static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression (e.g. a column) required in group_by()");
|
||||
|
||||
@ -63,12 +65,17 @@ namespace sqlpp
|
||||
group_by_t& operator=(group_by_t&&) = default;
|
||||
~group_by_t() = default;
|
||||
|
||||
template<typename Statement, typename Expression>
|
||||
void add_group_by(const Statement&, Expression expression)
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
static_assert(is_table_t<Expression>::value, "from arguments require to be tables or joins");
|
||||
_dynamic_expressions.emplace_back(expression);
|
||||
}
|
||||
template<typename Expression>
|
||||
void add_group_by(Expression expression)
|
||||
{
|
||||
static_assert(is_expression_t<Expression>::value, "invalid expression argument in add_group_by()");
|
||||
#warning: Need to dispatch to actual add method to prevent error messages from being generated
|
||||
return static_cast<typename Policies::_select_t*>(this)->_group_by._dynamic_expressions.emplace_back(expression);
|
||||
}
|
||||
};
|
||||
|
||||
const group_by_t& _group_by() const { return *this; }
|
||||
_parameter_tuple_t _expressions;
|
||||
@ -79,6 +86,29 @@ namespace sqlpp
|
||||
{
|
||||
using _is_noop = std::true_type;
|
||||
using _table_set = ::sqlpp::detail::type_set<>;
|
||||
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
using _database_t = typename Policies::_database_t;
|
||||
template<typename T>
|
||||
using _new_select_t = typename Policies::template _policies_update_t<no_group_by_t, T>;
|
||||
|
||||
template<typename... Args>
|
||||
auto group_by(Args... args)
|
||||
-> _new_select_t<group_by_t<void, Args...>>
|
||||
{
|
||||
return { *static_cast<typename Policies::_select_t*>(this), group_by_t<void, Args...>{args...} };
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
auto dynamic_group_by(Args... args)
|
||||
-> _new_select_t<group_by_t<_database_t, Args...>>
|
||||
{
|
||||
static_assert(not std::is_same<_database_t, void>::value, "dynamic_group_by must not be called in a static statement");
|
||||
return { *static_cast<typename Policies::_select_t*>(this), vendor::group_by_t<_database_t, Args...>{args...} };
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Interpreters
|
||||
|
Loading…
Reference in New Issue
Block a user