More functions are now auto-aliased

This commit is contained in:
rbock
2015-07-05 11:51:49 +02:00
parent bbe933f943
commit 864bd58eff
18 changed files with 230 additions and 154 deletions
-13
View File
@@ -39,19 +39,6 @@ namespace sqlpp
using _traits = make_traits<value_type_of<Select>, tag::is_multi_expression>;
using _nodes = detail::type_vector<Select>;
struct _alias_t
{
static constexpr const char _literal[] = "any_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T any;
T& operator()() { return any; }
const T& operator()() const { return any; }
};
};
any_t(Select select):
_select(select)
{}
+66
View File
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2013-2015, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQLPP_AUTO_ALIAS_H
#define SQLPP_AUTO_ALIAS_H
#include <sqlpp11/alias.h>
namespace sqlpp
{
template<typename T, typename Enable = void>
struct has_auto_alias_t
{
static constexpr bool value = false;
};
template<typename T>
struct has_auto_alias_t<T, typename std::enable_if<not wrong_t<typename T::_auto_alias_t>::value>::type>
{
static constexpr bool value = true;
};
namespace detail
{
template<typename T, typename Enable = void>
struct auto_alias_impl
{
using type = T;
};
template<typename T>
struct auto_alias_impl<T, typename std::enable_if<has_auto_alias_t<T>::value>::type>
{
using type = expression_alias_t<T, typename T::_auto_alias_t>;
};
}
template<typename T>
using auto_alias_t = typename detail::auto_alias_impl<T>::type;
}
#endif
+15 -10
View File
@@ -32,17 +32,8 @@
namespace sqlpp
{
template<typename Flag, typename Expr>
struct avg_t:
public expression_operators<avg_t<Flag, Expr>, floating_point>,
public alias_operators<avg_t<Flag, Expr>>
struct avg_alias_t
{
using _traits = make_traits<floating_point, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value, "avg() used with flag other than 'distinct'");
static_assert(is_numeric_t<Expr>::value, "avg() requires a value expression as argument");
struct _alias_t
{
static constexpr const char _literal[] = "avg_";
@@ -55,6 +46,20 @@ namespace sqlpp
const T& operator()() const { return avg; }
};
};
};
template<typename Flag, typename Expr>
struct avg_t:
public expression_operators<avg_t<Flag, Expr>, floating_point>,
public alias_operators<avg_t<Flag, Expr>>
{
using _traits = make_traits<floating_point, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value, "avg() used with flag other than 'distinct'");
static_assert(is_numeric_t<Expr>::value, "avg() requires a value expression as argument");
using _auto_alias_t = avg_alias_t;
avg_t(Expr expr):
_expr(expr)
+12 -7
View File
@@ -37,14 +37,8 @@ namespace sqlpp
{
struct text;
template<typename... Args>
struct concat_t:
public expression_operators<concat_t<Args...>, text>,
public alias_operators<concat_t<Args...>>
struct concat_alias_t
{
using _traits = make_traits<text, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Args...>;
struct _alias_t
{
static constexpr const char _literal[] = "concat_";
@@ -55,6 +49,17 @@ namespace sqlpp
T concat;
};
};
};
template<typename... Args>
struct concat_t:
public expression_operators<concat_t<Args...>, text>,
public alias_operators<concat_t<Args...>>
{
using _traits = make_traits<text, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Args...>;
using _auto_alias_t = concat_alias_t;
concat_t(Args... args):
_args(args...)
+1 -16
View File
@@ -28,7 +28,7 @@
#define SQLPP_DETAIL_COPY_TUPLE_ARGS_H
#include <tuple>
#include <sqlpp11/alias.h>
#include <sqlpp11/auto_alias.h>
namespace sqlpp
{
@@ -37,21 +37,6 @@ namespace sqlpp
namespace detail
{
template<typename T, typename Enable = void>
struct auto_alias_impl
{
using type = T;
};
template<typename T>
struct auto_alias_impl<T, typename std::enable_if<not wrong_t<typename T::_auto_alias_t>::value>::type>
{
using type = expression_alias_t<T, typename T::_auto_alias_t>;
};
template<typename T>
using auto_alias_t = typename detail::auto_alias_impl<T>::type;
template<typename T>
struct as_column_tuple
{
+14 -9
View File
@@ -32,16 +32,8 @@
namespace sqlpp
{
template<typename Select>
struct exists_t:
public expression_operators<exists_t<Select>, boolean>,
public alias_operators<exists_t<Select>>
struct exists_alias_t
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Select>;
static_assert(is_select_t<Select>::value, "exists() requires a select expression as argument");
struct _alias_t
{
static constexpr const char _literal[] = "exists_";
@@ -54,6 +46,19 @@ namespace sqlpp
const T& operator()() const { return exists; }
};
};
};
template<typename Select>
struct exists_t:
public expression_operators<exists_t<Select>, boolean>,
public alias_operators<exists_t<Select>>
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Select>;
static_assert(is_select_t<Select>::value, "exists() requires a select expression as argument");
using _auto_alias_t = exists_alias_t;
exists_t(Select select):
_select(select)
+1 -1
View File
@@ -34,7 +34,6 @@
#include <sqlpp11/not_in.h>
#include <sqlpp11/is_null.h>
#include <sqlpp11/is_not_null.h>
#include <sqlpp11/value_type.h>
#include <sqlpp11/exists.h>
#include <sqlpp11/any.h>
#include <sqlpp11/concat.h>
@@ -44,6 +43,7 @@
#include <sqlpp11/max.h>
#include <sqlpp11/avg.h>
#include <sqlpp11/sum.h>
#include <sqlpp11/value_type.h>
#include <sqlpp11/verbatim.h> // Csaba Csoma suggests: unsafe_sql instead of verbatim
#include <sqlpp11/verbatim_table.h>
#include <sqlpp11/value_or_null.h>
+14 -9
View File
@@ -35,16 +35,8 @@
namespace sqlpp
{
template<typename Operand, typename... Args>
struct in_t:
public expression_operators<in_t<Operand, Args...>, boolean>,
public alias_operators<in_t<Operand, Args...>>
struct in_alias_t
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Operand, Args...>;
static_assert(sizeof...(Args) > 0, "in() requires at least one argument");
struct _alias_t
{
static constexpr const char _literal[] = "in_";
@@ -55,6 +47,19 @@ namespace sqlpp
T in;
};
};
};
template<typename Operand, typename... Args>
struct in_t:
public expression_operators<in_t<Operand, Args...>, boolean>,
public alias_operators<in_t<Operand, Args...>>
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Operand, Args...>;
static_assert(sizeof...(Args) > 0, "in() requires at least one argument");
using _auto_alias_t = in_alias_t;
in_t(Operand operand, Args... args):
_operand(operand),
+12 -7
View File
@@ -34,14 +34,8 @@
namespace sqlpp
{
template<typename Operand>
struct is_not_null_t:
public expression_operators<is_not_null_t<Operand>, boolean>,
public alias_operators<is_not_null_t<Operand>>
struct is_not_null_alias_t
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Operand>;
struct _alias_t
{
static constexpr const char _literal[] = "is_not_null_";
@@ -52,6 +46,17 @@ namespace sqlpp
T is_not_null;
};
};
};
template<typename Operand>
struct is_not_null_t:
public expression_operators<is_not_null_t<Operand>, boolean>,
public alias_operators<is_not_null_t<Operand>>
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Operand>;
using _auto_alias_t = is_not_null_alias_t;
is_not_null_t(Operand operand):
_operand(operand)
+15 -10
View File
@@ -34,6 +34,20 @@
namespace sqlpp
{
struct is_null_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "is_null_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T is_null;
};
};
};
template<typename Operand>
struct is_null_t:
public expression_operators<is_null_t<Operand>, boolean>,
@@ -42,16 +56,7 @@ namespace sqlpp
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Operand>;
struct _alias_t
{
static constexpr const char _literal[] = "is_nnull_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T is_null;
};
};
using _auto_alias_t = is_null_alias_t;
is_null_t(Operand operand):
_operand(operand)
+12 -7
View File
@@ -32,14 +32,8 @@
namespace sqlpp
{
template<typename Expr>
struct max_t:
public expression_operators<max_t<Expr>, value_type_of<Expr>>,
public alias_operators<max_t<Expr>>
struct max_alias_t
{
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
struct _alias_t
{
static constexpr const char _literal[] = "max_";
@@ -52,6 +46,17 @@ namespace sqlpp
const T& operator()() const { return max; }
};
};
};
template<typename Expr>
struct max_t:
public expression_operators<max_t<Expr>, value_type_of<Expr>>,
public alias_operators<max_t<Expr>>
{
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
using _auto_alias_t = max_alias_t;
max_t(Expr expr):
_expr(expr)
+12 -7
View File
@@ -32,14 +32,8 @@
namespace sqlpp
{
template<typename Expr>
struct min_t:
public expression_operators<min_t<Expr>, value_type_of<Expr>>,
public alias_operators<min_t<Expr>>
struct min_alias_t
{
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
struct _alias_t
{
static constexpr const char _literal[] = "min_";
@@ -52,6 +46,17 @@ namespace sqlpp
const T& operator()() const { return min; }
};
};
};
template<typename Expr>
struct min_t:
public expression_operators<min_t<Expr>, value_type_of<Expr>>,
public alias_operators<min_t<Expr>>
{
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
using _auto_alias_t = min_alias_t;
min_t(Expr expr):
_expr(expr)
+15 -10
View File
@@ -35,6 +35,20 @@
namespace sqlpp
{
struct not_in_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "not_in_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T in;
};
};
};
template<typename Operand, typename... Args>
struct not_in_t:
public expression_operators<not_in_t<Operand, Args...>, boolean>,
@@ -45,16 +59,7 @@ namespace sqlpp
static_assert(sizeof...(Args) > 0, "not_in() requires at least one argument");
struct _alias_t
{
static constexpr const char _literal[] = "not_in_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T not_in;
};
};
using _auto_alias_t = not_in_alias_t;
not_in_t(Operand operand, Args... args):
_operand(operand),
+2 -2
View File
@@ -188,7 +188,7 @@ namespace sqlpp
template<typename NamedExpression, typename TableCheckRequired = std::true_type>
void add(NamedExpression namedExpression)
{
using named_expression = detail::auto_alias_t<NamedExpression>;
using named_expression = auto_alias_t<NamedExpression>;
static_assert(_is_dynamic::value, "selected_columns::add() can only be called for dynamic_column");
static_assert(is_selectable_t<named_expression>::value, "invalid named expression argument in selected_columns::add()");
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<named_expression>::value, "named expression uses tables unknown to this statement in selected_columns::add()");
@@ -210,7 +210,7 @@ namespace sqlpp
template<typename NamedExpression>
void _add_impl(NamedExpression namedExpression, const std::true_type&)
{
return _data._dynamic_columns.emplace_back(detail::auto_alias_t<NamedExpression>{namedExpression});
return _data._dynamic_columns.emplace_back(auto_alias_t<NamedExpression>{namedExpression});
}
template<typename NamedExpression>
-13
View File
@@ -39,19 +39,6 @@ namespace sqlpp
using _traits = make_traits<value_type_of<Select>, tag::is_multi_expression>;
using _nodes = detail::type_vector<Select>;
struct _alias_t
{
static constexpr const char _literal[] = "some_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T some;
T& operator()() { return some; }
const T& operator()() const { return some; }
};
};
some_t(Select select):
_select(select)
{}
+15 -10
View File
@@ -32,17 +32,8 @@
namespace sqlpp
{
template<typename Flag, typename Expr>
struct sum_t:
public expression_operators<sum_t<Flag, Expr>, value_type_of<Expr>>,
public alias_operators<sum_t<Flag, Expr>>
struct sum_alias_t
{
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value, "sum() used with flag other than 'distinct'");
static_assert(is_numeric_t<Expr>::value, "sum() requires a numeric expression as argument");
struct _alias_t
{
static constexpr const char _literal[] = "sum_";
@@ -55,6 +46,20 @@ namespace sqlpp
const T& operator()() const { return sum; }
};
};
};
template<typename Flag, typename Expr>
struct sum_t:
public expression_operators<sum_t<Flag, Expr>, value_type_of<Expr>>,
public alias_operators<sum_t<Flag, Expr>>
{
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value, "sum() used with flag other than 'distinct'");
static_assert(is_numeric_t<Expr>::value, "sum() requires a numeric expression as argument");
using _auto_alias_t = sum_alias_t;
sum_t(Expr expr):
_expr(expr)