mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Add more join tests
This commit is contained in:
parent
64163be810
commit
6589c9ccbe
@ -80,7 +80,7 @@ namespace sqlpp
|
|||||||
"schema qualified tables must not depend on other tables");
|
"schema qualified tables must not depend on other tables");
|
||||||
static_assert(required_ctes_of<Table>::size::value == 0,
|
static_assert(required_ctes_of<Table>::size::value == 0,
|
||||||
"schema qualified tables must not depend on common table expressions");
|
"schema qualified tables must not depend on common table expressions");
|
||||||
static_assert(is_raw_table_t<Table>::value,
|
static_assert(is_raw_table<Table>::value,
|
||||||
"table must be a raw table, i.e. not an alias or common table expression");
|
"table must be a raw table, i.e. not an alias or common table expression");
|
||||||
|
|
||||||
return {schema, table};
|
return {schema, table};
|
||||||
|
@ -39,7 +39,7 @@ namespace sqlpp
|
|||||||
template <typename TableSpec>
|
template <typename TableSpec>
|
||||||
struct table_t : public TableSpec::_table_columns<table_t<TableSpec>>, public enable_join<table_t<TableSpec>>
|
struct table_t : public TableSpec::_table_columns<table_t<TableSpec>>, public enable_join<table_t<TableSpec>>
|
||||||
{
|
{
|
||||||
using _traits = make_traits<no_value_t, tag::is_raw_table>;
|
using _traits = make_traits<no_value_t>;
|
||||||
|
|
||||||
using _required_insert_columns = typename TableSpec::_required_insert_columns;
|
using _required_insert_columns = typename TableSpec::_required_insert_columns;
|
||||||
#warning: Need to inherit?
|
#warning: Need to inherit?
|
||||||
@ -56,11 +56,14 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename TableSpec>
|
template <typename TableSpec>
|
||||||
struct name_tag_of<table_t<TableSpec>>: public name_tag_of<TableSpec> {};
|
struct is_raw_table<table_t<TableSpec>>: public std::true_type {};
|
||||||
|
|
||||||
template <typename TableSpec>
|
template <typename TableSpec>
|
||||||
struct is_table<table_t<TableSpec>>: public std::true_type {};
|
struct is_table<table_t<TableSpec>>: public std::true_type {};
|
||||||
|
|
||||||
|
template <typename TableSpec>
|
||||||
|
struct name_tag_of<table_t<TableSpec>>: public name_tag_of<TableSpec> {};
|
||||||
|
|
||||||
template <typename TableSpec>
|
template <typename TableSpec>
|
||||||
struct provided_tables_of<table_t<TableSpec>>
|
struct provided_tables_of<table_t<TableSpec>>
|
||||||
{
|
{
|
||||||
|
@ -89,7 +89,7 @@ namespace sqlpp
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
struct check_into
|
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>::value, assert_into_arg_is_table>>;
|
||||||
};
|
};
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using check_into_t = typename check_into<T>::type;
|
using check_into_t = typename check_into<T>::type;
|
||||||
|
@ -227,7 +227,6 @@ namespace sqlpp
|
|||||||
SQLPP_VALUE_TRAIT_GENERATOR(is_cte)
|
SQLPP_VALUE_TRAIT_GENERATOR(is_cte)
|
||||||
SQLPP_VALUE_TRAIT_GENERATOR(is_noop)
|
SQLPP_VALUE_TRAIT_GENERATOR(is_noop)
|
||||||
SQLPP_VALUE_TRAIT_GENERATOR(is_missing)
|
SQLPP_VALUE_TRAIT_GENERATOR(is_missing)
|
||||||
SQLPP_VALUE_TRAIT_GENERATOR(is_raw_table)
|
|
||||||
SQLPP_VALUE_TRAIT_GENERATOR(is_pre_join)
|
SQLPP_VALUE_TRAIT_GENERATOR(is_pre_join)
|
||||||
SQLPP_VALUE_TRAIT_GENERATOR(is_join)
|
SQLPP_VALUE_TRAIT_GENERATOR(is_join)
|
||||||
SQLPP_VALUE_TRAIT_GENERATOR(is_dynamic_pre_join)
|
SQLPP_VALUE_TRAIT_GENERATOR(is_dynamic_pre_join)
|
||||||
@ -414,9 +413,14 @@ namespace sqlpp
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
using parameters_of = typename detail::parameters_of_impl<T>::type;
|
using parameters_of = typename detail::parameters_of_impl<T>::type;
|
||||||
|
|
||||||
|
// Something that can be used as a table
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct is_table : public std::false_type{};
|
struct is_table : public std::false_type{};
|
||||||
|
|
||||||
|
// Really a table, not a `table AS ...`, `JOIN` or `CTE` or `SELECT ... AS`
|
||||||
|
template <typename T>
|
||||||
|
struct is_raw_table : public std::false_type{};
|
||||||
|
|
||||||
template <typename ValueType, typename... Tags>
|
template <typename ValueType, typename... Tags>
|
||||||
struct make_traits
|
struct make_traits
|
||||||
{
|
{
|
||||||
|
@ -52,8 +52,6 @@ void test_column()
|
|||||||
|
|
||||||
static_assert(std::is_same<sqlpp::value_type_of_t<Id>, sqlpp::integral>::value, "");
|
static_assert(std::is_same<sqlpp::value_type_of_t<Id>, sqlpp::integral>::value, "");
|
||||||
|
|
||||||
foo.as(test::TabBar{}).id = 7;
|
|
||||||
|
|
||||||
// tab_foo.id AS cheese
|
// tab_foo.id AS cheese
|
||||||
// This is only useful SELECT. It therefore exposes neither name nor value directly.
|
// This is only useful SELECT. It therefore exposes neither name nor value directly.
|
||||||
// It does require its table, though.
|
// It does require its table, though.
|
||||||
@ -74,7 +72,6 @@ void test_column()
|
|||||||
static_assert(std::is_same<sqlpp::value_type_of_t<Cheese>, sqlpp::no_value_t>::value, "");
|
static_assert(std::is_same<sqlpp::value_type_of_t<Cheese>, sqlpp::no_value_t>::value, "");
|
||||||
|
|
||||||
// (tab_foo AS bar).id
|
// (tab_foo AS bar).id
|
||||||
#warning : insert must not accept table_as!
|
|
||||||
static_assert(not sqlpp::is_table<BarId>::value, "");
|
static_assert(not sqlpp::is_table<BarId>::value, "");
|
||||||
static_assert(sqlpp::has_default<BarId>::value, "");
|
static_assert(sqlpp::has_default<BarId>::value, "");
|
||||||
static_assert(sqlpp::is_group_by_column<BarId>::value, "");
|
static_assert(sqlpp::is_group_by_column<BarId>::value, "");
|
||||||
|
@ -26,34 +26,116 @@
|
|||||||
#include "Sample.h"
|
#include "Sample.h"
|
||||||
#include <sqlpp11/sqlpp11.h>
|
#include <sqlpp11/sqlpp11.h>
|
||||||
|
|
||||||
|
namespace test {
|
||||||
|
SQLPP_CREATE_NAME_TAG(cheese);
|
||||||
|
SQLPP_CREATE_NAME_TAG(cake);
|
||||||
|
}
|
||||||
|
|
||||||
void test_group_by()
|
void test_group_by()
|
||||||
{
|
{
|
||||||
auto v = sqlpp::value(17);
|
auto v = sqlpp::value(17);
|
||||||
auto foo = test::TabFoo{};
|
auto foo = test::TabFoo{};
|
||||||
auto bar = test::TabBar{};
|
auto bar = test::TabBar{};
|
||||||
|
auto cheese = foo.as(test::cheese);
|
||||||
|
auto cake = foo.as(test::cake);
|
||||||
|
|
||||||
|
using Foo = decltype(foo);
|
||||||
|
using Bar = decltype(bar);
|
||||||
|
using Cheese = decltype(cheese);
|
||||||
|
using Cake = decltype(cake);
|
||||||
|
|
||||||
// Pre-join
|
// Pre-join
|
||||||
static_assert(not sqlpp::is_table<decltype(foo.join(bar))>::value, "");
|
static_assert(not sqlpp::is_table<decltype(foo.join(bar))>::value, "");
|
||||||
|
|
||||||
// Join
|
// Join of tables
|
||||||
{
|
{
|
||||||
using J = decltype(foo.join(bar).on(foo.id == bar.id));
|
using J = decltype(foo.join(bar).on(foo.id == bar.id));
|
||||||
static_assert(sqlpp::is_table<J>::value, "");
|
static_assert(sqlpp::is_table<J>::value, "");
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_vector<sqlpp::table_t<test::TabFoo_>, sqlpp::table_t<test::TabBar_>>>::value, "");
|
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_vector<Foo, Bar>>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_static_tables_of_t<J>, sqlpp::provided_tables_of_t<J>>::value, "");
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_vector<>>::value, "");
|
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_vector<>>::value, "");
|
||||||
#warning: test the provided dynamic tables of?
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
using J = decltype(foo.cross_join(bar));
|
||||||
|
static_assert(sqlpp::is_table<J>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_vector<Foo, Bar>>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_static_tables_of_t<J>, sqlpp::provided_tables_of_t<J>>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_vector<>>::value, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
using J = decltype(foo.inner_join(bar).on(foo.id == bar.id));
|
||||||
|
static_assert(sqlpp::is_table<J>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_vector<Foo, Bar>>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_static_tables_of_t<J>, sqlpp::provided_tables_of_t<J>>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_vector<>>::value, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
using J = decltype(foo.left_outer_join(bar).on(foo.id == bar.id));
|
||||||
|
static_assert(sqlpp::is_table<J>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_vector<Foo, Bar>>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_static_tables_of_t<J>, sqlpp::provided_tables_of_t<J>>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_vector<Bar>>::value, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
using J = decltype(foo.right_outer_join(bar).on(foo.id == bar.id));
|
||||||
|
static_assert(sqlpp::is_table<J>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_vector<Foo, Bar>>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_static_tables_of_t<J>, sqlpp::provided_tables_of_t<J>>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_vector<Foo>>::value, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
using J = decltype(foo.full_outer_join(bar).on(foo.id == bar.id));
|
using J = decltype(foo.full_outer_join(bar).on(foo.id == bar.id));
|
||||||
static_assert(sqlpp::is_table<J>::value, "");
|
static_assert(sqlpp::is_table<J>::value, "");
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_vector<sqlpp::table_t<test::TabFoo_>, sqlpp::table_t<test::TabBar_>>>::value, "");
|
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_vector<Foo, Bar>>::value, "");
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_vector<sqlpp::table_t<test::TabFoo_>, sqlpp::table_t<test::TabBar_>>>::value, "");
|
std::is_same<sqlpp::provided_static_tables_of_t<J>, sqlpp::provided_tables_of_t<J>>::value, "");
|
||||||
#warning: test the provided dynamic tables of?
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_vector<Foo, Bar>>::value, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Join with rhs alias table
|
||||||
|
{
|
||||||
|
using J = decltype(foo.join(cheese).on(foo.id == cheese.id));
|
||||||
|
static_assert(sqlpp::is_table<J>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_vector<Foo, Cheese>>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_static_tables_of_t<J>, sqlpp::provided_tables_of_t<J>>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_vector<>>::value, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Join with two alias tables
|
||||||
|
{
|
||||||
|
using J = decltype(cheese.join(cake).on(cheese.id == cake.id));
|
||||||
|
static_assert(sqlpp::is_table<J>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_vector<Cheese, Cake>>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_static_tables_of_t<J>, sqlpp::provided_tables_of_t<J>>::value, "");
|
||||||
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_vector<>>::value, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join with dynamic table
|
// Join with dynamic table
|
||||||
@ -61,16 +143,14 @@ void test_group_by()
|
|||||||
using J = decltype(foo.join(dynamic(true, bar)).on(foo.id == bar.id));
|
using J = decltype(foo.join(dynamic(true, bar)).on(foo.id == bar.id));
|
||||||
static_assert(sqlpp::is_table<J>::value, "");
|
static_assert(sqlpp::is_table<J>::value, "");
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_vector<test::TabFoo, test::TabBar>>::value, "");
|
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_vector<Foo, Bar>>::value, "");
|
||||||
#warning: OUTER is the wrong term. In a left-outer join, the *right* table is the one with optional rows.
|
static_assert(
|
||||||
|
std::is_same<sqlpp::provided_static_tables_of_t<J>, sqlpp::detail::type_vector<Foo>>::value, "");
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_vector<>>::value, "");
|
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_vector<>>::value, "");
|
||||||
#warning: test the provided dynamic tables of?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#warning: Need to add tests all join types!
|
|
||||||
#warning: Need to add tests with table_as
|
|
||||||
#warning: Need to add tests with verbatim tables
|
#warning: Need to add tests with verbatim tables
|
||||||
#warning: Need to add tests with 3 tables
|
#warning: Need to add tests with 3 tables
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ void test_table()
|
|||||||
auto bar = test::TabBar{};
|
auto bar = test::TabBar{};
|
||||||
|
|
||||||
static_assert(sqlpp::is_table<test::TabFoo>::value, "");
|
static_assert(sqlpp::is_table<test::TabFoo>::value, "");
|
||||||
|
static_assert(sqlpp::is_raw_table<test::TabFoo>::value, "");
|
||||||
static_assert(std::is_same<sqlpp::name_tag_of_t<test::TabFoo>, test::TabFoo_::_sqlpp_name_tag>::value, "");
|
static_assert(std::is_same<sqlpp::name_tag_of_t<test::TabFoo>, test::TabFoo_::_sqlpp_name_tag>::value, "");
|
||||||
static_assert(std::is_same<sqlpp::provided_tables_of_t<test::TabFoo>, sqlpp::detail::type_vector<test::TabFoo>>::value, "");
|
static_assert(std::is_same<sqlpp::provided_tables_of_t<test::TabFoo>, sqlpp::detail::type_vector<test::TabFoo>>::value, "");
|
||||||
static_assert(std::is_same<sqlpp::provided_static_tables_of_t<test::TabFoo>, sqlpp::provided_tables_of_t<test::TabFoo>>::value, "");
|
static_assert(std::is_same<sqlpp::provided_static_tables_of_t<test::TabFoo>, sqlpp::provided_tables_of_t<test::TabFoo>>::value, "");
|
||||||
|
@ -36,6 +36,7 @@ void test_table()
|
|||||||
|
|
||||||
static_assert(std::is_same<FooBar, sqlpp::table_as_t<test::TabFoo_, test::TabBar_::_sqlpp_name_tag>>::value, "");
|
static_assert(std::is_same<FooBar, sqlpp::table_as_t<test::TabFoo_, test::TabBar_::_sqlpp_name_tag>>::value, "");
|
||||||
static_assert(sqlpp::is_table<FooBar>::value, "");
|
static_assert(sqlpp::is_table<FooBar>::value, "");
|
||||||
|
static_assert(not sqlpp::is_raw_table<FooBar>::value, "");
|
||||||
static_assert(std::is_same<sqlpp::name_tag_of_t<FooBar>, test::TabBar_::_sqlpp_name_tag>::value, "");
|
static_assert(std::is_same<sqlpp::name_tag_of_t<FooBar>, test::TabBar_::_sqlpp_name_tag>::value, "");
|
||||||
static_assert(std::is_same<sqlpp::provided_tables_of_t<FooBar>, sqlpp::detail::type_vector<FooBar>>::value, "");
|
static_assert(std::is_same<sqlpp::provided_tables_of_t<FooBar>, sqlpp::detail::type_vector<FooBar>>::value, "");
|
||||||
static_assert(std::is_same<sqlpp::provided_static_tables_of_t<FooBar>, sqlpp::provided_tables_of_t<FooBar>>::value, "");
|
static_assert(std::is_same<sqlpp::provided_static_tables_of_t<FooBar>, sqlpp::provided_tables_of_t<FooBar>>::value, "");
|
||||||
|
Loading…
Reference in New Issue
Block a user