Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
condition_builder.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
7#include "../database_types.h"
8#include "value_formatter.h"
9#include <string>
10#include <vector>
11#include <memory>
12
13namespace database::query {
14
19enum class logical_op {
20 AND,
21 OR
22};
23
28struct condition {
29 std::string field;
30 std::string op;
32 std::string raw;
33
34 bool is_raw() const { return !raw.empty(); }
35};
36
71public:
73
81
90 condition_builder& add(const std::string& field, const std::string& operator_,
92
99 condition_builder& add_raw(const std::string& raw, logical_op op = logical_op::AND);
100
106
112
118 std::string build(const value_formatter& formatter) const;
119
124 bool empty() const;
125
129 void clear();
130
131private:
139
140 std::vector<condition_node> nodes_;
142
143 std::string format_condition(const condition& cond, const value_formatter& formatter) const;
144 std::string logical_op_to_string(logical_op op) const;
145};
146
147} // namespace database::query
Builds WHERE clause conditions with proper precedence.
condition_builder & end_group()
End a condition group (adds closing parenthesis)
void clear()
Clear all conditions.
condition_builder & add_raw(const std::string &raw, logical_op op=logical_op::AND)
Add a raw SQL condition.
std::string logical_op_to_string(logical_op op) const
std::vector< condition_node > nodes_
condition_builder & begin_group()
Begin a condition group (adds opening parenthesis)
std::string build(const value_formatter &formatter) const
Build the WHERE clause.
std::string format_condition(const condition &cond, const value_formatter &formatter) const
bool empty() const
Check if builder is empty.
condition_builder & add(const condition &cond, logical_op op=logical_op::AND)
Add a condition.
Formats database values for different backends.
Defines the enumeration of supported database types.
std::variant< std::string, int64_t, double, bool, std::nullptr_t > database_value
logical_op
Logical operators for combining conditions.
Represents a single WHERE condition.
core::database_value value
Value to compare.
std::string raw
Raw SQL condition (if any)
std::string field
Field name.
std::string op
Operator (=, !=, <, >, <=, >=, LIKE, IN, etc.)