mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Move offset methods into offset classes
This commit is contained in:
parent
4727de831f
commit
f2fc4f73f6
@ -131,7 +131,8 @@ 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>>,
|
||||
Limit::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>>,
|
||||
Offset::template _methods_t<detail::select_policies_t<Database, FlagList, ColumnList, From, Where, GroupBy, Having, OrderBy, Limit, Offset>>
|
||||
{
|
||||
using _database_t = Database;
|
||||
using _is_dynamic = typename std::conditional<std::is_same<Database, void>::value, std::false_type, std::true_type>::type;
|
||||
@ -284,22 +285,6 @@ namespace sqlpp
|
||||
return { *this, vendor::order_by_t<_database_t, Args...>{args...} };
|
||||
}
|
||||
|
||||
template<typename Arg>
|
||||
auto offset(Arg arg)
|
||||
-> _policies_update_t<vendor::no_offset_t, vendor::offset_t<typename vendor::wrap_operand<Arg>::type>>
|
||||
{
|
||||
static_assert(is_noop_t<Offset>::value, "cannot call offset()/dynamic_offset() twice");
|
||||
return { *this, vendor::offset_t<typename vendor::wrap_operand<Arg>::type>{{arg}} };
|
||||
}
|
||||
|
||||
auto dynamic_offset()
|
||||
-> _policies_update_t<vendor::no_offset_t, vendor::dynamic_offset_t<_database_t>>
|
||||
{
|
||||
static_assert(is_noop_t<Offset>::value, "cannot call offset()/dynamic_offset() twice");
|
||||
static_assert(not std::is_same<_database_t, void>::value, "dynamic_offset must not be called in a static statement");
|
||||
return { *this, vendor::dynamic_offset_t<_database_t>{} };
|
||||
}
|
||||
|
||||
// value adding methods
|
||||
template<typename... Args>
|
||||
void add_flag(Args... args)
|
||||
@ -349,22 +334,6 @@ namespace sqlpp
|
||||
return _order_by.add_order_by(*this, args...);
|
||||
}
|
||||
|
||||
template<typename Arg>
|
||||
void set_limit(Arg arg)
|
||||
{
|
||||
static_assert(is_limit_t<Limit>::value, "cannot call add_limit() before dynamic_limit()");
|
||||
static_assert(is_dynamic_t<Limit>::value, "cannot call add_limit() before dynamic_limit()");
|
||||
return _limit.set_limit(arg);
|
||||
}
|
||||
|
||||
template<typename Arg>
|
||||
void set_offset(Arg arg)
|
||||
{
|
||||
static_assert(is_offset_t<Offset>::value, "cannot call add_offset() before dynamic_offset()");
|
||||
static_assert(is_dynamic_t<Offset>::value, "cannot call add_offset() before dynamic_offset()");
|
||||
return _offset.set_offset(arg);
|
||||
}
|
||||
|
||||
// PseudoTable
|
||||
template<typename AliasProvider>
|
||||
struct _pseudo_table_t
|
||||
|
8
include/sqlpp11/vendor/limit.h
vendored
8
include/sqlpp11/vendor/limit.h
vendored
@ -86,14 +86,6 @@ namespace sqlpp
|
||||
dynamic_limit_t& operator=(dynamic_limit_t&&) = default;
|
||||
~dynamic_limit_t() = default;
|
||||
|
||||
template<typename Limit>
|
||||
void set_limit(Limit value)
|
||||
{
|
||||
using arg_t = typename wrap_operand<Limit>::type;
|
||||
_value = arg_t{value};
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
|
37
include/sqlpp11/vendor/offset.h
vendored
37
include/sqlpp11/vendor/offset.h
vendored
@ -40,6 +40,7 @@ namespace sqlpp
|
||||
struct offset_t
|
||||
{
|
||||
using _is_offset = std::true_type;
|
||||
using _table_set = ::sqlpp::detail::type_set<>;
|
||||
static_assert(is_integral_t<Offset>::value, "offset requires an integral value or integral parameter");
|
||||
|
||||
offset_t(Offset value):
|
||||
@ -52,6 +53,11 @@ namespace sqlpp
|
||||
offset_t& operator=(offset_t&&) = default;
|
||||
~offset_t() = default;
|
||||
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
};
|
||||
|
||||
Offset _value;
|
||||
};
|
||||
|
||||
@ -60,6 +66,7 @@ namespace sqlpp
|
||||
{
|
||||
using _is_offset = std::true_type;
|
||||
using _is_dynamic = std::true_type;
|
||||
using _table_set = ::sqlpp::detail::type_set<>;
|
||||
|
||||
dynamic_offset_t():
|
||||
_value(noop())
|
||||
@ -79,13 +86,17 @@ namespace sqlpp
|
||||
dynamic_offset_t& operator=(dynamic_offset_t&&) = default;
|
||||
~dynamic_offset_t() = default;
|
||||
|
||||
template<typename Policies>
|
||||
struct _methods_t
|
||||
{
|
||||
template<typename Offset>
|
||||
void set_offset(Offset value)
|
||||
{
|
||||
using arg_t = typename wrap_operand<Offset>::type;
|
||||
_value = arg_t(value);
|
||||
_initialized = true;
|
||||
static_cast<typename Policies::_select_t*>(this)->_offset._value = arg_t{value};
|
||||
static_cast<typename Policies::_select_t*>(this)->_offset._initialized = true;
|
||||
}
|
||||
};
|
||||
|
||||
bool _initialized = false;
|
||||
interpretable_t<Database> _value;
|
||||
@ -95,6 +106,28 @@ 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_offset_t, T>;
|
||||
|
||||
template<typename Arg>
|
||||
auto offset(Arg arg)
|
||||
-> _new_select_t<offset_t<typename wrap_operand<Arg>::type>>
|
||||
{
|
||||
return { *static_cast<typename Policies::_select_t*>(this), offset_t<typename wrap_operand<Arg>::type>{{arg}} };
|
||||
}
|
||||
|
||||
auto dynamic_offset()
|
||||
-> _new_select_t<dynamic_offset_t<_database_t>>
|
||||
{
|
||||
static_assert(not std::is_same<_database_t, void>::value, "dynamic_offset must not be called in a static statement");
|
||||
return { *static_cast<typename Policies::_select_t*>(this), dynamic_offset_t<_database_t>{} };
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Interpreters
|
||||
|
Loading…
Reference in New Issue
Block a user