mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Added table() method for columns.
This commit is contained in:
parent
028af83fe7
commit
6591d38bab
@ -70,6 +70,13 @@ namespace sqlpp
|
|||||||
column_t& operator=(column_t&&) = default;
|
column_t& operator=(column_t&&) = default;
|
||||||
~column_t() = default;
|
~column_t() = default;
|
||||||
|
|
||||||
|
template<typename T = _table>
|
||||||
|
auto table() const -> _table
|
||||||
|
{
|
||||||
|
static_assert(is_table_t<T>::value, "cannot call get_table for columns of a sub-selects or cte");
|
||||||
|
return _table{};
|
||||||
|
}
|
||||||
|
|
||||||
template<typename alias_provider>
|
template<typename alias_provider>
|
||||||
expression_alias_t<column_t, alias_provider> as(const alias_provider&) const
|
expression_alias_t<column_t, alias_provider> as(const alias_provider&) const
|
||||||
{
|
{
|
||||||
|
@ -36,11 +36,23 @@
|
|||||||
MockDb db = {};
|
MockDb db = {};
|
||||||
MockDb::_serializer_context_t printer;
|
MockDb::_serializer_context_t printer;
|
||||||
|
|
||||||
|
template<typename Column>
|
||||||
|
int64_t getColumn(const Column& column)
|
||||||
|
{
|
||||||
|
auto result = db(select(column.as(sqlpp::a)).from(column.table()).where(true));
|
||||||
|
if (not result.empty())
|
||||||
|
return result.front().a;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
test::TabFoo f;
|
test::TabFoo f;
|
||||||
test::TabBar t;
|
test::TabBar t;
|
||||||
|
|
||||||
|
getColumn(t.alpha);
|
||||||
|
|
||||||
for (const auto& row : db(select(all_of(t)).from(t).where(true)))
|
for (const auto& row : db(select(all_of(t)).from(t).where(true)))
|
||||||
{
|
{
|
||||||
int64_t a = row.alpha;
|
int64_t a = row.alpha;
|
||||||
|
Loading…
Reference in New Issue
Block a user