-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathQueryModel.h
More file actions
79 lines (68 loc) · 2.25 KB
/
Copy pathQueryModel.h
File metadata and controls
79 lines (68 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once
#include <QString>
#include <QVector>
#include "ForeignKey.h"
// A single WHERE condition. Kept deliberately simple for phase 4 —
// one column, one operator, one value. Extend later for AND/OR grouping.
struct Condition
{
QString column;
QString op; // "=", "LIKE", ">", etc.
QString value;
};
// A single JOIN clause, built from a ForeignKey the user clicked in the diagram.
struct JoinClause
{
QString table;
ForeignKey onRelation;
};
// The in-memory representation of a query being built visually.
// This is the single source of truth: both the step panel (right side)
// and the SQL text box render FROM this model. Editing raw SQL directly
// is phase 5's job (escape hatch) — this model does not parse SQL back.
class QueryModel
{
public:
void setFromTable(const QString& tableName) { m_fromTable = tableName; }
const QString& fromTable() const { return m_fromTable; }
void addJoin(const QString& table, const ForeignKey& relation)
{
m_joins.push_back({table, relation});
}
void removeJoin(int index)
{
if (index >= 0 && index < m_joins.size()) {
m_joins.remove(index);
}
}
const QVector<JoinClause>& joins() const { return m_joins; }
void addCondition(const Condition& condition) { m_conditions.push_back(condition); }
void removeCondition(int index)
{
if (index >= 0 && index < m_conditions.size()) {
m_conditions.remove(index);
}
}
const QVector<Condition>& conditions() const { return m_conditions; }
bool isEmpty() const { return m_fromTable.isEmpty(); }
// Every table already referenced by the query (FROM + all JOINs).
// Used to figure out which relations/columns are still available to
// add as a new step.
QVector<QString> involvedTables() const
{
QVector<QString> result;
if (!m_fromTable.isEmpty()) {
result.push_back(m_fromTable);
}
for (const auto& join : m_joins) {
result.push_back(join.table);
}
return result;
}
// Renders the model to a formatted SQL string.
QString toSql() const;
private:
QString m_fromTable;
QVector<JoinClause> m_joins;
QVector<Condition> m_conditions;
};