/* * Copyright (c) 2013, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, this * list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef SQLPP_TABLE_BASE_H #define SQLPP_TABLE_BASE_H #include #include #include #include #include #include #include namespace sqlpp { template struct table_base_t: public ColumnSpec::_name_t::template _member_t>... { using _table_set = detail::set; // Hint need a set here to be similar to a join (which always represents more than one table) using _all_columns = typename detail::make_set...>::type; static_assert(_all_columns::size::value, "at least one column required per table"); using _required_insert_columns = typename detail::make_set_if...>::type; using _all_of_t = std::tuple...>; using _is_table = std::true_type; template join_t::type> join(T&& t) { return { *static_cast(this), std::forward(t) }; } template struct alias_t: public ColumnSpec::_name_t::template _member_t>... { using _is_table = std::true_type; using _table_set = detail::set; struct _value_type: Table::_value_type { using _is_expression = std::false_type; using _is_named_expression = copy_type_trait; using _is_alias = std::true_type; }; using _name_t = typename AliasProvider::_name_t; using _all_of_t = std::tuple...>; alias_t(const Table& table): _table(table) {} alias_t(Table&& table): _table(std::move(table)) {} template void serialize(std::ostream& os, Db& db) const { os << "("; _table.serialize(os, db); os << ") AS " << _name_t::_get_name(); } Table _table; }; template alias_t as(const AliasProvider&) const { return {*static_cast(this)}; } template void serialize(std::ostream& os, Db& db) const { static_cast(this)->serialize_impl(os, db); } }; template auto all_of(Table&& t) -> typename std::decay
::type::_all_of_t { return {}; } } #endif