mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
No more type traits in generated code
This commit is contained in:
parent
4baede7434
commit
08f643460c
@ -41,7 +41,8 @@ namespace sqlpp
|
||||
using _rhs_t = Rhs;
|
||||
using _nodes = detail::type_vector<_lhs_t, _rhs_t>;
|
||||
|
||||
static_assert(can_be_null_t<_lhs_t>::value ? true
|
||||
#warning: We check this in the factory function
|
||||
static_assert(can_be_null<_lhs_t>::value ? true
|
||||
: not std::is_same<_rhs_t, null_t>::value,
|
||||
"column must not be null");
|
||||
|
||||
|
@ -47,13 +47,11 @@ namespace sqlpp
|
||||
struct _traits
|
||||
{
|
||||
using _value_type = typename ColumnSpec::value_type;
|
||||
using _tags = detail::make_joined_set_t<detail::type_set<tag::is_column, tag::is_expression, tag::is_selectable>,
|
||||
typename ColumnSpec::_traits::_tags>;
|
||||
using _tags = detail::make_joined_set_t<detail::type_set<tag::is_column, tag::is_expression, tag::is_selectable>>;
|
||||
};
|
||||
|
||||
using _nodes = detail::type_vector<>;
|
||||
using _required_tables = detail::type_set<Table>;
|
||||
using _can_be_null = column_spec_can_be_null_t<ColumnSpec>;
|
||||
|
||||
using _spec_t = ColumnSpec;
|
||||
using _table = Table;
|
||||
@ -98,7 +96,7 @@ namespace sqlpp
|
||||
|
||||
auto operator=(null_t /*unused*/) const -> assignment_t<column_t, null_t>
|
||||
{
|
||||
static_assert(can_be_null_t<column_t>::value, "column cannot be null");
|
||||
static_assert(can_be_null<column_t>::value, "column cannot be null");
|
||||
return {*this, null_t{}};
|
||||
}
|
||||
|
||||
|
@ -94,8 +94,7 @@ namespace sqlpp
|
||||
{
|
||||
using _alias_t = typename FieldSpec::_alias_t;
|
||||
|
||||
using _traits = make_traits<value_type_of_t<FieldSpec>,
|
||||
tag_if<tag::can_be_null, column_spec_can_be_null_t<FieldSpec>::value>>;
|
||||
using _traits = make_traits<value_type_of_t<FieldSpec>>;
|
||||
};
|
||||
|
||||
template <typename AliasProvider, typename Statement, typename ResultRow>
|
||||
|
@ -60,7 +60,6 @@ namespace sqlpp
|
||||
using _traits = make_traits<text, tag::is_expression, tag::is_selectable>;
|
||||
|
||||
using _nodes = detail::type_vector<Expr>;
|
||||
using _can_be_null = can_be_null_t<Expr>;
|
||||
|
||||
using _auto_alias_t = lower_alias_t;
|
||||
|
||||
|
@ -45,7 +45,7 @@ namespace sqlpp
|
||||
#warning handle default_t, but only if the column does have a default!
|
||||
template <typename L, typename R>
|
||||
using check_assign_args = std::enable_if_t<is_column_t<L>::value and values_are_comparable<L, R>::value and
|
||||
(can_be_null_t<L>::value or not is_optional<R>::value) and
|
||||
(can_be_null<L>::value or not is_optional<R>::value) and
|
||||
(has_default_t<L>::value or not std::is_same<R, default_value_t>::value)>;
|
||||
|
||||
template <typename L, typename R, typename = check_assign_args<L, R>>
|
||||
|
@ -39,14 +39,14 @@ namespace sqlpp
|
||||
{
|
||||
using _alias_t = typename NamedExpr::_alias_t;
|
||||
|
||||
static constexpr bool _can_be_null = can_be_null_t<NamedExpr>::value;
|
||||
static constexpr bool _depends_on_outer_table =
|
||||
detail::make_intersect_set_t<required_tables_of<NamedExpr>, typename Select::_used_outer_tables>::size::value >
|
||||
0;
|
||||
|
||||
#warning: somehow prevent insert...
|
||||
using _traits = make_traits<value_type_of_t<NamedExpr>,
|
||||
tag_if<tag::can_be_null, _can_be_null or _depends_on_outer_table>>;
|
||||
#warning: may need to make value type optional for outer tables
|
||||
using _traits = make_traits<value_type_of_t<NamedExpr>/*,
|
||||
tag_if<tag::can_be_null, _depends_on_outer_table>*/>;
|
||||
};
|
||||
|
||||
template<typename... NamedExpr>
|
||||
@ -60,7 +60,6 @@ namespace sqlpp
|
||||
struct select_expression_type<NamedExpr> {
|
||||
using value_t = value_type_of_t<NamedExpr>;
|
||||
static constexpr bool _is_expression = true;
|
||||
static constexpr bool _can_be_null = can_be_null_t<NamedExpr>::value;
|
||||
};
|
||||
|
||||
template <typename Select, typename... NamedExpr>
|
||||
@ -72,7 +71,6 @@ namespace sqlpp
|
||||
// Usage as named expression
|
||||
typename _expr_t::value_t,
|
||||
tag_if<tag::is_expression, _expr_t::_is_expression>,
|
||||
tag_if<tag::can_be_null, _expr_t::_can_be_null>,
|
||||
// Usage as table
|
||||
tag::is_table,
|
||||
tag::is_pseudo_table,
|
||||
|
@ -138,9 +138,12 @@ namespace sqlpp
|
||||
make_traits<_value_type, tag_if<tag::is_expression, not std::is_same<_value_type, no_value_t>::value>>;
|
||||
|
||||
using _nodes = detail::type_vector<>;
|
||||
#warning: maybe need to make value type optional
|
||||
/*
|
||||
using _can_be_null = logic::any_t<can_be_null_t<_result_type_provider>::value,
|
||||
detail::make_intersect_set_t<required_tables_of<_result_type_provider>,
|
||||
_all_provided_outer_tables>::size::value != 0>;
|
||||
*/
|
||||
using _parameters = detail::type_vector_cat_t<parameters_of<Policies>...>;
|
||||
// required_tables and _required_ctes are defined above
|
||||
|
||||
|
@ -44,7 +44,6 @@ namespace sqlpp
|
||||
using _traits = make_traits<value_type_of_t<Table>,
|
||||
tag::is_table,
|
||||
tag::is_alias,
|
||||
tag_if<tag::can_be_null, can_be_null_t<Table>::value>,
|
||||
tag_if<tag::is_selectable, is_expression_t<Table>::value>>;
|
||||
|
||||
using _nodes = detail::type_vector<>;
|
||||
|
@ -61,7 +61,6 @@ namespace sqlpp
|
||||
using _traits = make_traits<text, tag::is_expression, tag::is_selectable>;
|
||||
|
||||
using _nodes = detail::type_vector<Expr>;
|
||||
using _can_be_null = can_be_null_t<Expr>;
|
||||
|
||||
using _auto_alias_t = trim_alias_t;
|
||||
|
||||
|
@ -412,30 +412,8 @@ namespace sqlpp
|
||||
template <typename T>
|
||||
using is_day_or_time_point_t = logic::any_t<is_day_point_t<T>::value, is_time_point_t<T>::value>;
|
||||
|
||||
namespace tag
|
||||
{
|
||||
struct can_be_null
|
||||
{
|
||||
};
|
||||
} // namespace tag
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <typename T, typename Enable = void>
|
||||
struct column_spec_can_be_null_impl
|
||||
{
|
||||
using type = std::false_type;
|
||||
};
|
||||
template <typename T>
|
||||
struct column_spec_can_be_null_impl<
|
||||
T,
|
||||
typename std::enable_if<detail::is_element_of<tag::can_be_null, typename T::_traits::_tags>::value>::type>
|
||||
{
|
||||
using type = std::true_type;
|
||||
};
|
||||
} // namespace detail
|
||||
template <typename T>
|
||||
using column_spec_can_be_null_t = typename detail::column_spec_can_be_null_impl<T>::type;
|
||||
struct can_be_null : public is_optional<value_type_of_t<T>> {};
|
||||
|
||||
#define SQLPP_VALUE_TRAIT_GENERATOR(name) \
|
||||
namespace tag \
|
||||
@ -597,7 +575,6 @@ namespace sqlpp
|
||||
template <typename T> \
|
||||
using trait##_t = typename detail::trait##_impl<T>::type;
|
||||
|
||||
SQLPP_RECURSIVE_TRAIT_GENERATOR(can_be_null)
|
||||
SQLPP_RECURSIVE_TRAIT_GENERATOR(contains_aggregate_function)
|
||||
|
||||
template <typename ValueType, typename T>
|
||||
|
@ -60,7 +60,6 @@ namespace sqlpp
|
||||
using _traits = make_traits<text, tag::is_expression, tag::is_selectable>;
|
||||
|
||||
using _nodes = detail::type_vector<Expr>;
|
||||
using _can_be_null = can_be_null_t<Expr>;
|
||||
|
||||
using _auto_alias_t = upper_alias_t;
|
||||
|
||||
|
@ -703,8 +703,6 @@ def createHeader():
|
||||
)
|
||||
print("You can disable this warning using -no-timestamp-warning")
|
||||
noTimestampWarning = True
|
||||
traitslist = ["::sqlpp::" + columnType]
|
||||
columnCanBeNull = not column.notNull and not column.isPrimaryKey
|
||||
print(" struct " + columnClass, file=header)
|
||||
print(" {", file=header)
|
||||
print(" struct _alias_t", file=header)
|
||||
@ -735,21 +733,19 @@ def createHeader():
|
||||
)
|
||||
print(" };", file=header)
|
||||
print(" };", file=header)
|
||||
hasAutoValue = column.hasAutoValue or (autoId and sqlColumnName == "id")
|
||||
if columnCanBeNull:
|
||||
traitslist.append("::sqlpp::tag::can_be_null")
|
||||
if column.hasDefaultValue or hasAutoValue or columnCanBeNull:
|
||||
traitslist.append("::sqlpp::tag::has_default")
|
||||
columnCanBeNull = not column.notNull and not column.isPrimaryKey
|
||||
if columnCanBeNull:
|
||||
print(" using value_type = ::sqlpp::compat::optional<::sqlpp::" + columnType + ">;", file=header)
|
||||
else:
|
||||
print(" using value_type = ::sqlpp::" + columnType + ";", file=header)
|
||||
print(
|
||||
" using _traits = ::sqlpp::make_traits<"
|
||||
+ ", ".join(traitslist)
|
||||
+ ">;",
|
||||
file=header,
|
||||
)
|
||||
columnHasDefault = column.hasDefaultValue or \
|
||||
columnCanBeNull or \
|
||||
column.hasAutoValue or \
|
||||
(autoId and sqlColumnName == "id")
|
||||
if columnHasDefault:
|
||||
print(" using has_default_value = std::true_type;", file=header)
|
||||
else:
|
||||
print(" using has_default_value = std::false_type;", file=header)
|
||||
print(" };", file=header)
|
||||
print(" } // namespace " + tableNamespace, file=header)
|
||||
print("", file=header)
|
||||
|
@ -44,12 +44,12 @@ namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert(not sqlpp::can_be_null_t<decltype(bar.id)>::value, "");
|
||||
static_assert(sqlpp::can_be_null_t<decltype(foo.doubleN)>::value, "");
|
||||
static_assert(not sqlpp::can_be_null_t<decltype(foo.textNnD)>::value, "");
|
||||
static_assert(not sqlpp::can_be_null_t<decltype(bar.boolNn)>::value, "");
|
||||
static_assert(not sqlpp::can_be_null<decltype(bar.id)>::value, "");
|
||||
static_assert(sqlpp::can_be_null<decltype(foo.doubleN)>::value, "");
|
||||
static_assert(not sqlpp::can_be_null<decltype(foo.textNnD)>::value, "");
|
||||
static_assert(not sqlpp::can_be_null<decltype(bar.boolNn)>::value, "");
|
||||
const auto seven = sqlpp::value(7).as(sqlpp::alias::s);
|
||||
static_assert(not sqlpp::can_be_null_t<decltype(seven)>::value, "");
|
||||
static_assert(not sqlpp::can_be_null<decltype(seven)>::value, "");
|
||||
|
||||
// Select non-optional column or alias of it.
|
||||
for (const auto& row : db(select(foo.id, foo.id.as(sqlpp::alias::a), foo.textNnD, foo.textNnD.as(sqlpp::alias::b))
|
||||
@ -319,8 +319,8 @@ int main()
|
||||
// aggregates of nullable values
|
||||
#warning use a nullable value
|
||||
const auto a = bar.id;
|
||||
static_assert(not sqlpp::can_be_null_t<decltype(bar.id)>::value, "");
|
||||
static_assert(not sqlpp::can_be_null_t<decltype(a)>::value, "");
|
||||
static_assert(not sqlpp::can_be_null<decltype(bar.id)>::value, "");
|
||||
static_assert(not sqlpp::can_be_null<decltype(a)>::value, "");
|
||||
const auto rows = db(select(count(a), avg(a), max(a), min(a), sum(a)).from(bar).unconditionally());
|
||||
auto& x = rows.front();
|
||||
static_assert(not is_optional<decltype(x.count)>::value, "");
|
||||
@ -332,8 +332,8 @@ int main()
|
||||
{
|
||||
// aggregates of nullable values
|
||||
const auto o = foo.doubleN;
|
||||
static_assert(sqlpp::can_be_null_t<decltype(foo.doubleN)>::value, "");
|
||||
static_assert(sqlpp::can_be_null_t<decltype(o)>::value, "");
|
||||
static_assert(sqlpp::can_be_null<decltype(foo.doubleN)>::value, "");
|
||||
static_assert(sqlpp::can_be_null<decltype(o)>::value, "");
|
||||
const auto rows = db(select(count(o), avg(o), max(o), min(o), sum(o)).from(foo).unconditionally());
|
||||
auto& x = rows.front();
|
||||
static_assert(not is_optional<decltype(x.count)>::value, "");
|
||||
|
@ -25,7 +25,7 @@ namespace test
|
||||
};
|
||||
};
|
||||
using value_type = ::sqlpp::integer;
|
||||
using _traits = ::sqlpp::make_traits<::sqlpp::integer, ::sqlpp::tag::has_default>;
|
||||
using has_default_value = std::true_type;
|
||||
};
|
||||
struct TextNnD
|
||||
{
|
||||
@ -42,7 +42,7 @@ namespace test
|
||||
};
|
||||
};
|
||||
using value_type = ::sqlpp::text;
|
||||
using _traits = ::sqlpp::make_traits<::sqlpp::text, ::sqlpp::tag::has_default>;
|
||||
using has_default_value = std::true_type;
|
||||
};
|
||||
struct IntN
|
||||
{
|
||||
@ -59,7 +59,7 @@ namespace test
|
||||
};
|
||||
};
|
||||
using value_type = ::sqlpp::compat::optional<::sqlpp::integer>;
|
||||
using _traits = ::sqlpp::make_traits<::sqlpp::integer, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
|
||||
using has_default_value = std::true_type;
|
||||
};
|
||||
struct DoubleN
|
||||
{
|
||||
@ -76,7 +76,7 @@ namespace test
|
||||
};
|
||||
};
|
||||
using value_type = ::sqlpp::compat::optional<::sqlpp::floating_point>;
|
||||
using _traits = ::sqlpp::make_traits<::sqlpp::floating_point, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
|
||||
using has_default_value = std::true_type;
|
||||
};
|
||||
struct UIntN
|
||||
{
|
||||
@ -93,7 +93,7 @@ namespace test
|
||||
};
|
||||
};
|
||||
using value_type = ::sqlpp::compat::optional<::sqlpp::integer_unsigned>;
|
||||
using _traits = ::sqlpp::make_traits<::sqlpp::integer_unsigned, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
|
||||
using has_default_value = std::true_type;
|
||||
};
|
||||
struct BlobN
|
||||
{
|
||||
@ -110,7 +110,7 @@ namespace test
|
||||
};
|
||||
};
|
||||
using value_type = ::sqlpp::compat::optional<::sqlpp::blob>;
|
||||
using _traits = ::sqlpp::make_traits<::sqlpp::blob, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
|
||||
using has_default_value = std::true_type;
|
||||
};
|
||||
} // namespace TabFoo_
|
||||
|
||||
@ -152,7 +152,7 @@ namespace test
|
||||
};
|
||||
};
|
||||
using value_type = ::sqlpp::integer;
|
||||
using _traits = ::sqlpp::make_traits<::sqlpp::integer, ::sqlpp::tag::has_default>;
|
||||
using has_default_value = std::true_type;
|
||||
};
|
||||
struct TextN
|
||||
{
|
||||
@ -169,7 +169,7 @@ namespace test
|
||||
};
|
||||
};
|
||||
using value_type = ::sqlpp::compat::optional<::sqlpp::text>;
|
||||
using _traits = ::sqlpp::make_traits<::sqlpp::text, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
|
||||
using has_default_value = std::true_type;
|
||||
};
|
||||
struct BoolNn
|
||||
{
|
||||
@ -186,7 +186,7 @@ namespace test
|
||||
};
|
||||
};
|
||||
using value_type = ::sqlpp::boolean;
|
||||
using _traits = ::sqlpp::make_traits<::sqlpp::boolean>;
|
||||
using has_default_value = std::false_type;
|
||||
};
|
||||
struct IntN
|
||||
{
|
||||
@ -203,7 +203,7 @@ namespace test
|
||||
};
|
||||
};
|
||||
using value_type = ::sqlpp::compat::optional<::sqlpp::integer>;
|
||||
using _traits = ::sqlpp::make_traits<::sqlpp::integer, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
|
||||
using has_default_value = std::true_type;
|
||||
};
|
||||
} // namespace TabBar_
|
||||
|
||||
@ -243,7 +243,7 @@ namespace test
|
||||
};
|
||||
};
|
||||
using value_type = ::sqlpp::integer;
|
||||
using _traits = ::sqlpp::make_traits<::sqlpp::integer, ::sqlpp::tag::has_default>;
|
||||
using has_default_value = std::true_type;
|
||||
};
|
||||
struct DayPointN
|
||||
{
|
||||
@ -260,7 +260,7 @@ namespace test
|
||||
};
|
||||
};
|
||||
using value_type = ::sqlpp::compat::optional<::sqlpp::day_point>;
|
||||
using _traits = ::sqlpp::make_traits<::sqlpp::day_point, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
|
||||
using has_default_value = std::true_type;
|
||||
};
|
||||
struct TimePointN
|
||||
{
|
||||
@ -277,7 +277,7 @@ namespace test
|
||||
};
|
||||
};
|
||||
using value_type = ::sqlpp::compat::optional<::sqlpp::time_point>;
|
||||
using _traits = ::sqlpp::make_traits<::sqlpp::time_point, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
|
||||
using has_default_value = std::true_type;
|
||||
};
|
||||
struct TimeOfDayN
|
||||
{
|
||||
@ -294,7 +294,7 @@ namespace test
|
||||
};
|
||||
};
|
||||
using value_type = ::sqlpp::compat::optional<::sqlpp::time_of_day>;
|
||||
using _traits = ::sqlpp::make_traits<::sqlpp::time_of_day, ::sqlpp::tag::can_be_null, ::sqlpp::tag::has_default>;
|
||||
using has_default_value = std::true_type;
|
||||
};
|
||||
} // namespace TabDateTime_
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user