mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Merge branch 'develop' of https://github.com/rbock/sqlpp11 into develop
This commit is contained in:
commit
b0aa23ee87
@ -187,14 +187,19 @@ namespace sqlpp
|
|||||||
return {*static_cast<const Expr*>(this)};
|
return {*static_cast<const Expr*>(this)};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto asc() const -> sort_order_t<Expr, sort_type::asc>
|
auto asc() const -> sort_order_t<Expr>
|
||||||
{
|
{
|
||||||
return {*static_cast<const Expr*>(this)};
|
return {*static_cast<const Expr*>(this), sort_type::asc};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto desc() const -> sort_order_t<Expr, sort_type::desc>
|
auto desc() const -> sort_order_t<Expr>
|
||||||
{
|
{
|
||||||
return {*static_cast<const Expr*>(this)};
|
return {*static_cast<const Expr*>(this), sort_type::desc};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto order(sort_type s) const -> sort_order_t<Expr>
|
||||||
|
{
|
||||||
|
return {*static_cast<const Expr*>(this), s};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... T>
|
template <typename... T>
|
||||||
|
@ -39,25 +39,26 @@ namespace sqlpp
|
|||||||
desc
|
desc
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Expression, sort_type SortType>
|
template <typename Expression>
|
||||||
struct sort_order_t
|
struct sort_order_t
|
||||||
{
|
{
|
||||||
using _traits = make_traits<no_value_t, tag::is_sort_order>;
|
using _traits = make_traits<no_value_t, tag::is_sort_order>;
|
||||||
using _nodes = detail::type_vector<Expression>;
|
using _nodes = detail::type_vector<Expression>;
|
||||||
|
|
||||||
Expression _expression;
|
Expression _expression;
|
||||||
|
sort_type _sort_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename Expression, sort_type SortType>
|
template <typename Context, typename Expression>
|
||||||
struct serializer_t<Context, sort_order_t<Expression, SortType>>
|
struct serializer_t<Context, sort_order_t<Expression>>
|
||||||
{
|
{
|
||||||
using _serialize_check = serialize_check_of<Context, Expression>;
|
using _serialize_check = serialize_check_of<Context, Expression>;
|
||||||
using T = sort_order_t<Expression, SortType>;
|
using T = sort_order_t<Expression>;
|
||||||
|
|
||||||
static Context& _(const T& t, Context& context)
|
static Context& _(const T& t, Context& context)
|
||||||
{
|
{
|
||||||
serialize_operand(t._expression, context);
|
serialize_operand(t._expression, context);
|
||||||
switch (SortType)
|
switch (t._sort_type)
|
||||||
{
|
{
|
||||||
case sort_type::asc:
|
case sort_type::asc:
|
||||||
context << " ASC";
|
context << " ASC";
|
||||||
|
@ -57,9 +57,11 @@ int CustomQuery(int, char* [])
|
|||||||
custom_query(sqlpp::select(), dynamic_select_flags(db, sqlpp::distinct), dynamic_select_columns(db, foo.omega),
|
custom_query(sqlpp::select(), dynamic_select_flags(db, sqlpp::distinct), dynamic_select_columns(db, foo.omega),
|
||||||
dynamic_from(db, foo.join(bar).on(foo.omega == bar.alpha)), dynamic_where(db, bar.alpha > 17),
|
dynamic_from(db, foo.join(bar).on(foo.omega == bar.alpha)), dynamic_where(db, bar.alpha > 17),
|
||||||
dynamic_group_by(db, foo.omega), dynamic_having(db, avg(bar.alpha) > 19),
|
dynamic_group_by(db, foo.omega), dynamic_having(db, avg(bar.alpha) > 19),
|
||||||
dynamic_order_by(db, foo.omega.asc()), sqlpp::dynamic_limit(db), sqlpp::dynamic_offset(db)),
|
dynamic_order_by(db, foo.omega.asc(), foo.psi.order(sqlpp::sort_type::desc)),
|
||||||
|
sqlpp::dynamic_limit(db), sqlpp::dynamic_offset(db)),
|
||||||
"SELECT DISTINCT tab_foo.omega FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega=tab_bar.alpha) WHERE "
|
"SELECT DISTINCT tab_foo.omega FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega=tab_bar.alpha) WHERE "
|
||||||
"(tab_bar.alpha>17) GROUP BY tab_foo.omega HAVING (AVG(tab_bar.alpha)>19) ORDER BY tab_foo.omega ASC ");
|
"(tab_bar.alpha>17) GROUP BY tab_foo.omega HAVING (AVG(tab_bar.alpha)>19) ORDER BY tab_foo.omega "
|
||||||
|
"ASC,tab_foo.psi DESC ");
|
||||||
|
|
||||||
// A pragma query for sqlite
|
// A pragma query for sqlite
|
||||||
compare(__LINE__,
|
compare(__LINE__,
|
||||||
|
@ -160,6 +160,7 @@ int Select(int, char* [])
|
|||||||
s.offset.set(3u);
|
s.offset.set(3u);
|
||||||
s.group_by.add(t.beta);
|
s.group_by.add(t.beta);
|
||||||
s.order_by.add(t.beta.asc());
|
s.order_by.add(t.beta.asc());
|
||||||
|
s.order_by.add(t.delta.order(sqlpp::sort_type::desc));
|
||||||
for (const auto& row : db(s))
|
for (const auto& row : db(s))
|
||||||
{
|
{
|
||||||
int64_t a = row.alpha;
|
int64_t a = row.alpha;
|
||||||
|
Loading…
Reference in New Issue
Block a user