mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
More tests
This commit is contained in:
parent
98a4ff9cb2
commit
42d1b61279
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* Copyright (c) 2013-2020, Roland Bock, MacDue
|
||||
* Copyright (c) 2013-2020, Roland Bock
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
@ -27,16 +27,20 @@
|
||||
*/
|
||||
|
||||
#include <sqlpp11/core/operator/enable_as.h>
|
||||
#include <sqlpp11/core/operator/enable_comparison.h>
|
||||
#include <sqlpp11/core/aggregate_function/enable_over.h>
|
||||
#include <sqlpp11/core/type_traits.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template <typename Flag, typename Expr>
|
||||
struct avg_t : public enable_as<avg_t<Flag, Expr>>, public enable_over<avg_t<Flag, Expr>>
|
||||
struct avg_t : public enable_as<avg_t<Flag, Expr>>,
|
||||
public enable_comparison<avg_t<Flag, Expr>>,
|
||||
public enable_over<avg_t<Flag, Expr>>
|
||||
{
|
||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||
using _can_be_null = std::true_type;
|
||||
using _traits = make_traits<integral, tag::is_expression /*, tag::is_selectable*/>;
|
||||
|
||||
using _can_be_null = std::false_type;
|
||||
using _is_aggregate_expression = std::true_type;
|
||||
|
||||
constexpr avg_t(Expr expr) : _expr(std::move(expr))
|
||||
@ -52,26 +56,18 @@ namespace sqlpp
|
||||
Expr _expr;
|
||||
};
|
||||
|
||||
template <typename Flag, typename Expr>
|
||||
struct nodes_of<avg_t<Flag, Expr>>
|
||||
{
|
||||
using type = sqlpp::detail::type_vector<Expr>;
|
||||
};
|
||||
|
||||
template <typename Flag, typename Expr>
|
||||
struct value_type_of<avg_t<Flag, Expr>>
|
||||
{
|
||||
using type = sqlpp::force_optional_t<floating_point>;
|
||||
};
|
||||
|
||||
template <typename Context, typename Flag, typename Expr>
|
||||
Context& serialize(Context& context, const avg_t<Flag, Expr>& t)
|
||||
{
|
||||
context << "AVG(";
|
||||
if (std::is_same<distinct_t, Flag>::value)
|
||||
{
|
||||
serialize(context, Flag());
|
||||
context << ' ';
|
||||
}
|
||||
serialize_operand(context, t._expr);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using check_avg_arg =
|
||||
::sqlpp::enable_if_t<(is_numeric<T>::value or is_boolean<T>::value) and not contains_aggregate_function_t<T>::value>;
|
||||
|
@ -27,6 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <sqlpp11/core/operator/enable_as.h>
|
||||
#include <sqlpp11/core/operator/enable_comparison.h>
|
||||
#include <sqlpp11/core/aggregate_function/enable_over.h>
|
||||
#include <sqlpp11/core/clause/select_flags.h>
|
||||
#include <sqlpp11/core/type_traits.h>
|
||||
@ -34,15 +35,16 @@
|
||||
namespace sqlpp
|
||||
{
|
||||
template <typename Flag, typename Expr>
|
||||
struct count_t : public enable_as<count_t<Flag, Expr>>, public enable_over<count_t<Flag, Expr>>
|
||||
struct count_t : public enable_as<count_t<Flag, Expr>>,
|
||||
public enable_comparison<count_t<Flag, Expr>>,
|
||||
public enable_over<count_t<Flag, Expr>>
|
||||
{
|
||||
using _traits = make_traits<integral, tag::is_expression /*, tag::is_selectable*/>;
|
||||
|
||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||
using _can_be_null = std::false_type;
|
||||
using _is_aggregate_expression = std::true_type;
|
||||
|
||||
constexpr count_t(const Expr expr) : _expr(std::move(expr))
|
||||
constexpr count_t(Expr expr) : _expr(std::move(expr))
|
||||
{
|
||||
}
|
||||
|
||||
@ -55,6 +57,12 @@ namespace sqlpp
|
||||
Expr _expr;
|
||||
};
|
||||
|
||||
template <typename Flag, typename Expr>
|
||||
struct nodes_of<count_t<Flag, Expr>>
|
||||
{
|
||||
using type = sqlpp::detail::type_vector<Expr>;
|
||||
};
|
||||
|
||||
template <typename Flag, typename Expr>
|
||||
struct value_type_of<count_t<Flag, Expr>>
|
||||
{
|
||||
|
@ -47,4 +47,10 @@ namespace sqlpp
|
||||
}
|
||||
};
|
||||
|
||||
#warning: Need to use in tests
|
||||
template <typename T>
|
||||
struct has_enabled_over : public std::is_base_of<enable_over<T>, T>
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace sqlpp
|
||||
|
@ -27,6 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <sqlpp11/core/operator/enable_as.h>
|
||||
#include <sqlpp11/core/operator/enable_comparison.h>
|
||||
#include <sqlpp11/core/aggregate_function/enable_over.h>
|
||||
#include <sqlpp11/core/clause/select_flags.h>
|
||||
#include <sqlpp11/core/type_traits.h>
|
||||
@ -34,10 +35,11 @@
|
||||
namespace sqlpp
|
||||
{
|
||||
template <typename Flag, typename Expr>
|
||||
struct max_t : public enable_as<max_t<Flag, Expr>>, public enable_over<max_t<Flag, Expr>>
|
||||
struct max_t : public enable_as<max_t<Flag, Expr>>,
|
||||
public enable_comparison<max_t<Flag, Expr>>,
|
||||
public enable_over<max_t<Flag, Expr>>
|
||||
{
|
||||
using _traits = make_traits<value_type_of_t<Expr>, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||
using _can_be_null = std::true_type;
|
||||
using _is_aggregate_expression = std::true_type;
|
||||
|
||||
@ -54,6 +56,12 @@ namespace sqlpp
|
||||
Expr _expr;
|
||||
};
|
||||
|
||||
template <typename Flag, typename Expr>
|
||||
struct nodes_of<max_t<Flag, Expr>>
|
||||
{
|
||||
using type = sqlpp::detail::type_vector<Expr>;
|
||||
};
|
||||
|
||||
template <typename Flag, typename Expr>
|
||||
struct value_type_of<max_t<Flag, Expr>>
|
||||
{
|
||||
|
@ -27,6 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <sqlpp11/core/operator/enable_as.h>
|
||||
#include <sqlpp11/core/operator/enable_comparison.h>
|
||||
#include <sqlpp11/core/aggregate_function/enable_over.h>
|
||||
#include <sqlpp11/core/clause/select_flags.h>
|
||||
#include <sqlpp11/core/type_traits.h>
|
||||
@ -34,10 +35,11 @@
|
||||
namespace sqlpp
|
||||
{
|
||||
template <typename Flag, typename Expr>
|
||||
struct min_t : public enable_as<min_t<Flag, Expr>>, enable_over<min_t<Flag, Expr>>
|
||||
struct min_t : public enable_as<min_t<Flag, Expr>>,
|
||||
public enable_comparison<min_t<Flag, Expr>>,
|
||||
enable_over<min_t<Flag, Expr>>
|
||||
{
|
||||
using _traits = make_traits<value_type_of_t<Expr>, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||
using _can_be_null = std::true_type;
|
||||
using _is_aggregate_expression = std::true_type;
|
||||
|
||||
@ -54,6 +56,12 @@ namespace sqlpp
|
||||
Expr _expr;
|
||||
};
|
||||
|
||||
template <typename Flag, typename Expr>
|
||||
struct nodes_of<min_t<Flag, Expr>>
|
||||
{
|
||||
using type = sqlpp::detail::type_vector<Expr>;
|
||||
};
|
||||
|
||||
template <typename Flag, typename Expr>
|
||||
struct value_type_of<min_t<Flag, Expr>>
|
||||
{
|
||||
|
@ -33,10 +33,10 @@
|
||||
namespace sqlpp
|
||||
{
|
||||
template <typename Expr>
|
||||
struct over_t : public enable_as<over_t<Expr>>, public enable_comparison<over_t<Expr>>
|
||||
struct over_t : public enable_as<over_t<Expr>>,
|
||||
public enable_comparison<over_t<Expr>>
|
||||
{
|
||||
using _traits = make_traits<integral, tag::is_expression>;
|
||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||
|
||||
over_t(Expr expr)
|
||||
: _expr(expr)
|
||||
@ -53,11 +53,15 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template<typename Expr>
|
||||
struct value_type_of<over_t<Expr>>: public value_type_of<Expr> {};
|
||||
struct nodes_of<over_t<Expr>>
|
||||
{
|
||||
using type = sqlpp::detail::type_vector<Expr>;
|
||||
};
|
||||
|
||||
template<typename Expr>
|
||||
struct nodes_of<over_t<Expr>>: public nodes_of<Expr> {};
|
||||
struct value_type_of<over_t<Expr>>: public value_type_of<Expr> {};
|
||||
|
||||
#warning: should this be "is_aggregate_function"?
|
||||
template<typename Expr>
|
||||
using check_over_args = ::sqlpp::enable_if_t<contains_aggregate_function_t<Expr>::value>;
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <sqlpp11/core/operator/enable_as.h>
|
||||
#include <sqlpp11/core/operator/enable_comparison.h>
|
||||
#include <sqlpp11/core/aggregate_function/enable_over.h>
|
||||
#include <sqlpp11/core/clause/select_flags.h>
|
||||
#include <sqlpp11/core/type_traits.h>
|
||||
@ -34,10 +35,11 @@
|
||||
namespace sqlpp
|
||||
{
|
||||
template <typename Flag, typename Expr>
|
||||
struct sum_t : public enable_as<sum_t<Flag, Expr>>, enable_over<sum_t<Flag, Expr>>
|
||||
struct sum_t : public enable_as<sum_t<Flag, Expr>>,
|
||||
public enable_comparison<sum_t<Flag, Expr>>,
|
||||
enable_over<sum_t<Flag, Expr>>
|
||||
{
|
||||
using _traits = make_traits<value_type_of_t<Expr>, tag::is_expression, tag::is_selectable>;
|
||||
using _nodes = detail::type_vector<Expr, aggregate_function>;
|
||||
using _can_be_null = std::true_type;
|
||||
using _is_aggregate_expression = std::true_type;
|
||||
|
||||
@ -54,6 +56,12 @@ namespace sqlpp
|
||||
Expr _expr;
|
||||
};
|
||||
|
||||
template <typename Flag, typename Expr>
|
||||
struct nodes_of<sum_t<Flag, Expr>>
|
||||
{
|
||||
using type = sqlpp::detail::type_vector<Expr>;
|
||||
};
|
||||
|
||||
template <typename Flag, typename Expr>
|
||||
struct value_type_of<sum_t<Flag, Expr>>
|
||||
{
|
||||
|
@ -725,12 +725,6 @@ namespace sqlpp
|
||||
using _tags = detail::make_type_set_t<Tags...>;
|
||||
};
|
||||
|
||||
struct aggregate_function
|
||||
{
|
||||
using _nodes = detail::type_vector<>;
|
||||
using _contains_aggregate_function = std::true_type;
|
||||
};
|
||||
|
||||
template <typename NameTagProvider, typename Member>
|
||||
using member_t = typename name_tag_of_t<NameTagProvider>::template _member_t<Member>;
|
||||
|
||||
|
@ -53,9 +53,26 @@ void test_aggregate_functions(Value v)
|
||||
static_assert(is_same_type<decltype(max(v_maybe_null)), OptValueType>::value, "");
|
||||
static_assert(is_same_type<decltype(min(v_maybe_null)), OptValueType>::value, "");
|
||||
|
||||
#warning: test can be aliased
|
||||
#warning: test has comparison operators
|
||||
#warning: test nodes
|
||||
// Aggregate functions enable the `as` member function.
|
||||
static_assert(sqlpp::has_enabled_as<decltype(count(v_not_null))>::value, "");
|
||||
static_assert(sqlpp::has_enabled_as<decltype(max(v_not_null))>::value, "");
|
||||
static_assert(sqlpp::has_enabled_as<decltype(min(v_not_null))>::value, "");
|
||||
|
||||
// Aggregate functions enable comparison member functions.
|
||||
static_assert(sqlpp::has_enabled_comparison<decltype(count(v_not_null))>::value, "");
|
||||
static_assert(sqlpp::has_enabled_comparison<decltype(max(v_not_null))>::value, "");
|
||||
static_assert(sqlpp::has_enabled_comparison<decltype(min(v_not_null))>::value, "");
|
||||
|
||||
// Aggregate functions enable OVER.
|
||||
static_assert(sqlpp::has_enabled_over<decltype(count(v_not_null))>::value, "");
|
||||
static_assert(sqlpp::has_enabled_over<decltype(max(v_not_null))>::value, "");
|
||||
static_assert(sqlpp::has_enabled_over<decltype(min(v_not_null))>::value, "");
|
||||
|
||||
// Aggregate functions have their arguments as nodes
|
||||
using L = typename std::decay<decltype(v_not_null)>::type;
|
||||
static_assert(std::is_same<sqlpp::nodes_of_t<decltype(count(v_not_null))>, sqlpp::detail::type_vector<L>>::value, "");
|
||||
static_assert(std::is_same<sqlpp::nodes_of_t<decltype(max(v_not_null))>, sqlpp::detail::type_vector<L>>::value, "");
|
||||
static_assert(std::is_same<sqlpp::nodes_of_t<decltype(min(v_not_null))>, sqlpp::detail::type_vector<L>>::value, "");
|
||||
}
|
||||
|
||||
template <typename Value>
|
||||
@ -75,6 +92,25 @@ void test_numeric_aggregate_functions(Value v)
|
||||
// Aggregate of nullable
|
||||
static_assert(is_same_type<decltype(sum(v_maybe_null)), OptValueType>::value, "");
|
||||
static_assert(is_same_type<decltype(avg(v_maybe_null)), OptFloat>::value, "");
|
||||
|
||||
// Aggregate functions enable the `as` member function.
|
||||
static_assert(sqlpp::has_enabled_as<decltype(sum(v_not_null))>::value, "");
|
||||
static_assert(sqlpp::has_enabled_as<decltype(avg(v_not_null))>::value, "");
|
||||
|
||||
// Aggregate functions enable OVER.
|
||||
static_assert(sqlpp::has_enabled_over<decltype(sum(v_not_null))>::value, "");
|
||||
static_assert(sqlpp::has_enabled_over<decltype(avg(v_not_null))>::value, "");
|
||||
|
||||
// Aggregate functions enable comparison member functions.
|
||||
static_assert(sqlpp::has_enabled_comparison<decltype(sum(v_not_null))>::value, "");
|
||||
static_assert(sqlpp::has_enabled_comparison<decltype(avg(v_not_null))>::value, "");
|
||||
|
||||
// Aggregate functions have their arguments as nodes
|
||||
using L = typename std::decay<decltype(v_not_null)>::type;
|
||||
static_assert(std::is_same<sqlpp::nodes_of_t<decltype(sum(v_not_null))>, sqlpp::detail::type_vector<L>>::value, "");
|
||||
static_assert(std::is_same<sqlpp::nodes_of_t<decltype(avg(v_not_null))>, sqlpp::detail::type_vector<L>>::value, "");
|
||||
|
||||
#warning: test enable_over
|
||||
}
|
||||
|
||||
int main()
|
||||
|
Loading…
Reference in New Issue
Block a user