xale-db 1.0
minimal SQL engine, written in c++
Loading...
Searching...
No Matches
Statement.h
Go to the documentation of this file.
1#ifndef QUERY_STATEMENT_H
2#define QUERY_STATEMENT_H
3
4#include <string>
5#include <vector>
6#include <memory>
7#include <variant>
8
9namespace Xale::Query
10{
25
37
41 struct Expression;
42 struct BinaryExpression;
43
48 {
50 std::string value;
51 std::unique_ptr<BinaryExpression> binary;
52
54 explicit Expression(ExpressionType t, std::string val = "")
55 : type(t), value(std::move(val)) {}
56 };
57
62 {
63 std::unique_ptr<Expression> left;
64 std::string op;
65 std::unique_ptr<Expression> right;
66
67 BinaryExpression() = default;
68 BinaryExpression(std::unique_ptr<Expression> l, std::string operation, std::unique_ptr<Expression> r)
69 : left(std::move(l)), op(std::move(operation)), right(std::move(r)) {}
70 };
71
76 {
77 std::unique_ptr<Expression> condition;
78
79 WhereClause() = default;
80 explicit WhereClause(std::unique_ptr<Expression> cond)
81 : condition(std::move(cond)) {}
82 };
83
87 struct Statement
88 {
90
91 explicit Statement(StatementType t) : type(t) {}
92 virtual ~Statement() = default;
93 };
94
99 {
100 std::string tableName;
101 std::string leftTableCol;
102 std::string rightTableCol;
103 };
104
109 {
110 std::vector<Expression> columns;
111 std::string tableName;
112 std::vector<JoinClause> joins;
113 std::unique_ptr<WhereClause> where;
114
116 };
117
122 {
123 std::string tableName;
124 std::vector<std::string> columns;
125 std::vector<Expression> values;
126
128 };
129
134 {
135 std::string tableName;
136 std::vector<std::pair<std::string, Expression>> assignments;
137 std::unique_ptr<WhereClause> where;
138
140 };
141
146 {
147 std::string tableName;
148 std::unique_ptr<WhereClause> where;
149
151 };
152
157 {
158 std::string refTable;
159 std::string refColumn;
160 };
161
166 {
167 std::string name;
168 std::string type;
171
173 ColumnDefinitionStmt(std::string n, std::string t, bool pk = false)
174 : name(std::move(n)), type(std::move(t)), isPrimaryKey(pk) {}
175 };
176
181 {
182 std::string tableName;
183 std::vector<ColumnDefinitionStmt> columns;
184
186 };
187
191 struct DropStatement : public Statement
192 {
193 std::string tableName;
194
196 };
197
198
206}
207
208#endif // QUERY_STATEMENT_H
Definition BasicParser.h:16
StatementType
Types of SQL statements.
Definition Statement.h:15
@ Update
Definition Statement.h:18
@ Drop
Definition Statement.h:21
@ List
Definition Statement.h:22
@ Create
Definition Statement.h:20
@ Unknown
Definition Statement.h:23
@ Insert
Definition Statement.h:17
@ Select
Definition Statement.h:16
@ Delete
Definition Statement.h:19
ExpressionType
Types of expression nodes.
Definition Statement.h:30
@ Identifier
Definition Statement.h:31
@ StringLiteral
Definition Statement.h:32
@ BinaryOp
Definition Statement.h:34
@ NumericLiteral
Definition Statement.h:33
@ Wildcard
Definition Statement.h:35
std::unique_ptr< Expression > right
Definition Statement.h:65
BinaryExpression(std::unique_ptr< Expression > l, std::string operation, std::unique_ptr< Expression > r)
Definition Statement.h:68
std::string op
Definition Statement.h:64
std::unique_ptr< Expression > left
Definition Statement.h:63
std::string name
Definition Statement.h:167
ForeignKeyRef references
Empty refTable means no FK.
Definition Statement.h:170
bool isPrimaryKey
Definition Statement.h:169
std::string type
Definition Statement.h:168
ColumnDefinitionStmt()
Definition Statement.h:172
ColumnDefinitionStmt(std::string n, std::string t, bool pk=false)
Definition Statement.h:173
std::vector< ColumnDefinitionStmt > columns
Definition Statement.h:183
std::string tableName
Definition Statement.h:182
CreateStatement()
Definition Statement.h:185
std::unique_ptr< WhereClause > where
Definition Statement.h:148
DeleteStatement()
Definition Statement.h:150
std::string tableName
Definition Statement.h:147
DropStatement()
Definition Statement.h:195
std::string tableName
Definition Statement.h:193
Expression()
Definition Statement.h:53
Expression(ExpressionType t, std::string val="")
Definition Statement.h:54
std::unique_ptr< BinaryExpression > binary
Definition Statement.h:51
ExpressionType type
Definition Statement.h:49
std::string value
Definition Statement.h:50
Represents a REFERENCES clause in a column definition.
Definition Statement.h:157
std::string refTable
Referenced table name.
Definition Statement.h:158
std::string refColumn
Referenced column name (may be empty).
Definition Statement.h:159
InsertStatement()
Definition Statement.h:127
std::vector< std::string > columns
Definition Statement.h:124
std::vector< Expression > values
Definition Statement.h:125
std::string tableName
Definition Statement.h:123
Represents a JOIN clause (INNER JOIN only for now).
Definition Statement.h:99
std::string leftTableCol
Left side of ON condition (e.g. "orders.user_id").
Definition Statement.h:101
std::string tableName
Joined table name.
Definition Statement.h:100
std::string rightTableCol
Right side of ON condition (e.g. "users.id").
Definition Statement.h:102
ListStatement()
Definition Statement.h:204
std::vector< JoinClause > joins
Optional JOIN clauses.
Definition Statement.h:112
std::vector< Expression > columns
Definition Statement.h:110
SelectStatement()
Definition Statement.h:115
std::unique_ptr< WhereClause > where
Definition Statement.h:113
std::string tableName
Definition Statement.h:111
Statement(StatementType t)
Definition Statement.h:91
StatementType type
Definition Statement.h:89
virtual ~Statement()=default
std::string tableName
Definition Statement.h:135
std::unique_ptr< WhereClause > where
Definition Statement.h:137
std::vector< std::pair< std::string, Expression > > assignments
Definition Statement.h:136
UpdateStatement()
Definition Statement.h:139
WhereClause(std::unique_ptr< Expression > cond)
Definition Statement.h:80
std::unique_ptr< Expression > condition
Definition Statement.h:77