0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Very rough draft for supporting views (#453)

This commit is contained in:
Roland Bock 2022-08-22 19:58:57 +02:00
parent 159f4be66f
commit 35a17efc0a
6 changed files with 47 additions and 4 deletions

View File

@ -114,10 +114,14 @@ namespace sqlpp
SQLPP_PORTABLE_STATIC_ASSERT(assert_into_t, "into() required");
SQLPP_PORTABLE_STATIC_ASSERT(assert_into_arg_is_table, "argument for into() must be a table");
SQLPP_PORTABLE_STATIC_ASSERT(assert_into_arg_is_not_a_view, "argument for into() must not be a view");
template <typename T>
struct check_into
{
using type = static_combined_check_t<static_check_t<is_raw_table_t<T>::value, assert_into_arg_is_table>>;
using type = static_combined_check_t<
static_check_t<is_raw_table_t<T>::value, assert_into_arg_is_table>,
static_check_t<not is_view_t<T>::value, assert_into_arg_is_not_a_view>
>;
};
template <typename T>
using check_into_t = typename check_into<wrap_operand_t<T>>::type;

View File

@ -60,6 +60,7 @@ namespace sqlpp
using _nodes = detail::type_vector<Table>;
static_assert(is_table_t<Table>::value, "argument has to be a table");
static_assert(not is_view_t<Table>::value, "argument must not be a view");
static_assert(required_tables_of<Table>::size::value == 0, "table depends on another table");
using _data_t = single_table_data_t<Database, Table>;
@ -113,11 +114,15 @@ namespace sqlpp
};
};
SQLPP_PORTABLE_STATIC_ASSERT(assert_update_table_arg_is_table_t, "argument for update() must be a table");
SQLPP_PORTABLE_STATIC_ASSERT(assert_update_table_arg_is_table, "argument for update() must be a table");
SQLPP_PORTABLE_STATIC_ASSERT(assert_update_table_arg_is_no_a_view, "argument for update() must not be a view");
template <typename Table>
struct check_update_table
{
using type = static_combined_check_t<static_check_t<is_table_t<Table>::value, assert_update_table_arg_is_table_t>>;
using type = static_combined_check_t<
static_check_t<is_table_t<Table>::value, assert_update_table_arg_is_table>,
static_check_t<not is_view_t<Table>::value, assert_update_table_arg_is_no_a_view>
>;
};
template <typename Table>
using check_update_table_t = typename check_update_table<Table>::type;

View File

@ -43,7 +43,7 @@ namespace sqlpp
template <typename Table, typename... ColumnSpec>
struct table_t : public ColumnSpec::_alias_t::template _member_t<column_t<Table, ColumnSpec>>...
{
using _traits = make_traits<no_value_t, tag::is_raw_table, tag::is_table>;
using _traits = make_traits<no_value_t, tag::is_raw_table, tag::is_table, tag_if<tag::is_view, is_view_t<Table>::value>>;
using _nodes = detail::type_vector<>;
using _provided_tables = detail::type_set<Table>;

View File

@ -182,6 +182,7 @@ namespace sqlpp
SQLPP_VALUE_TRAIT_GENERATOR(is_noop)
SQLPP_VALUE_TRAIT_GENERATOR(is_missing)
SQLPP_VALUE_TRAIT_GENERATOR(is_return_value)
SQLPP_VALUE_TRAIT_GENERATOR(is_view)
SQLPP_VALUE_TRAIT_GENERATOR(is_table)
SQLPP_VALUE_TRAIT_GENERATOR(is_raw_table)
SQLPP_VALUE_TRAIT_GENERATOR(is_pre_join)

View File

@ -142,6 +142,32 @@ namespace test
};
};
};
struct ViewFoo_
{
struct _alias_t
{
static constexpr const char _literal[] = "view_foo";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T tabFoo;
T& operator()()
{
return tabFoo;
}
const T& operator()() const
{
return tabFoo;
}
};
};
using _traits = sqlpp::make_traits<sqlpp::no_value_t, sqlpp::tag::is_view>;
};
struct ViewFoo : sqlpp::table_t<ViewFoo_, TabFoo_::Delta, TabFoo_::Epsilon, TabFoo_::Omega, TabFoo_::Psi, TabFoo_::Book>
{
};
namespace TabBar_
{
struct Alpha

View File

@ -68,6 +68,7 @@ int Select(int, char*[])
const auto f = test::TabFoo{};
const auto t = test::TabBar{};
const auto vf = test::ViewFoo{};
const auto tab_a = f.as(sqlpp::alias::a);
getColumn(db, t.alpha);
@ -108,6 +109,12 @@ int Select(int, char*[])
std::cout << row.alpha << std::endl;
}
for (const auto& row :
db(select(all_of(vf)).from(vf).where(vf.book == "sql")))
{
std::cout << row.book << std::endl;
}
for (const auto& row : db(select(all_of(t), all_of(f))
.from(t.join(f).on(t.alpha > f.omega).join(tab_a).on(t.alpha == tab_a.omega))
.unconditionally()))