ORM C++
Loading...
Searching...
No Matches
query.hpp
1#pragma once
2
3#include <optional>
4
5#include "model.hpp"
6#include "query/QueryData.hpp"
7
8namespace orm
9{
10class Database;
18template <typename T>
19class Query
20{
21public:
25 Query() : data{.modelInfo = Model<T>().getModelInfo()} {}
26
31 auto where(const query::Condition& condition) -> Query<T>&
32 {
33 data.condition = condition;
34
35 return *this;
36 }
37
43 inline auto offset(std::size_t offset) -> Query<T>&
44 {
45 data.offset = offset;
46
47 return *this;
48 }
49
55 inline auto limit(std::size_t limit) -> Query<T>&
56 {
57 data.limit = limit;
58
59 return *this;
60 }
61
67 inline auto disableJoining() -> Query<T>&
68 {
69 data.shouldJoin = false;
70
71 return *this;
72 }
73
74private:
78 friend class orm::Database;
79
84 [[nodiscard]] inline auto getData() const -> const query::QueryData&
85 {
86 return data;
87 }
88
89 query::QueryData data;
90};
91} // namespace orm
A class representing a database in the ORM framework.
Definition database.hpp:17
A template class representing a model in the ORM framework.
Definition model.hpp:17
A template class representing a select query in the ORM framework.
Definition query.hpp:20
auto limit(std::size_t limit) -> Query< T > &
Sets the LIMIT clause for the select query.
Definition query.hpp:55
auto disableJoining() -> Query< T > &
Disables joining for the select query.
Definition query.hpp:67
auto where(const query::Condition &condition) -> Query< T > &
Where clause.
Definition query.hpp:31
Query()
Constructs a Query object.
Definition query.hpp:25
auto offset(std::size_t offset) -> Query< T > &
Sets the OFFSET clause for the select query.
Definition query.hpp:43