mirror of
https://github.com/rbock/sqlpp11.git
synced 2025-12-31 10:10:28 -06:00
Use _traits in column specs
This commit is contained in:
@@ -42,10 +42,15 @@
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename Table, typename ColumnSpec>
|
||||
struct column_t: public ColumnSpec::_value_type::template expression_operators<column_t<Table, ColumnSpec>>,
|
||||
public ColumnSpec::_value_type::template column_operators<column_t<Table, ColumnSpec>>
|
||||
struct column_t: public value_type_of<ColumnSpec>::template expression_operators<column_t<Table, ColumnSpec>>,
|
||||
public value_type_of<ColumnSpec>::template column_operators<column_t<Table, ColumnSpec>>
|
||||
{
|
||||
using _traits = make_traits<typename ColumnSpec::_value_type, tag::column, tag::expression, tag::named_expression>;
|
||||
struct _traits
|
||||
{
|
||||
using _value_type = value_type_of<ColumnSpec>;
|
||||
using _tags = detail::make_joined_set_t<detail::type_set<tag::column, tag::expression, tag::named_expression>, typename ColumnSpec::_traits::_tags>;
|
||||
};
|
||||
|
||||
struct _recursive_traits
|
||||
{
|
||||
using _parameters = std::tuple<>;
|
||||
@@ -56,11 +61,10 @@ namespace sqlpp
|
||||
|
||||
using _spec_t = ColumnSpec;
|
||||
using _table = Table;
|
||||
using _column_type = typename _spec_t::_column_type;
|
||||
using _name_t = typename _spec_t::_name_t;
|
||||
|
||||
template<typename T>
|
||||
using _is_valid_operand = typename ColumnSpec::_value_type::template _is_valid_operand<T>;
|
||||
using _is_valid_operand = typename value_type_of<ColumnSpec>::template _is_valid_operand<T>;
|
||||
|
||||
column_t() = default;
|
||||
column_t(const column_t&) = default;
|
||||
|
||||
@@ -32,19 +32,13 @@
|
||||
namespace sqlpp
|
||||
{
|
||||
// provide type information for sub-selects that are used as named expressions or tables
|
||||
template<typename ValueType, typename NameType>
|
||||
template<typename NamedExpr>
|
||||
struct select_column_spec_t
|
||||
{
|
||||
using _traits = make_traits<ValueType>;
|
||||
using _recursive_traits = make_recursive_traits<>;
|
||||
using _value_type = ValueType; // FIXME: column specs probably should use _traits, too
|
||||
using _name_t = typename NamedExpr::_name_t;
|
||||
|
||||
using _name_t = NameType;
|
||||
struct _column_type
|
||||
{
|
||||
using _must_not_insert = std::true_type;
|
||||
using _must_not_update = std::true_type;
|
||||
};
|
||||
#warning take can_be_null from named expression...
|
||||
using _traits = make_traits<value_type_of<NamedExpr>, tag::must_not_insert, tag::must_not_update>;
|
||||
};
|
||||
|
||||
template<
|
||||
@@ -53,7 +47,7 @@ namespace sqlpp
|
||||
>
|
||||
struct select_pseudo_table_t: public sqlpp::table_t<select_pseudo_table_t<
|
||||
Select,
|
||||
NamedExpr...>, select_column_spec_t<value_type_of<NamedExpr>, typename NamedExpr::_name_t>...>
|
||||
NamedExpr...>, select_column_spec_t<NamedExpr>...>
|
||||
{
|
||||
using _traits = make_traits<no_value_t, tag::table, tag::pseudo_table>;
|
||||
using _recursive_traits = make_recursive_traits<>;
|
||||
|
||||
@@ -32,6 +32,21 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
#define SQLPP_VALUE_TRAIT_GENERATOR(name) \
|
||||
namespace tag\
|
||||
{\
|
||||
struct name{};\
|
||||
};\
|
||||
namespace detail\
|
||||
{\
|
||||
template<typename T, typename Enable = void>\
|
||||
struct name##_impl { using type = std::false_type; };\
|
||||
template<typename T>\
|
||||
struct name##_impl<T, typename std::enable_if<detail::is_element_of<tag::name, typename T::_traits::_tags>::value>::type> { using type = std::true_type; };\
|
||||
}\
|
||||
template<typename T>\
|
||||
using name##_t = typename detail::name##_impl<T>::type;
|
||||
|
||||
#define SQLPP_IS_VALUE_TRAIT_GENERATOR(name) \
|
||||
namespace tag\
|
||||
{\
|
||||
@@ -47,17 +62,6 @@ namespace sqlpp
|
||||
template<typename T>\
|
||||
using is_##name##_t = typename detail::is_##name##_impl<T>::type;
|
||||
|
||||
#define SQLPP_IS_COLUMN_TRAIT_GENERATOR(name) \
|
||||
namespace detail\
|
||||
{\
|
||||
template<typename T, typename Enable = void>\
|
||||
struct name##_impl { using type = std::false_type; };\
|
||||
template<typename T>\
|
||||
struct name##_impl<T, typename std::enable_if<std::is_same<typename T::_column_type::_##name, std::true_type>::value>::type> { using type = std::true_type; };\
|
||||
}\
|
||||
template<typename T>\
|
||||
using name##_t = typename detail::name##_impl<T>::type;
|
||||
|
||||
#define SQLPP_TYPE_TRAIT_GENERATOR(name) \
|
||||
namespace detail\
|
||||
{\
|
||||
@@ -105,11 +109,11 @@ namespace sqlpp
|
||||
SQLPP_IS_VALUE_TRAIT_GENERATOR(alias);
|
||||
SQLPP_IS_VALUE_TRAIT_GENERATOR(select_flag);
|
||||
|
||||
SQLPP_IS_COLUMN_TRAIT_GENERATOR(must_not_insert);
|
||||
SQLPP_IS_COLUMN_TRAIT_GENERATOR(must_not_update);
|
||||
SQLPP_IS_COLUMN_TRAIT_GENERATOR(require_insert);
|
||||
SQLPP_IS_COLUMN_TRAIT_GENERATOR(can_be_null);
|
||||
SQLPP_IS_COLUMN_TRAIT_GENERATOR(trivial_value_is_null);
|
||||
SQLPP_VALUE_TRAIT_GENERATOR(must_not_insert);
|
||||
SQLPP_VALUE_TRAIT_GENERATOR(must_not_update);
|
||||
SQLPP_VALUE_TRAIT_GENERATOR(require_insert);
|
||||
SQLPP_VALUE_TRAIT_GENERATOR(can_be_null);
|
||||
SQLPP_VALUE_TRAIT_GENERATOR(trivial_value_is_null);
|
||||
|
||||
SQLPP_IS_VALUE_TRAIT_GENERATOR(noop);
|
||||
SQLPP_IS_VALUE_TRAIT_GENERATOR(missing);
|
||||
|
||||
@@ -42,8 +42,7 @@ namespace sqlpp
|
||||
{
|
||||
};
|
||||
};
|
||||
using _value_type = no_value_t;
|
||||
struct _column_type {};
|
||||
using _traits = make_traits<no_value_t>;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -155,22 +155,20 @@ for tableCreation in tableCreations:
|
||||
print(' };', file=header)
|
||||
print(' };', file=header)
|
||||
#print(sqlColumnType)
|
||||
print(' using _value_type = ' + NAMESPACE + '::' + types[sqlColumnType] + ';', file=header)
|
||||
print(' struct _column_type', file=header)
|
||||
print(' {', file=header)
|
||||
traitslist = [NAMESPACE + '::' + types[sqlColumnType]];
|
||||
requireInsert = True
|
||||
if column.hasAutoValue:
|
||||
print(' using _must_not_insert = std::true_type;', file=header)
|
||||
print(' using _must_not_update = std::true_type;', file=header)
|
||||
traitslist.append(NAMESPACE + '::tag::must_not_insert');
|
||||
traitslist.append(NAMESPACE + '::tag::must_not_update');
|
||||
requireInsert = False
|
||||
if not column.notNull:
|
||||
print(' using _can_be_null = std::true_type;', file=header)
|
||||
traitslist.append(NAMESPACE + '::tag::can_be_null');
|
||||
requireInsert = False
|
||||
if column.hasDefaultValue:
|
||||
requireInsert = False
|
||||
if requireInsert:
|
||||
print(' using _require_insert = std::true_type;', file=header)
|
||||
print(' };', file=header)
|
||||
traitslist.append(NAMESPACE + '::tag::require_insert');
|
||||
print(' using _traits = ' + NAMESPACE + '::make_traits<' + ', '.join(traitslist) + '>;', file=header)
|
||||
print(' };', file=header)
|
||||
print(' }', file=header)
|
||||
print('', file=header)
|
||||
|
||||
@@ -21,11 +21,7 @@ namespace test
|
||||
const T& operator()() const { return delta; }
|
||||
};
|
||||
};
|
||||
using _value_type = sqlpp::varchar;
|
||||
struct _column_type
|
||||
{
|
||||
using _can_be_null = std::true_type;
|
||||
};
|
||||
using _traits = sqlpp::make_traits<sqlpp::varchar, sqlpp::tag::can_be_null>;
|
||||
};
|
||||
struct Epsilon
|
||||
{
|
||||
@@ -40,11 +36,7 @@ namespace test
|
||||
const T& operator()() const { return epsilon; }
|
||||
};
|
||||
};
|
||||
using _value_type = sqlpp::bigint;
|
||||
struct _column_type
|
||||
{
|
||||
using _can_be_null = std::true_type;
|
||||
};
|
||||
using _traits = sqlpp::make_traits<sqlpp::bigint, sqlpp::tag::can_be_null>;
|
||||
};
|
||||
struct Omega
|
||||
{
|
||||
@@ -59,11 +51,7 @@ namespace test
|
||||
const T& operator()() const { return omega; }
|
||||
};
|
||||
};
|
||||
using _value_type = sqlpp::floating_point;
|
||||
struct _column_type
|
||||
{
|
||||
using _can_be_null = std::true_type;
|
||||
};
|
||||
using _traits = sqlpp::make_traits<sqlpp::floating_point, sqlpp::tag::can_be_null>;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -100,13 +88,7 @@ namespace test
|
||||
const T& operator()() const { return alpha; }
|
||||
};
|
||||
};
|
||||
using _value_type = sqlpp::bigint;
|
||||
struct _column_type
|
||||
{
|
||||
using _must_not_insert = std::true_type;
|
||||
using _must_not_update = std::true_type;
|
||||
using _can_be_null = std::true_type;
|
||||
};
|
||||
using _traits = sqlpp::make_traits<sqlpp::bigint, sqlpp::tag::must_not_insert, sqlpp::tag::must_not_update, sqlpp::tag::can_be_null>;
|
||||
};
|
||||
struct Beta
|
||||
{
|
||||
@@ -121,11 +103,7 @@ namespace test
|
||||
const T& operator()() const { return beta; }
|
||||
};
|
||||
};
|
||||
using _value_type = sqlpp::varchar;
|
||||
struct _column_type
|
||||
{
|
||||
using _can_be_null = std::true_type;
|
||||
};
|
||||
using _traits = sqlpp::make_traits<sqlpp::varchar, sqlpp::tag::can_be_null>;
|
||||
};
|
||||
struct Gamma
|
||||
{
|
||||
@@ -140,11 +118,7 @@ namespace test
|
||||
const T& operator()() const { return gamma; }
|
||||
};
|
||||
};
|
||||
using _value_type = sqlpp::boolean;
|
||||
struct _column_type
|
||||
{
|
||||
using _require_insert = std::true_type;
|
||||
};
|
||||
using _traits = sqlpp::make_traits<sqlpp::boolean, sqlpp::tag::require_insert>;
|
||||
};
|
||||
struct Delta
|
||||
{
|
||||
@@ -159,11 +133,7 @@ namespace test
|
||||
const T& operator()() const { return delta; }
|
||||
};
|
||||
};
|
||||
using _value_type = sqlpp::integer;
|
||||
struct _column_type
|
||||
{
|
||||
using _can_be_null = std::true_type;
|
||||
};
|
||||
using _traits = sqlpp::make_traits<sqlpp::integer, sqlpp::tag::can_be_null>;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user