mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 12:51:13 +08:00
A bit of cleanup
This commit is contained in:
parent
8caea01d0a
commit
c0ad5e0696
@ -58,7 +58,13 @@ namespace sqlpp
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Lhs, typename JoinType, typename Rhs, typename Condition>
|
template <typename Lhs, typename JoinType, typename Rhs, typename Condition>
|
||||||
struct provided_outer_tables_of<join_t<Lhs, JoinType, Rhs, Condition>>
|
struct provided_tables_of<join_t<Lhs, JoinType, dynamic_t<Rhs>, Condition>>
|
||||||
|
{
|
||||||
|
using type = detail::make_joined_set_t<provided_tables_of_t<Lhs>, detail::type_set<dynamic_t<Rhs>>>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Lhs, typename JoinType, typename Rhs, typename Condition>
|
||||||
|
struct provided_optional_tables_of<join_t<Lhs, JoinType, Rhs, Condition>>
|
||||||
{
|
{
|
||||||
using type = typename std::conditional<
|
using type = typename std::conditional<
|
||||||
std::is_same<JoinType, left_outer_join_t>::value,
|
std::is_same<JoinType, left_outer_join_t>::value,
|
||||||
|
@ -63,7 +63,6 @@ namespace sqlpp
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
using size = std::integral_constant<size_t, sizeof...(Elements)>;
|
using size = std::integral_constant<size_t, sizeof...(Elements)>;
|
||||||
using _is_type_set = std::true_type;
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static constexpr bool count()
|
static constexpr bool count()
|
||||||
|
@ -79,7 +79,7 @@ namespace sqlpp
|
|||||||
using _all_provided_ctes = detail::make_joined_set_t<provided_ctes_of<Policies>...>;
|
using _all_provided_ctes = detail::make_joined_set_t<provided_ctes_of<Policies>...>;
|
||||||
using _all_required_tables = detail::make_joined_set_t<required_tables_of_t<Policies>...>;
|
using _all_required_tables = detail::make_joined_set_t<required_tables_of_t<Policies>...>;
|
||||||
using _all_provided_tables = detail::make_joined_set_t<provided_tables_of_t<Policies>...>;
|
using _all_provided_tables = detail::make_joined_set_t<provided_tables_of_t<Policies>...>;
|
||||||
using _all_provided_outer_tables = detail::make_joined_set_t<provided_outer_tables_of_t<Policies>...>;
|
using _all_provided_outer_tables = detail::make_joined_set_t<provided_optional_tables_of_t<Policies>...>;
|
||||||
using _all_provided_aggregates = detail::make_joined_set_t<provided_aggregates_of<Policies>...>;
|
using _all_provided_aggregates = detail::make_joined_set_t<provided_aggregates_of<Policies>...>;
|
||||||
|
|
||||||
template <typename Expression>
|
template <typename Expression>
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
#include <sqlpp11/core/type_traits/nodes_of.h>
|
#include <sqlpp11/core/type_traits/nodes_of.h>
|
||||||
#include <sqlpp11/core/type_traits/optional.h>
|
#include <sqlpp11/core/type_traits/optional.h>
|
||||||
#include <sqlpp11/core/type_traits/value_type.h>
|
#include <sqlpp11/core/type_traits/value_type.h>
|
||||||
|
#include <sqlpp11/core/type_traits/tables_of.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
@ -305,67 +306,6 @@ namespace sqlpp
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
using rhs_t = typename rhs<T>::type;
|
using rhs_t = typename rhs<T>::type;
|
||||||
|
|
||||||
// Anything that directly requires a table (e.g. a column) has to specialize required_tables_of.
|
|
||||||
template<typename T>
|
|
||||||
struct required_tables_of
|
|
||||||
{
|
|
||||||
using type = typename required_tables_of<nodes_of_t<T>>::type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename... T>
|
|
||||||
struct required_tables_of<detail::type_vector<T...>>
|
|
||||||
{
|
|
||||||
using type = detail::make_joined_set_t<typename required_tables_of<T>::type...>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
using required_tables_of_t = typename required_tables_of<T>::type;
|
|
||||||
|
|
||||||
static_assert(required_tables_of_t<int>::size::value == 0, "");
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct provided_tables_of
|
|
||||||
{
|
|
||||||
using type = typename provided_tables_of<nodes_of_t<T>>::type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename... T>
|
|
||||||
struct provided_tables_of<detail::type_vector<T...>>
|
|
||||||
{
|
|
||||||
using type = detail::make_joined_set_t<typename provided_tables_of<T>::type...>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
using provided_tables_of_t = typename provided_tables_of<T>::type;
|
|
||||||
|
|
||||||
static_assert(provided_tables_of_t<int>::size::value == 0, "");
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct provided_outer_tables_of
|
|
||||||
{
|
|
||||||
using type = typename provided_outer_tables_of<nodes_of_t<T>>::type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename... T>
|
|
||||||
struct provided_outer_tables_of<detail::type_vector<T...>>
|
|
||||||
{
|
|
||||||
using type = detail::make_joined_set_t<typename provided_outer_tables_of<T>::type...>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
using provided_outer_tables_of_t = typename provided_outer_tables_of<T>::type;
|
|
||||||
|
|
||||||
static_assert(provided_outer_tables_of_t<int>::size::value == 0, "");
|
|
||||||
|
|
||||||
template <typename ValueType, typename T>
|
|
||||||
struct is_valid_operand
|
|
||||||
{
|
|
||||||
static constexpr bool value =
|
|
||||||
is_expression_t<T>::value // expressions are OK
|
|
||||||
and ValueType::template _is_valid_operand<T>::value // the correct value type is required, of course
|
|
||||||
;
|
|
||||||
};
|
|
||||||
|
|
||||||
#warning: This should go away
|
#warning: This should go away
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
95
include/sqlpp11/core/type_traits/tables_of.h
Normal file
95
include/sqlpp11/core/type_traits/tables_of.h
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sqlpp11/core/type_traits/nodes_of.h>
|
||||||
|
#include <sqlpp11/core/detail/type_vector.h>
|
||||||
|
#include <sqlpp11/core/detail/type_set.h>
|
||||||
|
|
||||||
|
namespace sqlpp
|
||||||
|
{
|
||||||
|
// required_tables_of determines the type_set of tables referenced by columns within within T.
|
||||||
|
// column_t or other structs that might reference a table shall specialize this template to indicate their table
|
||||||
|
// requirement.
|
||||||
|
// Dynamic parts of a query shall wrap their required tables in dynamic_t.
|
||||||
|
template<typename T>
|
||||||
|
struct required_tables_of
|
||||||
|
{
|
||||||
|
using type = typename required_tables_of<nodes_of_t<T>>::type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename... T>
|
||||||
|
struct required_tables_of<detail::type_vector<T...>>
|
||||||
|
{
|
||||||
|
using type = detail::make_joined_set_t<typename required_tables_of<T>::type...>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
using required_tables_of_t = typename required_tables_of<T>::type;
|
||||||
|
|
||||||
|
#warning: need type tests...
|
||||||
|
//static_assert(required_tables_of_t<int>::size::value == 0, "");
|
||||||
|
|
||||||
|
// provided_tables_of determines the type_set of tables provided by the query clause, e.g. by FROM.
|
||||||
|
// Provided tables can be wrapped in dynamic_t if they are provided through a dynamic join.
|
||||||
|
// table_t, cte_ref_t, or other structs that might provide a table in a query need to specialize this template.
|
||||||
|
template <typename T>
|
||||||
|
struct provided_tables_of
|
||||||
|
{
|
||||||
|
using type = typename provided_tables_of<nodes_of_t<T>>::type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename... T>
|
||||||
|
struct provided_tables_of<detail::type_vector<T...>>
|
||||||
|
{
|
||||||
|
using type = detail::make_joined_set_t<typename provided_tables_of<T>::type...>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using provided_tables_of_t = typename provided_tables_of<T>::type;
|
||||||
|
|
||||||
|
static_assert(provided_tables_of_t<int>::size::value == 0, "");
|
||||||
|
|
||||||
|
// provided_optional_tables_of is similar to provided_tables_of but only references the tables that have optional
|
||||||
|
// rows in outer joins (e.g. the right hand side table in a LEFT OUTER JOIN).
|
||||||
|
template <typename T>
|
||||||
|
struct provided_optional_tables_of
|
||||||
|
{
|
||||||
|
using type = typename provided_optional_tables_of<nodes_of_t<T>>::type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename... T>
|
||||||
|
struct provided_optional_tables_of<detail::type_vector<T...>>
|
||||||
|
{
|
||||||
|
using type = detail::make_joined_set_t<typename provided_optional_tables_of<T>::type...>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using provided_optional_tables_of_t = typename provided_optional_tables_of<T>::type;
|
||||||
|
|
||||||
|
} // namespace sqlpp
|
||||||
|
|
@ -1,53 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2013-2015, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sqlpp11/core/type_traits.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
|
||||||
{
|
|
||||||
template <typename ValueType, typename T, typename Enable = void>
|
|
||||||
struct is_valid_assignment_operand
|
|
||||||
{
|
|
||||||
static constexpr bool value =
|
|
||||||
is_expression_t<T>::value // expressions are OK
|
|
||||||
and ValueType::template _is_valid_operand<T>::value // the correct value type is required, of course
|
|
||||||
;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename ValueType, typename T>
|
|
||||||
struct is_valid_assignment_operand<
|
|
||||||
ValueType,
|
|
||||||
T,
|
|
||||||
typename std::enable_if<std::is_class<typename ValueType::template _is_valid_assignment_operand<T>>::value>::type>
|
|
||||||
{
|
|
||||||
static constexpr bool value =
|
|
||||||
is_expression_t<T>::value // expressions are OK
|
|
||||||
and ValueType::template _is_valid_assignment_operand<T>::value // the correct value type is required, of course
|
|
||||||
;
|
|
||||||
};
|
|
||||||
} // namespace sqlpp
|
|
@ -42,7 +42,7 @@ void test_group_by()
|
|||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_set<test::TabFoo, test::TabBar>>::value, "");
|
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_set<test::TabFoo, test::TabBar>>::value, "");
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_outer_tables_of_t<J>, sqlpp::detail::type_set<>>::value, "");
|
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_set<>>::value, "");
|
||||||
#warning: test the provided dynamic tables of?
|
#warning: test the provided dynamic tables of?
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ void test_group_by()
|
|||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_set<test::TabFoo, test::TabBar>>::value, "");
|
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_set<test::TabFoo, test::TabBar>>::value, "");
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_outer_tables_of_t<J>, sqlpp::detail::type_set<test::TabFoo, test::TabBar>>::value, "");
|
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_set<test::TabFoo, test::TabBar>>::value, "");
|
||||||
#warning: test the provided dynamic tables of?
|
#warning: test the provided dynamic tables of?
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ void test_group_by()
|
|||||||
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_set<test::TabFoo, test::TabBar>>::value, "");
|
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_set<test::TabFoo, test::TabBar>>::value, "");
|
||||||
#warning: OUTER is the wrong term. In a left-outer join, the *right* table is the one with optional rows.
|
#warning: OUTER is the wrong term. In a left-outer join, the *right* table is the one with optional rows.
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_outer_tables_of_t<J>, sqlpp::detail::type_set<>>::value, "");
|
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_set<>>::value, "");
|
||||||
#warning: test the provided dynamic tables of?
|
#warning: test the provided dynamic tables of?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user