Skip to content

Commit 35a17ef

Browse files
committed
Very rough draft for supporting views (#453)
1 parent 159f4be commit 35a17ef

File tree

6 files changed

+47
-4
lines changed

6 files changed

+47
-4
lines changed

include/sqlpp11/into.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,14 @@ namespace sqlpp
114114
SQLPP_PORTABLE_STATIC_ASSERT(assert_into_t, "into() required");
115115

116116
SQLPP_PORTABLE_STATIC_ASSERT(assert_into_arg_is_table, "argument for into() must be a table");
117+
SQLPP_PORTABLE_STATIC_ASSERT(assert_into_arg_is_not_a_view, "argument for into() must not be a view");
117118
template <typename T>
118119
struct check_into
119120
{
120-
using type = static_combined_check_t<static_check_t<is_raw_table_t<T>::value, assert_into_arg_is_table>>;
121+
using type = static_combined_check_t<
122+
static_check_t<is_raw_table_t<T>::value, assert_into_arg_is_table>,
123+
static_check_t<not is_view_t<T>::value, assert_into_arg_is_not_a_view>
124+
>;
121125
};
122126
template <typename T>
123127
using check_into_t = typename check_into<wrap_operand_t<T>>::type;

include/sqlpp11/single_table.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ namespace sqlpp
6060
using _nodes = detail::type_vector<Table>;
6161

6262
static_assert(is_table_t<Table>::value, "argument has to be a table");
63+
static_assert(not is_view_t<Table>::value, "argument must not be a view");
6364
static_assert(required_tables_of<Table>::size::value == 0, "table depends on another table");
6465

6566
using _data_t = single_table_data_t<Database, Table>;
@@ -113,11 +114,15 @@ namespace sqlpp
113114
};
114115
};
115116

116-
SQLPP_PORTABLE_STATIC_ASSERT(assert_update_table_arg_is_table_t, "argument for update() must be a table");
117+
SQLPP_PORTABLE_STATIC_ASSERT(assert_update_table_arg_is_table, "argument for update() must be a table");
118+
SQLPP_PORTABLE_STATIC_ASSERT(assert_update_table_arg_is_no_a_view, "argument for update() must not be a view");
117119
template <typename Table>
118120
struct check_update_table
119121
{
120-
using type = static_combined_check_t<static_check_t<is_table_t<Table>::value, assert_update_table_arg_is_table_t>>;
122+
using type = static_combined_check_t<
123+
static_check_t<is_table_t<Table>::value, assert_update_table_arg_is_table>,
124+
static_check_t<not is_view_t<Table>::value, assert_update_table_arg_is_no_a_view>
125+
>;
121126
};
122127
template <typename Table>
123128
using check_update_table_t = typename check_update_table<Table>::type;

include/sqlpp11/table.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace sqlpp
4343
template <typename Table, typename... ColumnSpec>
4444
struct table_t : public ColumnSpec::_alias_t::template _member_t<column_t<Table, ColumnSpec>>...
4545
{
46-
using _traits = make_traits<no_value_t, tag::is_raw_table, tag::is_table>;
46+
using _traits = make_traits<no_value_t, tag::is_raw_table, tag::is_table, tag_if<tag::is_view, is_view_t<Table>::value>>;
4747

4848
using _nodes = detail::type_vector<>;
4949
using _provided_tables = detail::type_set<Table>;

include/sqlpp11/type_traits.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ namespace sqlpp
182182
SQLPP_VALUE_TRAIT_GENERATOR(is_noop)
183183
SQLPP_VALUE_TRAIT_GENERATOR(is_missing)
184184
SQLPP_VALUE_TRAIT_GENERATOR(is_return_value)
185+
SQLPP_VALUE_TRAIT_GENERATOR(is_view)
185186
SQLPP_VALUE_TRAIT_GENERATOR(is_table)
186187
SQLPP_VALUE_TRAIT_GENERATOR(is_raw_table)
187188
SQLPP_VALUE_TRAIT_GENERATOR(is_pre_join)

tests/core/usage/Sample.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,32 @@ namespace test
142142
};
143143
};
144144
};
145+
struct ViewFoo_
146+
{
147+
struct _alias_t
148+
{
149+
static constexpr const char _literal[] = "view_foo";
150+
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
151+
template <typename T>
152+
struct _member_t
153+
{
154+
T tabFoo;
155+
T& operator()()
156+
{
157+
return tabFoo;
158+
}
159+
const T& operator()() const
160+
{
161+
return tabFoo;
162+
}
163+
};
164+
};
165+
using _traits = sqlpp::make_traits<sqlpp::no_value_t, sqlpp::tag::is_view>;
166+
};
167+
struct ViewFoo : sqlpp::table_t<ViewFoo_, TabFoo_::Delta, TabFoo_::Epsilon, TabFoo_::Omega, TabFoo_::Psi, TabFoo_::Book>
168+
{
169+
};
170+
145171
namespace TabBar_
146172
{
147173
struct Alpha

tests/core/usage/Select.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ int Select(int, char*[])
6868

6969
const auto f = test::TabFoo{};
7070
const auto t = test::TabBar{};
71+
const auto vf = test::ViewFoo{};
7172
const auto tab_a = f.as(sqlpp::alias::a);
7273

7374
getColumn(db, t.alpha);
@@ -108,6 +109,12 @@ int Select(int, char*[])
108109
std::cout << row.alpha << std::endl;
109110
}
110111

112+
for (const auto& row :
113+
db(select(all_of(vf)).from(vf).where(vf.book == "sql")))
114+
{
115+
std::cout << row.book << std::endl;
116+
}
117+
111118
for (const auto& row : db(select(all_of(t), all_of(f))
112119
.from(t.join(f).on(t.alpha > f.omega).join(tab_a).on(t.alpha == tab_a.omega))
113120
.unconditionally()))

0 commit comments

Comments
 (0)