mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Re-wrote in()/not_in() to use a specific template and removed the generic nary member function template
The specific version is easier to understand and could be adjusted more easily if some database should not support it...
This commit is contained in:
parent
7fde9dafb2
commit
1a8ea5a3b3
@ -30,6 +30,7 @@
|
|||||||
#include <sqlpp11/expression_fwd.h>
|
#include <sqlpp11/expression_fwd.h>
|
||||||
#include <sqlpp11/alias.h>
|
#include <sqlpp11/alias.h>
|
||||||
#include <sqlpp11/sort_order.h>
|
#include <sqlpp11/sort_order.h>
|
||||||
|
#include <sqlpp11/in.h>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
@ -75,12 +76,6 @@ namespace sqlpp
|
|||||||
static constexpr const char* _name = "IS NOT NULL";
|
static constexpr const char* _name = "IS NOT NULL";
|
||||||
};
|
};
|
||||||
|
|
||||||
struct in_
|
|
||||||
{
|
|
||||||
using _value_type = boolean;
|
|
||||||
static constexpr const char* _name = "IN";
|
|
||||||
};
|
|
||||||
|
|
||||||
struct not_in_
|
struct not_in_
|
||||||
{
|
{
|
||||||
using _value_type = boolean;
|
using _value_type = boolean;
|
||||||
@ -149,16 +144,14 @@ namespace sqlpp
|
|||||||
|
|
||||||
// Hint: use value_list wrapper for containers...
|
// Hint: use value_list wrapper for containers...
|
||||||
template<typename... T>
|
template<typename... T>
|
||||||
nary_member_function_t<Base, in_, typename Constraint<T>::type...> in(T&&... t) const
|
in_t<true, Base, typename Constraint<T>::type...> in(T&&... t) const
|
||||||
{
|
{
|
||||||
static_assert(sizeof...(T) > 0, "in() requires at least one argument");
|
|
||||||
return { *static_cast<const Base*>(this), std::forward<T>(t)... };
|
return { *static_cast<const Base*>(this), std::forward<T>(t)... };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... T>
|
template<typename... T>
|
||||||
nary_member_function_t<Base, not_in_, typename Constraint<T>::type...> not_in(T&&... t) const
|
in_t<false, Base, typename Constraint<T>::type...> not_in(T&&... t) const
|
||||||
{
|
{
|
||||||
static_assert(sizeof...(T) > 0, "not_in() requires at least one argument");
|
|
||||||
return { *static_cast<const Base*>(this), std::forward<T>(t)... };
|
return { *static_cast<const Base*>(this), std::forward<T>(t)... };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,45 +244,6 @@ namespace sqlpp
|
|||||||
Rhs _rhs;
|
Rhs _rhs;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Lhs, typename O, typename... Rhs>
|
|
||||||
struct nary_member_function_t: public O::_value_type::template operators<nary_member_function_t<Lhs, O, Rhs...>>
|
|
||||||
{
|
|
||||||
using _value_type = typename O::_value_type;
|
|
||||||
|
|
||||||
nary_member_function_t(Lhs&& l, Rhs&&... r):
|
|
||||||
_lhs(std::move(l)),
|
|
||||||
_rhs(std::move(r)...)
|
|
||||||
{}
|
|
||||||
|
|
||||||
nary_member_function_t(const Lhs& l, const Rhs&... r):
|
|
||||||
_lhs(l),
|
|
||||||
_rhs(r...)
|
|
||||||
{}
|
|
||||||
|
|
||||||
nary_member_function_t(const nary_member_function_t&) = default;
|
|
||||||
nary_member_function_t(nary_member_function_t&&) = default;
|
|
||||||
nary_member_function_t& operator=(const nary_member_function_t&) = default;
|
|
||||||
nary_member_function_t& operator=(nary_member_function_t&&) = default;
|
|
||||||
~nary_member_function_t() = default;
|
|
||||||
|
|
||||||
template<typename Db>
|
|
||||||
void serialize(std::ostream& os, Db& db) const
|
|
||||||
{
|
|
||||||
os << "(";
|
|
||||||
_lhs.serialize(os, db);
|
|
||||||
os << " ";
|
|
||||||
os << O::_name;
|
|
||||||
os << "(";
|
|
||||||
detail::serialize_tuple(os, db, _rhs, ',');
|
|
||||||
os << ")";
|
|
||||||
os << ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Lhs _lhs;
|
|
||||||
std::tuple<Rhs...> _rhs;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
91
include/sqlpp11/in.h
Normal file
91
include/sqlpp11/in.h
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* 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_IN_H
|
||||||
|
#define SQLPP_IN_H
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <sqlpp11/type_traits.h>
|
||||||
|
#include <sqlpp11/detail/set.h>
|
||||||
|
|
||||||
|
namespace sqlpp
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template<bool not_inverted, typename Operand, typename... Args>
|
||||||
|
struct in_t: public Operand::_value_type::template operators<in_t<not_inverted, Operand, Args...>>
|
||||||
|
{
|
||||||
|
static constexpr bool inverted = not not_inverted;
|
||||||
|
static_assert(sizeof...(Args) > 0, "in() requires at least one argument");
|
||||||
|
|
||||||
|
struct _value_type: public Operand::_value_type::_base_value_type
|
||||||
|
{
|
||||||
|
using _is_named_expression = std::true_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _name_t
|
||||||
|
{
|
||||||
|
static constexpr const char* _get_name() { return inverted ? "NOT IN" : "IN"; }
|
||||||
|
template<typename T>
|
||||||
|
struct _member_t
|
||||||
|
{
|
||||||
|
T in;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
in_t(const Operand& operand, const Args&... args):
|
||||||
|
_operand(operand),
|
||||||
|
_args(args...)
|
||||||
|
{}
|
||||||
|
|
||||||
|
in_t(Operand&& operand, Args&&... args):
|
||||||
|
_operand(std::move(operand)),
|
||||||
|
_args(std::move(args...))
|
||||||
|
{}
|
||||||
|
|
||||||
|
in_t(const in_t&) = default;
|
||||||
|
in_t(in_t&&) = default;
|
||||||
|
in_t& operator=(const in_t&) = default;
|
||||||
|
in_t& operator=(in_t&&) = default;
|
||||||
|
~in_t() = default;
|
||||||
|
|
||||||
|
template<typename Db>
|
||||||
|
void serialize(std::ostream& os, Db& db) const
|
||||||
|
{
|
||||||
|
_operand.serialize(os, db);
|
||||||
|
os << (inverted ? " NOT IN(" : " IN(");
|
||||||
|
detail::serialize_tuple(os, db, _args, ',');
|
||||||
|
os << ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Operand _operand;
|
||||||
|
std::tuple<Args...> _args;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user