summary refs log tree commit diff stats
path: root/lib/statement.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/statement.h')
-rw-r--r--lib/statement.h96
1 files changed, 55 insertions, 41 deletions
diff --git a/lib/statement.h b/lib/statement.h index 2fadf05..6c2e42e 100644 --- a/lib/statement.h +++ b/lib/statement.h
@@ -4,8 +4,8 @@
4#include <string> 4#include <string>
5#include <list> 5#include <list>
6#include <map> 6#include <map>
7#include <set> 7#include <hkutil/database.h>
8#include "binding.h" 8#include <variant.hpp>
9#include "enums.h" 9#include "enums.h"
10#include "field.h" 10#include "field.h"
11#include "filter.h" 11#include "filter.h"
@@ -15,14 +15,28 @@ namespace verbly {
15 class filter; 15 class filter;
16 class order; 16 class order;
17 17
18 using field_binding =
19 std::tuple<std::string, std::string>;
20
21 using binding =
22 mpark::variant<
23 mpark::monostate,
24 std::string,
25 int,
26 field_binding>;
27
18 class statement { 28 class statement {
19 public: 29 public:
20 30
21 statement(object context, filter queryFilter); 31 statement(object context, filter queryFilter);
22 32
23 std::string getQueryString(std::list<std::string> select, order sortOrder, int limit, bool debug = false) const; 33 std::string getQueryString(
34 std::list<std::string> select,
35 order sortOrder,
36 int limit,
37 bool debug = false) const;
24 38
25 std::list<binding> getBindings() const; 39 std::list<hatkirby::binding> getBindings() const;
26 40
27 private: 41 private:
28 42
@@ -108,23 +122,6 @@ namespace verbly {
108 is_null 122 is_null
109 }; 123 };
110 124
111 // Copy and move constructors
112
113 condition(const condition& other);
114 condition(condition&& other);
115
116 // Assignment
117
118 condition& operator=(condition other);
119
120 // Swap
121
122 friend void swap(condition& first, condition& second);
123
124 // Destructor
125
126 ~condition();
127
128 // Accessors 125 // Accessors
129 126
130 type getType() const 127 type getType() const
@@ -134,13 +131,21 @@ namespace verbly {
134 131
135 // Empty 132 // Empty
136 133
137 condition(); 134 condition() = default;
138 135
139 // Singleton 136 // Singleton
140 137
141 condition(std::string table, std::string column, bool isNull); 138 condition(
139 std::string table,
140 std::string column,
141 bool isNull);
142 142
143 condition(std::string table, std::string column, comparison comp, binding value, object parentObject = object::undefined); 143 condition(
144 std::string table,
145 std::string column,
146 comparison comp,
147 binding value,
148 object parentObject = object::undefined);
144 149
145 // Group 150 // Group
146 151
@@ -156,30 +161,39 @@ namespace verbly {
156 161
157 std::string toSql(bool toplevel, bool debug = false) const; 162 std::string toSql(bool toplevel, bool debug = false) const;
158 163
159 std::list<binding> flattenBindings() const; 164 std::list<hatkirby::binding> flattenBindings() const;
160 165
161 condition flatten() const; 166 condition flatten() const;
162 167
163 condition resolveCompareFields(object context, std::string tableName) const; 168 condition resolveCompareFields(
169 object context,
170 std::string tableName) const;
164 171
165 private: 172 private:
166 union { 173
167 struct { 174 struct singleton_type {
168 std::string table_; 175 std::string table;
169 std::string column_; 176 std::string column;
170 comparison comparison_; 177 comparison comparison;
171 binding value_; 178 binding value;
172 object parentObject_; 179 object parentObject;
173 } singleton_;
174 struct {
175 std::list<condition> children_;
176 bool orlogic_;
177 } group_;
178 }; 180 };
179 type type_;
180 };
181 181
182 friend void swap(condition& first, condition& second); 182 struct group_type {
183 std::list<condition> children;
184 bool orlogic;
185 };
186
187 using variant_type =
188 mpark::variant<
189 mpark::monostate,
190 singleton_type,
191 group_type>;
192
193 variant_type variant_;
194
195 type type_ = type::empty;
196 };
183 197
184 class with { 198 class with {
185 public: 199 public: