mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Made boolean expression more usable
This commit is contained in:
parent
c0902f8683
commit
ad1c5f94bb
@ -33,17 +33,17 @@
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename Database>
|
||||
struct boolean_expression_t
|
||||
struct boolean_expression_t: public boolean::template expression_operators<boolean_expression_t<Database>>
|
||||
{
|
||||
using _traits = make_traits<boolean, tag::is_expression>;
|
||||
using _recursive_traits = make_recursive_traits<>;
|
||||
|
||||
template<typename Expression>
|
||||
boolean_expression_t(Expression expression):
|
||||
_expression(expression)
|
||||
template<typename Expr>
|
||||
boolean_expression_t(Expr expr):
|
||||
_expr(expr)
|
||||
{
|
||||
static_assert(is_expression_t<Expression>::value, "boolean_expression requires a boolean expression argument");
|
||||
static_assert(is_boolean_t<Expression>::value, "boolean_expression requires a boolean expression argument");
|
||||
static_assert(is_expression_t<Expr>::value, "boolean_expression requires a boolean expression argument");
|
||||
static_assert(is_boolean_t<Expr>::value, "boolean_expression requires a boolean expression argument");
|
||||
}
|
||||
|
||||
boolean_expression_t(const boolean_expression_t&) = default;
|
||||
@ -52,19 +52,20 @@ namespace sqlpp
|
||||
boolean_expression_t& operator=(boolean_expression_t&&) = default;
|
||||
~boolean_expression_t() = default;
|
||||
|
||||
interpretable_t<Database> _expression;
|
||||
interpretable_t<Database> _expr;
|
||||
};
|
||||
|
||||
template<typename Database, typename T>
|
||||
boolean_expression_t<Database> boolean_expression(const Database&, T t)
|
||||
{
|
||||
return {t};
|
||||
}
|
||||
|
||||
template<typename Database, typename T>
|
||||
boolean_expression_t<Database> boolean_expression(T t)
|
||||
{
|
||||
return {t};
|
||||
using Expr = wrap_operand_t<T>;
|
||||
return {Expr{t}};
|
||||
}
|
||||
|
||||
template<typename Database, typename T>
|
||||
boolean_expression_t<Database> boolean_expression(const Database&, T t)
|
||||
{
|
||||
return boolean_expression<Database>(t);
|
||||
}
|
||||
|
||||
template<typename Context, typename Database>
|
||||
@ -74,7 +75,7 @@ namespace sqlpp
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
return serialize(t._expression);
|
||||
return serialize(t._expr, context);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -35,8 +35,10 @@ int main()
|
||||
test::TabBar t;
|
||||
|
||||
auto x = boolean_expression(db, t.alpha == 7);
|
||||
x = boolean_expression(db, t.gamma);
|
||||
x = sqlpp::boolean_expression<MockDb>(t.beta.like("%cheesecake"));
|
||||
x = x and boolean_expression(db, t.gamma);
|
||||
|
||||
db(select(t.alpha).from(t).where(x));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -25,12 +25,7 @@
|
||||
|
||||
#include "Sample.h"
|
||||
#include "MockDb.h"
|
||||
#include <sqlpp11/alias_provider.h>
|
||||
#include <sqlpp11/insert.h>
|
||||
#include <sqlpp11/select.h>
|
||||
#include <sqlpp11/update.h>
|
||||
#include <sqlpp11/remove.h>
|
||||
#include <sqlpp11/functions.h>
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@ -177,5 +172,14 @@ int main()
|
||||
|
||||
flatten(t.alpha == 7, db);
|
||||
|
||||
auto x = boolean_expression(db, t.alpha == 7);
|
||||
x = sqlpp::boolean_expression<MockDb>(t.beta.like("%cheesecake"));
|
||||
x = x and boolean_expression(db, t.gamma);
|
||||
std::cerr << "----------------------------" << std::endl;
|
||||
printer.reset();
|
||||
std::cerr << serialize(x, printer).str() << std::endl;
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user