0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 12:51:13 +08:00

Add enable_as

This commit is contained in:
Roland Bock 2024-07-15 07:57:08 +02:00
parent 2d2f08007a
commit bdd87b9e03
2 changed files with 54 additions and 7 deletions

View File

@ -26,6 +26,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sqlpp11/enable_as.h>
#include <sqlpp11/operator/as_expression.h>
#include <sqlpp11/operator/assign_expression.h>
#include <sqlpp11/column_fwd.h>
@ -39,7 +40,8 @@ namespace sqlpp
{
#warning: need to reactivate column operators?
template <typename Table, typename ColumnSpec>
struct column_t// : public expression_operators<column_t<Table, ColumnSpec>, typename ColumnSpec::value_type>,
struct column_t : public enable_as<column_t<Table, ColumnSpec>>
// : public expression_operators<column_t<Table, ColumnSpec>, typename ColumnSpec::value_type>,
// public column_operators<column_t<Table, ColumnSpec>, typename ColumnSpec::value_type>
{
struct _traits
@ -69,12 +71,6 @@ namespace sqlpp
return _table{};
}
template <typename AliasProvider>
auto as(const AliasProvider& alias_provider) const -> as_expression<column_t, AliasProvider>
{
return as(*this, alias_provider);
}
sqlpp::compat::optional<column_t> if_(bool condition) const
{
return condition ? sqlpp::compat::make_optional(*this) : sqlpp::compat::nullopt;

View File

@ -0,0 +1,51 @@
#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:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. 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/operator/as_expression.h>
#include <sqlpp11/type_traits.h>
namespace sqlpp
{
// To be used as CRTP base for expressions that should offer the as() member function.
template <typename Expr>
class enable_as
{
constexpr decltype(auto) derived() const
{
return static_cast<const Expr&>(*this);
}
public:
template <typename AliasProvider>
constexpr auto as(const AliasProvider& alias) const
{
return ::sqlpp::as(this->derived(), alias);
}
};
} // namespace sqlpp