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

Rename table_alias to table_as

This commit is contained in:
Roland Bock 2024-09-01 10:45:22 +02:00
parent 33a40b6351
commit 63c95e221c
6 changed files with 26 additions and 30 deletions

View File

@ -30,7 +30,7 @@
#include <sqlpp11/core/to_sql_string.h>
#include <sqlpp11/core/type_traits.h>
#include <sqlpp11/core/basic/schema.h>
#include <sqlpp11/core/basic/table_alias.h>
#include <sqlpp11/core/basic/table_as.h>
#include <sqlpp11/core/detail/type_set.h>
#include <utility>
@ -51,7 +51,7 @@ namespace sqlpp
}
template <typename AliasProvider>
typename Table::template _foreign_table_alias_t<AliasProvider, schema_qualified_table_t> as(
typename Table::template _foreign_table_as_t<AliasProvider, schema_qualified_table_t> as(
const AliasProvider& /*unused*/) const
{
return {*this};

View File

@ -28,7 +28,7 @@
#include <sqlpp11/core/basic/enable_join.h>
#include <sqlpp11/core/type_traits.h>
#include <sqlpp11/core/basic/table_alias.h>
#include <sqlpp11/core/basic/table_as.h>
#include <sqlpp11/core/basic/all_of.h>
#include <sqlpp11/core/basic/column.h>
#include <sqlpp11/core/detail/type_vector.h>
@ -45,9 +45,9 @@ namespace sqlpp
#warning: Need to inherit?
//using _column_tuple_t = std::tuple<column_t<Table, ColumnSpec>...>;
template <typename AliasProvider, typename T>
using _foreign_table_alias_t = table_alias_t<AliasProvider, T>;
using _foreign_table_as_t = table_as_t<AliasProvider, T>;
template <typename AliasProvider>
using _sqlpp_name_tag = table_alias_t<AliasProvider, TableSpec>;
using _sqlpp_name_tag = table_as_t<AliasProvider, TableSpec>;
template <typename AliasProvider>
_sqlpp_name_tag<AliasProvider> as(const AliasProvider& /*unused*/) const

View File

@ -36,8 +36,8 @@
namespace sqlpp
{
template <typename AliasProvider, typename TableSpec>
struct table_alias_t : public TableSpec::_table_columns<table_alias_t<AliasProvider, TableSpec>>,
public enable_join<table_alias_t<AliasProvider, TableSpec>>
struct table_as_t : public TableSpec::_table_columns<table_as_t<AliasProvider, TableSpec>>,
public enable_join<table_as_t<AliasProvider, TableSpec>>
{
using _nodes = detail::type_vector<>;
using _required_ctes = required_ctes_of<TableSpec>;
@ -50,29 +50,29 @@ namespace sqlpp
};
template<typename AliasProvider, typename TableSpec>
struct is_table<table_alias_t<AliasProvider, TableSpec>> : public std::true_type{};
struct is_table<table_as_t<AliasProvider, TableSpec>> : public std::true_type{};
template<typename AliasProvider, typename TableSpec>
struct name_tag_of<table_alias_t<AliasProvider, TableSpec>> : public name_tag_of<AliasProvider>{};
struct name_tag_of<table_as_t<AliasProvider, TableSpec>> : public name_tag_of<AliasProvider>{};
template <typename AliasProvider, typename TableSpec>
struct provided_tables_of<table_alias_t<AliasProvider, TableSpec>>
struct provided_tables_of<table_as_t<AliasProvider, TableSpec>>
{
using type = sqlpp::detail::type_vector<table_alias_t<AliasProvider, TableSpec>>;
using type = sqlpp::detail::type_vector<table_as_t<AliasProvider, TableSpec>>;
};
template <typename AliasProvider, typename TableSpec>
struct provided_static_tables_of<table_alias_t<AliasProvider, TableSpec>> : public provided_tables_of<table_alias_t<AliasProvider, TableSpec>>
struct provided_static_tables_of<table_as_t<AliasProvider, TableSpec>> : public provided_tables_of<table_as_t<AliasProvider, TableSpec>>
{
};
template <typename AliasProvider, typename TableSpec>
struct provided_optional_tables_of<table_alias_t<AliasProvider, TableSpec>> : public provided_tables_of<table_alias_t<AliasProvider, TableSpec>>
struct provided_optional_tables_of<table_as_t<AliasProvider, TableSpec>> : public provided_tables_of<table_as_t<AliasProvider, TableSpec>>
{
};
template <typename Context, typename AliasProvider, typename TableSpec>
auto to_sql_string(Context& context, const table_alias_t<AliasProvider, TableSpec>&) -> std::string
auto to_sql_string(Context& context, const table_as_t<AliasProvider, TableSpec>&) -> std::string
{
return name_to_sql_string(context, name_tag_of_t<TableSpec>::name) + " AS " +
name_to_sql_string(context, name_tag_of_t<AliasProvider>::name);

View File

@ -34,28 +34,28 @@
namespace sqlpp
{
template <typename AliasProvider>
struct verbatim_table_alias_t : public enable_join<verbatim_table_alias_t<AliasProvider>>
struct verbatim_table_as_t : public enable_join<verbatim_table_as_t<AliasProvider>>
{
verbatim_table_alias_t(std::string representation) : _representation(std::move(representation))
verbatim_table_as_t(std::string representation) : _representation(std::move(representation))
{
}
verbatim_table_alias_t(const verbatim_table_alias_t& rhs) = default;
verbatim_table_alias_t(verbatim_table_alias_t&& rhs) = default;
verbatim_table_alias_t& operator=(const verbatim_table_alias_t& rhs) = default;
verbatim_table_alias_t& operator=(verbatim_table_alias_t&& rhs) = default;
~verbatim_table_alias_t() = default;
verbatim_table_as_t(const verbatim_table_as_t& rhs) = default;
verbatim_table_as_t(verbatim_table_as_t&& rhs) = default;
verbatim_table_as_t& operator=(const verbatim_table_as_t& rhs) = default;
verbatim_table_as_t& operator=(verbatim_table_as_t&& rhs) = default;
~verbatim_table_as_t() = default;
std::string _representation;
};
template <typename AliasProvider>
struct is_table<verbatim_table_alias_t<AliasProvider>> : std::true_type
struct is_table<verbatim_table_as_t<AliasProvider>> : std::true_type
{
};
template <typename Context, typename AliasProvider>
auto to_sql_string(Context& context, const verbatim_table_alias_t<AliasProvider>& t) -> std::string
auto to_sql_string(Context& context, const verbatim_table_as_t<AliasProvider>& t) -> std::string
{
return t._representation + " AS " + name_to_sql_string(context, name_tag_of_t<AliasProvider>::name);
}
@ -73,7 +73,7 @@ namespace sqlpp
~verbatim_table_t() = default;
template <typename AliasProvider>
verbatim_table_alias_t<AliasProvider> as(const AliasProvider& /*unused*/) const
verbatim_table_as_t<AliasProvider> as(const AliasProvider& /*unused*/) const
{
return {_representation};
}

View File

@ -56,15 +56,10 @@ int From(int, char* [])
" FROM tab_foo LEFT OUTER JOIN tab_bar ON tab_foo.double_n > tab_bar.id");
SQLPP_COMPARE(from(foo.right_outer_join(bar).on(foo.doubleN > bar.id)),
" FROM tab_foo RIGHT OUTER JOIN tab_bar ON tab_foo.double_n > tab_bar.id");
sqlpp::provided_tables_of_t<decltype(aFoo.cross_join(bFoo))>::hansi;
sqlpp::required_tables_of_t<decltype(aFoo.doubleN > bFoo.doubleN)>::hansi;
#warning: reactivate
/*
SQLPP_COMPARE(from(aFoo.join(bFoo).on(aFoo.doubleN > bFoo.doubleN)),
" FROM tab_foo AS a INNER JOIN tab_foo AS b ON a.double_n > b.double_n");
SQLPP_COMPARE(from(aFoo.join(bFoo).on(aFoo.doubleN > bFoo.doubleN).join(cFoo).on(bFoo.doubleN > cFoo.doubleN)),
" FROM tab_foo AS a INNER JOIN tab_foo AS b ON a.double_n > b.double_n INNER JOIN tab_foo AS c ON b.double_n > c.double_n");
SQLPP_COMPARE(from(foo.join(bar).unconditionally()), " FROM tab_foo INNER JOIN tab_bar");
// Static joins involving verbatim tables
SQLPP_COMPARE(from(aFoo.join(sqlpp::verbatim_table("unknown_table"))
@ -81,6 +76,6 @@ int From(int, char* [])
" FROM unknown_table AS a INNER JOIN another_table ON a.column_x > another_table.x");
#warning add tests for dynamic joins
*/
return 0;
}

View File

@ -66,6 +66,7 @@ int main(int, char* [])
#warning: Need to add tests with 3 tables
#warning: Need to add tests with table aliases
#warning: Need to add tests with verbatim tables
#warning: Need to add tests with sub selects
#warning: Need to add tests with CTEs
return 0;