Appwrite C++ SDK
Auto-generated API documentation for the Appwrite C++ SDK
Loading...
Searching...
No Matches
Queries Class Reference

Utility class to construct and manage Appwrite-style database query filters. More...

#include <Query.hpp>

Collaboration diagram for Queries:

Public Member Functions

void addComplexQuery (const std::string jsonQuery)
 Add a raw JSON complex query.
 
template<typename T >
void notEqual (const std::string attributeId, std::list< T > &values)
 Filter documents where attribute does not equal any value in list.
 
 Queries ()
 Constructor.
 
template<typename T >
void queryBetween (const std::string attributeId, const T &value1, const T &value2)
 Filter documents where attribute is between two values.
 
void queryContains (const std::string attributeId, const std::string &value)
 Filter documents where attribute contains the value.
 
template<typename T >
void queryContains (const std::string attributeId, std::list< T > &value)
 Filter documents where attribute contains any value from list.
 
void queryCursorAfter (const std::string documentId)
 Add a cursor query to paginate after the given document ID.
 
void queryEndsWith (const std::string attributeId, const std::string &value)
 Filter documents where attribute ends with given value.
 
template<typename T >
void queryEqual (const std::string attributeId, std::list< T > &values)
 Filter documents where attribute equals any value in list.
 
template<typename T >
void queryGreaterThan (const std::string attributeId, const T &value)
 Filter documents where attribute is greater than value.
 
template<typename T >
void queryGreaterThanEqual (const std::string attributeId, const T &value)
 Filter documents where attribute is greater than or equal to value.
 
void queryIsNotNull (const std::string attributeId)
 Filter documents where an attribute is not null.
 
void queryIsNull (const std::string attributeId)
 Filter documents where an attribute is null.
 
template<typename T >
void queryLessThan (const std::string attributeId, const T &value)
 Filter documents where attribute is less than value.
 
template<typename T >
void queryLessThanEqual (const std::string attributeId, const T &value)
 Filter documents where attribute is less than or equal to value.
 
void queryLimit (int limit)
 Limit the number of documents returned.
 
void querySelect (std::list< std::string > &values)
 Select only certain fields from the result.
 
void queryStartsWith (const std::string attributeId, const std::string &value)
 Filter documents where attribute starts with given value.
 
bool removeJsonQuery (int index)
 Remove a JSON query by index.
 
void reset ()
 Resets the internal query list.
 
std::string to_string ()
 Serialize all added queries into a JSON string.
 

Detailed Description

Utility class to construct and manage Appwrite-style database query filters.

Provides methods to build query filters like equal, contains, range-based, null checks, and complex queries for Appwrite API requests.

Definition at line 24 of file Query.hpp.

Constructor & Destructor Documentation

◆ Queries()

Queries::Queries ( )

Constructor.

Member Function Documentation

◆ addComplexQuery()

void Queries::addComplexQuery ( const std::string  jsonQuery)

Add a raw JSON complex query.

Parameters
jsonQueryA valid Appwrite-style JSON query string.

◆ notEqual()

template<typename T >
void Queries::notEqual ( const std::string  attributeId,
std::list< T > &  values 
)
inline

Filter documents where attribute does not equal any value in list.

Template Parameters
TValue type.
Parameters
attributeIdThe attribute key.
valuesList of disallowed values.

Definition at line 244 of file Query.hpp.

244 {
245 std::string query = "{\"method\":\"notEqual\",\"attribute\":\"" +
246 attributeId + "\",\"values\":[" +
247 listToString(values) + "]}";
248 if (not_equal_iter == queries.end()) {
249 queries.push_back(query);
250 not_equal_iter = std::prev(queries.end());
251 return;
252 }
253 *not_equal_iter = query;
254 }

◆ queryBetween()

template<typename T >
void Queries::queryBetween ( const std::string  attributeId,
const T &  value1,
const T &  value2 
)
inline

Filter documents where attribute is between two values.

Template Parameters
TComparable value type.
Parameters
attributeIdThe attribute key.
value1Lower bound.
value2Upper bound.

Definition at line 118 of file Query.hpp.

119 {
120 std::ostringstream oss;
121
122 oss << append_encoded(oss, value1);
123 oss << ",";
124 oss << append_encoded(oss, value2);
125
126 std::string query = "{\"method\":\"between\",\"attribute\":\"" +
127 attributeId + "\",\"values\":[" + oss.str() + "]}";
128 if (between_iter == queries.end()) {
129 queries.push_back(query);
130 between_iter = std::prev(queries.end());
131 return;
132 }
133 *between_iter = query;
134 }

◆ queryContains() [1/2]

void Queries::queryContains ( const std::string  attributeId,
const std::string &  value 
)

Filter documents where attribute contains the value.

Parameters
attributeIdThe attribute key.
valueThe substring to match.

◆ queryContains() [2/2]

template<typename T >
void Queries::queryContains ( const std::string  attributeId,
std::list< T > &  value 
)
inline

Filter documents where attribute contains any value from list.

Template Parameters
TType of values in the list.
Parameters
attributeIdThe attribute key.
valueList of values to check containment.

Definition at line 98 of file Query.hpp.

98 {
99 std::string query = "{\"method\":\"contains\",\"attribute\":\"" +
100 attributeId + "\",\"values\":[" +
101 listToString(value) + "]}";
102 if (contains_iter == queries.end()) {
103 queries.push_back(query);
104 contains_iter = std::prev(queries.end());
105 return;
106 }
107 *contains_iter = query;
108 }

◆ queryCursorAfter()

void Queries::queryCursorAfter ( const std::string  documentId)

Add a cursor query to paginate after the given document ID.

Parameters
documentIdThe document ID to start after.

◆ queryEndsWith()

void Queries::queryEndsWith ( const std::string  attributeId,
const std::string &  value 
)

Filter documents where attribute ends with given value.

Parameters
attributeIdThe attribute key.
valueThe ending value to match.

◆ queryEqual()

template<typename T >
void Queries::queryEqual ( const std::string  attributeId,
std::list< T > &  values 
)
inline

Filter documents where attribute equals any value in list.

Template Parameters
TValue type.
Parameters
attributeIdThe attribute key.
valuesList of accepted values.

Definition at line 225 of file Query.hpp.

225 {
226 std::string query = "{\"method\":\"equal\",\"attribute\":\"" +
227 attributeId + "\",\"values\":[" +
228 listToString(values) + "]}";
229 if (equal_iter == queries.end()) {
230 queries.push_back(query);
231 equal_iter = std::prev(queries.end());
232 return;
233 }
234 *equal_iter = query;
235 }

◆ queryGreaterThan()

template<typename T >
void Queries::queryGreaterThan ( const std::string  attributeId,
const T &  value 
)
inline

Filter documents where attribute is greater than value.

Template Parameters
TValue type.
Parameters
attributeIdThe attribute key.
valueThe threshold.

Definition at line 165 of file Query.hpp.

165 {
166 std::ostringstream oss;
167 append_encoded(oss, value);
168 std::string query = "{\"method\":\"greaterThan\",\"attribute\":\"" +
169 attributeId + "\",\"values\":[" + oss.str() + "]}";
170 if (greater_than_iter == queries.end()) {
171 queries.push_back(query);
172 greater_than_iter = std::prev(queries.end());
173 return;
174 }
175 *greater_than_iter = query;
176 }

◆ queryGreaterThanEqual()

template<typename T >
void Queries::queryGreaterThanEqual ( const std::string  attributeId,
const T &  value 
)
inline

Filter documents where attribute is greater than or equal to value.

Template Parameters
TValue type.
Parameters
attributeIdThe attribute key.
valueThe lower bound.

Definition at line 144 of file Query.hpp.

144 {
145 std::ostringstream oss;
146 oss << append_encoded(oss, value);
147 std::string query =
148 "{\"method\":\"greaterThanEqual\",\"attribute\":\"" + attributeId +
149 "\",\"values\":[" + oss.str() + "]}";
150 if (greater_than_equal_iter == queries.end()) {
151 queries.push_back(query);
152 greater_than_equal_iter = std::prev(queries.end());
153 return;
154 }
155 *greater_than_equal_iter = query;
156 }

◆ queryIsNotNull()

void Queries::queryIsNotNull ( const std::string  attributeId)

Filter documents where an attribute is not null.

Parameters
attributeIdThe attribute key to filter.

◆ queryIsNull()

void Queries::queryIsNull ( const std::string  attributeId)

Filter documents where an attribute is null.

Parameters
attributeIdThe attribute key to filter.

◆ queryLessThan()

template<typename T >
void Queries::queryLessThan ( const std::string  attributeId,
const T &  value 
)
inline

Filter documents where attribute is less than value.

Template Parameters
TValue type.
Parameters
attributeIdThe attribute key.
valueThe threshold.

Definition at line 205 of file Query.hpp.

205 {
206 std::ostringstream oss;
207 append_encoded(oss, value);
208 std::string query = "{\"method\":\"lessThan\",\"attribute\":\"" +
209 attributeId + "\",\"values\":[" + oss.str() + "]}";
210 if (less_than_iter == queries.end()) {
211 queries.push_back(query);
212 less_than_iter = std::prev(queries.end());
213 return;
214 }
215 *less_than_iter = query;
216 }

◆ queryLessThanEqual()

template<typename T >
void Queries::queryLessThanEqual ( const std::string  attributeId,
const T &  value 
)
inline

Filter documents where attribute is less than or equal to value.

Template Parameters
TValue type.
Parameters
attributeIdThe attribute key.
valueThe upper bound.

Definition at line 185 of file Query.hpp.

185 {
186 std::ostringstream oss;
187 append_encoded(oss, value);
188 std::string query = "{\"method\":\"lessThanEqual\",\"attribute\":\"" +
189 attributeId + "\",\"values\":[" + oss.str() + "]}";
190 if (less_than_equal_iter == queries.end()) {
191 queries.push_back(query);
192 less_than_equal_iter = std::prev(queries.end());
193 return;
194 }
195 *less_than_equal_iter = query;
196 }

◆ queryLimit()

void Queries::queryLimit ( int  limit)

Limit the number of documents returned.

Parameters
limitThe maximum number of documents.

◆ querySelect()

void Queries::querySelect ( std::list< std::string > &  values)

Select only certain fields from the result.

Parameters
valuesList of field names to return.

◆ queryStartsWith()

void Queries::queryStartsWith ( const std::string  attributeId,
const std::string &  value 
)

Filter documents where attribute starts with given value.

Parameters
attributeIdThe attribute key.
valueThe starting value to match.

◆ removeJsonQuery()

bool Queries::removeJsonQuery ( int  index)

Remove a JSON query by index.

Parameters
indexThe index of the query to remove.
Returns
True if the query was removed, false if index is invalid.

◆ reset()

void Queries::reset ( )

Resets the internal query list.

◆ to_string()

std::string Queries::to_string ( )

Serialize all added queries into a JSON string.

Returns
Combined query string.

The documentation for this class was generated from the following file: