diff --git a/include/sqlpp11/core/aggregate_function/avg.h b/include/sqlpp11/core/aggregate_function/avg.h index f1a8893a..aff05077 100644 --- a/include/sqlpp11/core/aggregate_function/avg.h +++ b/include/sqlpp11/core/aggregate_function/avg.h @@ -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 +#include #include #include namespace sqlpp { template - struct avg_t : public enable_as>, public enable_over> + struct avg_t : public enable_as>, + public enable_comparison>, + public enable_over> { - using _nodes = detail::type_vector; - using _can_be_null = std::true_type; + using _traits = make_traits; + + 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 + struct nodes_of> + { + using type = sqlpp::detail::type_vector; + }; + template struct value_type_of> { using type = sqlpp::force_optional_t; }; - template - Context& serialize(Context& context, const avg_t& t) - { - context << "AVG("; - if (std::is_same::value) - { - serialize(context, Flag()); - context << ' '; - } - serialize_operand(context, t._expr); - context << ")"; - return context; - } - template using check_avg_arg = ::sqlpp::enable_if_t<(is_numeric::value or is_boolean::value) and not contains_aggregate_function_t::value>; diff --git a/include/sqlpp11/core/aggregate_function/count.h b/include/sqlpp11/core/aggregate_function/count.h index 40c22131..8bf49d52 100644 --- a/include/sqlpp11/core/aggregate_function/count.h +++ b/include/sqlpp11/core/aggregate_function/count.h @@ -27,6 +27,7 @@ */ #include +#include #include #include #include @@ -34,15 +35,16 @@ namespace sqlpp { template - struct count_t : public enable_as>, public enable_over> + struct count_t : public enable_as>, + public enable_comparison>, + public enable_over> { using _traits = make_traits; - using _nodes = detail::type_vector; 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 + struct nodes_of> + { + using type = sqlpp::detail::type_vector; + }; + template struct value_type_of> { diff --git a/include/sqlpp11/core/aggregate_function/enable_over.h b/include/sqlpp11/core/aggregate_function/enable_over.h index 2bad1aa8..37724d7f 100644 --- a/include/sqlpp11/core/aggregate_function/enable_over.h +++ b/include/sqlpp11/core/aggregate_function/enable_over.h @@ -47,4 +47,10 @@ namespace sqlpp } }; +#warning: Need to use in tests + template + struct has_enabled_over : public std::is_base_of, T> + { + }; + } // namespace sqlpp diff --git a/include/sqlpp11/core/aggregate_function/max.h b/include/sqlpp11/core/aggregate_function/max.h index dd43acc1..9267fa71 100644 --- a/include/sqlpp11/core/aggregate_function/max.h +++ b/include/sqlpp11/core/aggregate_function/max.h @@ -27,6 +27,7 @@ */ #include +#include #include #include #include @@ -34,10 +35,11 @@ namespace sqlpp { template - struct max_t : public enable_as>, public enable_over> + struct max_t : public enable_as>, + public enable_comparison>, + public enable_over> { using _traits = make_traits, tag::is_expression, tag::is_selectable>; - using _nodes = detail::type_vector; using _can_be_null = std::true_type; using _is_aggregate_expression = std::true_type; @@ -54,6 +56,12 @@ namespace sqlpp Expr _expr; }; + template + struct nodes_of> + { + using type = sqlpp::detail::type_vector; + }; + template struct value_type_of> { diff --git a/include/sqlpp11/core/aggregate_function/min.h b/include/sqlpp11/core/aggregate_function/min.h index a1f983e3..a36351b2 100644 --- a/include/sqlpp11/core/aggregate_function/min.h +++ b/include/sqlpp11/core/aggregate_function/min.h @@ -27,6 +27,7 @@ */ #include +#include #include #include #include @@ -34,10 +35,11 @@ namespace sqlpp { template - struct min_t : public enable_as>, enable_over> + struct min_t : public enable_as>, + public enable_comparison>, + enable_over> { using _traits = make_traits, tag::is_expression, tag::is_selectable>; - using _nodes = detail::type_vector; using _can_be_null = std::true_type; using _is_aggregate_expression = std::true_type; @@ -54,6 +56,12 @@ namespace sqlpp Expr _expr; }; + template + struct nodes_of> + { + using type = sqlpp::detail::type_vector; + }; + template struct value_type_of> { diff --git a/include/sqlpp11/core/aggregate_function/over.h b/include/sqlpp11/core/aggregate_function/over.h index 0a6ab11d..b8123e05 100644 --- a/include/sqlpp11/core/aggregate_function/over.h +++ b/include/sqlpp11/core/aggregate_function/over.h @@ -33,10 +33,10 @@ namespace sqlpp { template - struct over_t : public enable_as>, public enable_comparison> + struct over_t : public enable_as>, + public enable_comparison> { using _traits = make_traits; - using _nodes = detail::type_vector; over_t(Expr expr) : _expr(expr) @@ -53,11 +53,15 @@ namespace sqlpp }; template - struct value_type_of>: public value_type_of {}; + struct nodes_of> + { + using type = sqlpp::detail::type_vector; + }; template - struct nodes_of>: public nodes_of {}; + struct value_type_of>: public value_type_of {}; +#warning: should this be "is_aggregate_function"? template using check_over_args = ::sqlpp::enable_if_t::value>; diff --git a/include/sqlpp11/core/aggregate_function/sum.h b/include/sqlpp11/core/aggregate_function/sum.h index 392f8c1b..7fd04ce9 100644 --- a/include/sqlpp11/core/aggregate_function/sum.h +++ b/include/sqlpp11/core/aggregate_function/sum.h @@ -27,6 +27,7 @@ */ #include +#include #include #include #include @@ -34,10 +35,11 @@ namespace sqlpp { template - struct sum_t : public enable_as>, enable_over> + struct sum_t : public enable_as>, + public enable_comparison>, + enable_over> { using _traits = make_traits, tag::is_expression, tag::is_selectable>; - using _nodes = detail::type_vector; using _can_be_null = std::true_type; using _is_aggregate_expression = std::true_type; @@ -54,6 +56,12 @@ namespace sqlpp Expr _expr; }; + template + struct nodes_of> + { + using type = sqlpp::detail::type_vector; + }; + template struct value_type_of> { diff --git a/include/sqlpp11/core/type_traits.h b/include/sqlpp11/core/type_traits.h index 726bc815..9ebdc787 100644 --- a/include/sqlpp11/core/type_traits.h +++ b/include/sqlpp11/core/type_traits.h @@ -725,12 +725,6 @@ namespace sqlpp using _tags = detail::make_type_set_t; }; - struct aggregate_function - { - using _nodes = detail::type_vector<>; - using _contains_aggregate_function = std::true_type; - }; - template using member_t = typename name_tag_of_t::template _member_t; diff --git a/tests/core/types/aggregate_function.cpp b/tests/core/types/aggregate_function.cpp index bc21e3e9..804a1664 100644 --- a/tests/core/types/aggregate_function.cpp +++ b/tests/core/types/aggregate_function.cpp @@ -53,9 +53,26 @@ void test_aggregate_functions(Value v) static_assert(is_same_type::value, ""); static_assert(is_same_type::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::value, ""); + static_assert(sqlpp::has_enabled_as::value, ""); + static_assert(sqlpp::has_enabled_as::value, ""); + + // Aggregate functions enable comparison member functions. + static_assert(sqlpp::has_enabled_comparison::value, ""); + static_assert(sqlpp::has_enabled_comparison::value, ""); + static_assert(sqlpp::has_enabled_comparison::value, ""); + + // Aggregate functions enable OVER. + static_assert(sqlpp::has_enabled_over::value, ""); + static_assert(sqlpp::has_enabled_over::value, ""); + static_assert(sqlpp::has_enabled_over::value, ""); + + // Aggregate functions have their arguments as nodes + using L = typename std::decay::type; + static_assert(std::is_same, sqlpp::detail::type_vector>::value, ""); + static_assert(std::is_same, sqlpp::detail::type_vector>::value, ""); + static_assert(std::is_same, sqlpp::detail::type_vector>::value, ""); } template @@ -75,6 +92,25 @@ void test_numeric_aggregate_functions(Value v) // Aggregate of nullable static_assert(is_same_type::value, ""); static_assert(is_same_type::value, ""); + + // Aggregate functions enable the `as` member function. + static_assert(sqlpp::has_enabled_as::value, ""); + static_assert(sqlpp::has_enabled_as::value, ""); + + // Aggregate functions enable OVER. + static_assert(sqlpp::has_enabled_over::value, ""); + static_assert(sqlpp::has_enabled_over::value, ""); + + // Aggregate functions enable comparison member functions. + static_assert(sqlpp::has_enabled_comparison::value, ""); + static_assert(sqlpp::has_enabled_comparison::value, ""); + + // Aggregate functions have their arguments as nodes + using L = typename std::decay::type; + static_assert(std::is_same, sqlpp::detail::type_vector>::value, ""); + static_assert(std::is_same, sqlpp::detail::type_vector>::value, ""); + +#warning: test enable_over } int main()