diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 31da39a2..47bb5c78 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -42,10 +42,15 @@ namespace sqlpp { template - struct column_t: public ColumnSpec::_value_type::template expression_operators>, - public ColumnSpec::_value_type::template column_operators> + struct column_t: public value_type_of::template expression_operators>, + public value_type_of::template column_operators> { - using _traits = make_traits; + struct _traits + { + using _value_type = value_type_of; + using _tags = detail::make_joined_set_t, 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 - using _is_valid_operand = typename ColumnSpec::_value_type::template _is_valid_operand; + using _is_valid_operand = typename value_type_of::template _is_valid_operand; column_t() = default; column_t(const column_t&) = default; diff --git a/include/sqlpp11/select_pseudo_table.h b/include/sqlpp11/select_pseudo_table.h index 7530df7f..76286742 100644 --- a/include/sqlpp11/select_pseudo_table.h +++ b/include/sqlpp11/select_pseudo_table.h @@ -32,19 +32,13 @@ namespace sqlpp { // provide type information for sub-selects that are used as named expressions or tables - template + template struct select_column_spec_t { - using _traits = make_traits; - 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, 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_column_spec_t, typename NamedExpr::_name_t>...> + NamedExpr...>, select_column_spec_t...> { using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 2e05b10a..9bf63bfc 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -32,6 +32,21 @@ namespace sqlpp { +#define SQLPP_VALUE_TRAIT_GENERATOR(name) \ + namespace tag\ + {\ + struct name{};\ + };\ + namespace detail\ + {\ + template\ + struct name##_impl { using type = std::false_type; };\ + template\ + struct name##_impl::value>::type> { using type = std::true_type; };\ + }\ + template\ + using name##_t = typename detail::name##_impl::type; + #define SQLPP_IS_VALUE_TRAIT_GENERATOR(name) \ namespace tag\ {\ @@ -47,17 +62,6 @@ namespace sqlpp template\ using is_##name##_t = typename detail::is_##name##_impl::type; -#define SQLPP_IS_COLUMN_TRAIT_GENERATOR(name) \ - namespace detail\ - {\ - template\ - struct name##_impl { using type = std::false_type; };\ - template\ - struct name##_impl::value>::type> { using type = std::true_type; };\ - }\ - template\ - using name##_t = typename detail::name##_impl::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); diff --git a/include/sqlpp11/verbatim_table.h b/include/sqlpp11/verbatim_table.h index dbacdb9d..2a4ae805 100644 --- a/include/sqlpp11/verbatim_table.h +++ b/include/sqlpp11/verbatim_table.h @@ -42,8 +42,7 @@ namespace sqlpp { }; }; - using _value_type = no_value_t; - struct _column_type {}; + using _traits = make_traits; }; } diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index e65cf233..9fbeabb2 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -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) diff --git a/tests/Sample.h b/tests/Sample.h index 33eb36e0..4ba3774d 100644 --- a/tests/Sample.h +++ b/tests/Sample.h @@ -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; }; 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; }; 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; }; } @@ -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; }; 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; }; 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; }; 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; }; }