IronQuery
A SQL-first query builder for C++
Loading...
Searching...
No Matches
condition.hpp
1#pragma once
2
3#include <iron_query/expr.hpp>
4#include <iron_query/operator_precedence.hpp>
5#include <memory>
6#include <string>
7
8namespace iron_query {
9
10namespace impl {
11struct Node;
12} // namespace impl
13
25class [[nodiscard]] Condition final {
26public:
28 Condition operator&&(const Condition &other) const;
29
31 Condition operator||(const Condition &other) const;
32
35
38 static Condition FromRaw(std::string s);
39
42 std::string Extract(OperatorPrecedence precedence) const;
43
46 std::string ToString() const;
47
51 operator Expr() &&;
52
53private:
54 friend class Expr;
55 friend Condition operator<(const Expr &a, const Expr &b);
56 friend Condition operator<=(const Expr &a, const Expr &b);
57 friend Condition operator>(const Expr &a, const Expr &b);
58 friend Condition operator>=(const Expr &a, const Expr &b);
59 friend Condition operator==(const Expr &a, const Expr &b);
60 friend Condition operator!=(const Expr &a, const Expr &b);
61
62 Condition(std::string s, OperatorPrecedence precedence);
63 explicit Condition(std::shared_ptr<const impl::Node> node);
64
65 std::shared_ptr<const impl::Node> node_;
66};
67
68} // namespace iron_query
A boolean-valued SQL predicate, e.g. the result of a comparison, LIKE/IN/BETWEEN/IS [NOT] NULL,...
Definition condition.hpp:25
Condition operator||(const Condition &other) const
this OR other.
Condition operator!() const
NOT this.
friend Condition operator>=(const Expr &a, const Expr &b)
a >= b.
friend Condition operator==(const Expr &a, const Expr &b)
a = b.
std::string Extract(OperatorPrecedence precedence) const
Renders the condition as SQL text, parenthesizing it if its top-level operator does not bind at least...
friend Condition operator<(const Expr &a, const Expr &b)
a < b.
friend Condition operator!=(const Expr &a, const Expr &b)
a != b.
Condition operator&&(const Condition &other) const
this AND other.
static Condition FromRaw(std::string s)
Wraps a trusted, developer-written SQL predicate verbatim. Never pass untrusted/dynamic data here.
friend Condition operator<=(const Expr &a, const Expr &b)
a <= b.
std::string ToString() const
Renders the condition as a standalone, unparenthesized SQL fragment.
friend Condition operator>(const Expr &a, const Expr &b)
a > b.
Arbitrary SQL expression.
Definition expr.hpp:46
OperatorPrecedence
Relative binding strength of SQL operators, used by iron_query::Expr::Extract to decide whether a sub...
Definition operator_precedence.hpp:10