From 982812abccae81ab434c48ac9e797f76314358f0 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sun, 20 Oct 2024 11:15:10 +0200 Subject: [PATCH] Cleanup --- include/sqlpp11/core/basic/join.h | 2 - include/sqlpp11/core/basic/table_ref.h | 14 ------ include/sqlpp11/core/clause/cte.h | 60 +++++++------------------ include/sqlpp11/core/clause/from.h | 6 +-- include/sqlpp11/core/eval.h | 18 +++----- include/sqlpp11/core/field_spec.h | 7 ++- include/sqlpp11/core/query/result_row.h | 4 +- 7 files changed, 30 insertions(+), 81 deletions(-) diff --git a/include/sqlpp11/core/basic/join.h b/include/sqlpp11/core/basic/join.h index a05e1ecf..75e1f12a 100644 --- a/include/sqlpp11/core/basic/join.h +++ b/include/sqlpp11/core/basic/join.h @@ -107,7 +107,6 @@ namespace sqlpp auto to_sql_string(Context& context, const join_t& t) -> std::string { static_assert(not std::is_same::value, ""); -#warning: need to enclose with from_table here to turn this into table_ref (important for CTE) return to_sql_string(context, t._lhs) + JoinType::_name + to_sql_string(context, t._rhs) + " ON " + to_sql_string(context, t._condition); } @@ -187,7 +186,6 @@ namespace sqlpp // Note: See sqlpp11/core/basic/join_fwd.h for forward declarations including check_join_args. -#warning: reactivate check_join_args? template */> auto join(Lhs lhs, Rhs rhs) -> pre_join_t, inner_join_t, table_ref_t> { diff --git a/include/sqlpp11/core/basic/table_ref.h b/include/sqlpp11/core/basic/table_ref.h index 98c8d5ff..86be0a23 100644 --- a/include/sqlpp11/core/basic/table_ref.h +++ b/include/sqlpp11/core/basic/table_ref.h @@ -30,20 +30,6 @@ namespace sqlpp { - template - auto from_table(T t) -> T - { - return t; - } - - template - struct from_table_impl - { - using type = T; - }; - template - using from_table_t = typename from_table_impl::type; - template auto make_table_ref(T t) -> T { diff --git a/include/sqlpp11/core/clause/cte.h b/include/sqlpp11/core/clause/cte.h index 75e26521..01ec9733 100644 --- a/include/sqlpp11/core/clause/cte.h +++ b/include/sqlpp11/core/clause/cte.h @@ -88,54 +88,19 @@ namespace sqlpp return {}; } - template - auto from_table(cte_t /*unused*/) -> cte_ref_t - { - return cte_ref_t{}; - } - - template - struct from_table_impl> - { - using type = cte_ref_t; - }; - -#warning: Why can't we use FieldSpec directly? If not, does this one need to inherit from name_tag_base? - template - struct cte_column_spec_t - { - using _sqlpp_name_tag = name_tag_of_t; - - using value_type = value_type_of_t; - }; - - template - struct name_tag_of> : public name_tag_of{}; - + // make_cte translates the `Statement` into field_specs... + // The field_specs are required to add column data members to the CTE. template - struct make_cte_impl - { - using type = void; - }; + struct make_cte; template - struct make_cte_impl> + struct make_cte> { using type = cte_t; }; template - using make_cte_t = typename make_cte_impl>::type; - - // workaround for msvc unknown internal error - // template - // struct cte_t - // : public member_t, column_t>>... - template - struct cte_base - { - using type = member_t, cte_column_spec_t>>; - }; + using make_cte_t = typename make_cte>::type; template struct union_cte_impl @@ -162,9 +127,18 @@ namespace sqlpp template using check_cte_union_t = typename check_cte_union::type; - template - struct cte_t : public cte_base::type..., public enable_join> + // cte_member is a helper to add column data members to `cte_t`. + template + struct cte_member { + using type = member_t, FieldSpec>>; + }; + + template + struct cte_t : public cte_member::type..., + public enable_join> + { +#warning: remove using _traits = make_traits; using _nodes = detail::type_vector<>; using _provided_tables = detail::type_set; @@ -173,7 +147,7 @@ namespace sqlpp constexpr static bool _is_recursive = required_ctes_of::template count(); - using _column_tuple_t = std::tuple>...>; + using _column_tuple_t = std::tuple, FieldSpecs>...>; using _result_row_t = result_row_t; diff --git a/include/sqlpp11/core/clause/from.h b/include/sqlpp11/core/clause/from.h index 890582d3..141d2fad 100644 --- a/include/sqlpp11/core/clause/from.h +++ b/include/sqlpp11/core/clause/from.h @@ -116,7 +116,7 @@ namespace sqlpp using _consistency_check = consistent_t; template - auto from(Table table) const -> _new_statement_t, from_t>> + auto from(Table table) const -> _new_statement_t, from_t>> { using Check = check_from_static_t; return _from_impl(Check{}, table); @@ -128,10 +128,10 @@ namespace sqlpp template auto _from_impl(consistent_t /*unused*/, Table table) const - -> _new_statement_t>> + -> _new_statement_t>> { return {static_cast&>(*this), - from_data_t>{from_table(table)}}; + from_data_t>{make_table_ref(table)}}; } }; }; diff --git a/include/sqlpp11/core/eval.h b/include/sqlpp11/core/eval.h index 356a2729..750f7bff 100644 --- a/include/sqlpp11/core/eval.h +++ b/include/sqlpp11/core/eval.h @@ -33,26 +33,18 @@ namespace sqlpp { - template - struct eval_t +#warning: Need to add tests for eval. + template ::value, int>::type = 0> + auto eval(Db& db, Expr expr) -> result_value_t> { static_assert(is_database::value, "Db parameter of eval has to be a database connection"); static_assert(is_expression_t::value, "Expression parameter of eval has to be an sqlpp expression or a string"); static_assert(required_tables_of_t::size::value == 0, "Expression cannot be used in eval because it requires tables"); - using _name_type = alias::a_t; - using _value_type = value_type_of_t; -#warning: Or do we expect users to provide the optional, too? - using _field_spec = field_spec_t<_name_type, ::sqlpp::optional<_value_type>>; - using type = typename _field_spec::cpp_type; - }; - template ::value, int>::type = 0> - auto eval(Db& db, Expr expr) -> typename eval_t::type - { return db(select(expr.as(alias::a))).front().a; } diff --git a/include/sqlpp11/core/field_spec.h b/include/sqlpp11/core/field_spec.h index 34542baf..1587d956 100644 --- a/include/sqlpp11/core/field_spec.h +++ b/include/sqlpp11/core/field_spec.h @@ -35,12 +35,11 @@ namespace sqlpp { #warning: Do we need this? It should be possible to use name_tag_of_t and value_type_of_t somehow template - struct field_spec_t : public name_tag_base + struct field_spec_t { - using _sqlpp_name_tag = NameType; - #warning: Maybe rename result_value in result_value_type? - using cpp_type = result_value_t; + using result_value_type = result_value_t; + using value_type = ValueType; // This is used by column_t }; template diff --git a/include/sqlpp11/core/query/result_row.h b/include/sqlpp11/core/query/result_row.h index 5c837e1a..df646666 100644 --- a/include/sqlpp11/core/query/result_row.h +++ b/include/sqlpp11/core/query/result_row.h @@ -40,9 +40,9 @@ namespace sqlpp struct result_row_impl; template - struct result_field : public member_t + struct result_field : public member_t { - using _field = member_t; + using _field = member_t; result_field() = default;