2023-07-25 13:00:05 +08:00
|
|
|
#pragma once
|
|
|
|
|
2017-12-19 02:38:41 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2015, Roland Bock
|
|
|
|
* Copyright (c) 2017, Juan Dent
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2024-07-14 18:09:00 +08:00
|
|
|
#include <sqlpp11/serialize.h>
|
|
|
|
#include <sqlpp11/type_traits.h>
|
2017-12-19 02:38:41 +08:00
|
|
|
|
|
|
|
namespace sqlpp
|
|
|
|
{
|
2024-07-14 18:09:00 +08:00
|
|
|
template <typename Expr>
|
|
|
|
struct trim_t
|
2017-12-19 02:38:41 +08:00
|
|
|
{
|
|
|
|
using _traits = make_traits<text, tag::is_expression, tag::is_selectable>;
|
|
|
|
|
2019-08-28 15:42:48 +08:00
|
|
|
using _nodes = detail::type_vector<Expr>;
|
2017-12-19 02:38:41 +08:00
|
|
|
|
|
|
|
trim_t(const Expr expr) : _expr(expr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
trim_t(const trim_t&) = default;
|
|
|
|
trim_t(trim_t&&) = default;
|
|
|
|
trim_t& operator=(const trim_t&) = default;
|
|
|
|
trim_t& operator=(trim_t&&) = default;
|
|
|
|
~trim_t() = default;
|
|
|
|
|
|
|
|
Expr _expr;
|
|
|
|
};
|
|
|
|
|
2024-07-14 18:09:00 +08:00
|
|
|
template <typename Context, typename Expr>
|
|
|
|
Context& serialize(const trim_t<Expr>& t, Context& context)
|
2017-12-19 02:38:41 +08:00
|
|
|
{
|
2021-08-01 18:54:46 +08:00
|
|
|
context << "TRIM(";
|
2023-02-04 16:05:04 +08:00
|
|
|
serialize_operand(t._expr, context);
|
2021-08-01 18:54:46 +08:00
|
|
|
context << ")";
|
|
|
|
return context;
|
|
|
|
}
|
2017-12-19 02:38:41 +08:00
|
|
|
|
2024-07-14 18:09:00 +08:00
|
|
|
template<typename T>
|
|
|
|
using check_trim_args = std::enable_if_t<is_text<T>::value>;
|
|
|
|
|
|
|
|
template <typename T, typename = check_trim_args<T>>
|
|
|
|
auto trim(T t) -> trim_t<T>
|
2017-12-19 02:38:41 +08:00
|
|
|
{
|
2024-07-14 18:09:00 +08:00
|
|
|
return {std::move(t)};
|
2017-12-19 02:38:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace sqlpp
|