QueryBuilder
QueryBuilder
¶
QueryBuilder()
A class for constructing database queries in a structured way.
This class provides a fluent interface for building queriess. It encapsulates the query building logic, making it easier to construct complex queries in a readable and maintainable way.
Classes:
Name | Description |
---|---|
Mode |
Enum representing the different query modes. |
Methods:
Name | Description |
---|---|
set_count_mode |
Sets the count mode flag. |
set_delete_mode |
Sets the delete mode flag. |
set_equal |
Sets the equality filters for the query. |
set_greater_than |
Sets the greater than filters for the query. |
set_greater_than_or_equal |
Sets the greater than or equal filters for the query. |
set_insert_data |
Sets the data to be inserted in an insert query. |
set_less_than |
Sets the less than filters for the query. |
set_less_than_or_equal |
Sets the less than or equal filters for the query. |
set_not_equal |
Sets the non-equality filters for the query. |
set_select_fields |
Sets the selected fields for the query. |
set_update_data |
Sets the data to be updated in an update query. |
Attributes:
Name | Type | Description |
---|---|---|
count_mode |
bool
|
Gets the count mode flag. |
delete_mode |
bool
|
Gets the delete mode flag. |
equal |
tuple[tuple[str, Any], ...]
|
Gets the equality filters for the query. |
greater_than |
tuple[tuple[str, Any], ...]
|
Gets the greater than filters for the query. |
greater_than_or_equal |
tuple[tuple[str, Any], ...]
|
Gets the greater than or equal filters for the query. |
insert_data |
dict[str, Any] | None
|
Gets the data to be inserted in an insert query. |
less_than |
tuple[tuple[str, Any], ...]
|
Gets the less than filters for the query. |
less_than_or_equal |
tuple[tuple[str, Any], ...]
|
Gets the less than or equal filters for the query. |
mode |
Mode
|
Determines the query mode based on the current state of the QueryBuilder. |
not_equal |
tuple[tuple[str, Any], ...]
|
Gets the non-equality filters for the query. |
select_fields |
tuple[str, ...] | Literal['*']
|
Gets the selected fields for the query. |
update_data |
dict[str, Any] | None
|
Gets the data to be updated in an update query. |
Source code in supadantic/query_builder.py
32 33 34 35 36 37 38 39 40 41 42 43 |
|
count_mode
property
¶
count_mode: bool
Gets the count mode flag.
Returns:
Type | Description |
---|---|
bool
|
True if the query is in count mode, False otherwise. |
delete_mode
property
¶
delete_mode: bool
Gets the delete mode flag.
Returns:
Type | Description |
---|---|
bool
|
True if the query is in delete mode, False otherwise. |
equal
property
¶
equal: tuple[tuple[str, Any], ...]
Gets the equality filters for the query.
Returns:
Type | Description |
---|---|
tuple[tuple[str, Any], ...]
|
A tuple of tuples, where each inner tuple contains a field name and its desired value for equality filtering. |
greater_than
property
¶
greater_than: tuple[tuple[str, Any], ...]
Gets the greater than filters for the query.
Returns:
Type | Description |
---|---|
tuple[tuple[str, Any], ...]
|
A tuple of tuples, where each inner tuple contains a field name and its desired value for greater than filtering. |
greater_than_or_equal
property
¶
greater_than_or_equal: tuple[tuple[str, Any], ...]
Gets the greater than or equal filters for the query.
Returns:
Type | Description |
---|---|
tuple[tuple[str, Any], ...]
|
A tuple of tuples, where each inner tuple contains a field name and its desired value for greater than or equal filtering. |
insert_data
property
¶
insert_data: dict[str, Any] | None
Gets the data to be inserted in an insert query.
Returns:
Type | Description |
---|---|
dict[str, Any] | None
|
A dictionary representing the data to be inserted, or None if no data has been set for insertion. |
less_than
property
¶
less_than: tuple[tuple[str, Any], ...]
Gets the less than filters for the query.
Returns:
Type | Description |
---|---|
tuple[tuple[str, Any], ...]
|
A tuple of tuples, where each inner tuple contains a field name and its desired value for less than filtering. |
less_than_or_equal
property
¶
less_than_or_equal: tuple[tuple[str, Any], ...]
Gets the less than or equal filters for the query.
Returns:
Type | Description |
---|---|
tuple[tuple[str, Any], ...]
|
A tuple of tuples, where each inner tuple contains a field name and its desired value for less than or equal filtering. |
mode
property
¶
mode: Mode
Determines the query mode based on the current state of the QueryBuilder.
Returns:
Type | Description |
---|---|
Mode
|
The QueryBuilder.Mode enum representing the determined mode. |
not_equal
property
¶
not_equal: tuple[tuple[str, Any], ...]
Gets the non-equality filters for the query.
Returns:
Type | Description |
---|---|
tuple[tuple[str, Any], ...]
|
A tuple of tuples, where each inner tuple contains a field name and its desired value for non-equality filtering. |
select_fields
property
¶
select_fields: tuple[str, ...] | Literal['*']
Gets the selected fields for the query.
If no specific fields have been selected, this property returns "*"
,
which indicates that all fields should be selected.
Returns:
Type | Description |
---|---|
tuple[str, ...] | Literal[*]
|
A tuple of strings representing the selected fields,
or |
update_data
property
¶
update_data: dict[str, Any] | None
Gets the data to be updated in an update query.
Returns:
Type | Description |
---|---|
dict[str, Any] | None
|
A dictionary representing the data to be updated, or None if no data has been set for updating. |
Mode
¶
Bases: Enum
Enum representing the different query modes.
The Mode
enum defines the different types of queries that can be
built using the QueryBuilder
class.
set_count_mode
¶
set_count_mode(value: bool) -> None
Sets the count mode flag.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
bool
|
True to set the query to count mode, False otherwise. |
required |
Source code in supadantic/query_builder.py
328 329 330 331 332 333 334 335 336 |
|
set_delete_mode
¶
set_delete_mode(value: bool) -> None
Sets the delete mode flag.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
bool
|
True to set the query to delete mode, False otherwise. |
required |
Source code in supadantic/query_builder.py
318 319 320 321 322 323 324 325 326 |
|
set_equal
¶
set_equal(**kwargs) -> None
Sets the equality filters for the query.
This method accepts keyword arguments representing the equality filters and appends them to the existing set of equality filters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Key-value pairs where keys are field names and values are the desired values for equality. |
{}
|
Source code in supadantic/query_builder.py
218 219 220 221 222 223 224 225 226 227 228 229 |
|
set_greater_than
¶
set_greater_than(**kwargs) -> None
Sets the greater than filters for the query.
This method accepts keyword arguments representing the greater than filters and appends them to the existing set of greater than filters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Key-value pairs where keys are field names and values are the values to exclude. |
{}
|
Source code in supadantic/query_builder.py
257 258 259 260 261 262 263 264 265 266 267 268 |
|
set_greater_than_or_equal
¶
set_greater_than_or_equal(**kwargs) -> None
Sets the greater than or equal filters for the query.
This method accepts keyword arguments representing the greater than or equal filters and appends them to the existing set of greater than or equal filters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Key-value pairs where keys are field names and values are the values to exclude. |
{}
|
Source code in supadantic/query_builder.py
283 284 285 286 287 288 289 290 291 292 293 294 |
|
set_insert_data
¶
set_insert_data(data: dict[str, Any]) -> None
Sets the data to be inserted in an insert query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict[str, Any]
|
A dictionary representing the data to be inserted, where keys are field names and values are the corresponding values. |
required |
Source code in supadantic/query_builder.py
296 297 298 299 300 301 302 303 304 305 |
|
set_less_than
¶
set_less_than(**kwargs) -> None
Sets the less than filters for the query.
This method accepts keyword arguments representing the less than filters and appends them to the existing set of less than filters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Key-value pairs where keys are field names and values are the values to exclude. |
{}
|
Source code in supadantic/query_builder.py
270 271 272 273 274 275 276 277 278 279 280 281 |
|
set_less_than_or_equal
¶
set_less_than_or_equal(**kwargs) -> None
Sets the less than or equal filters for the query.
This method accepts keyword arguments representing the less than or equal filters and appends them to the existing set of less than or equal filters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Key-value pairs where keys are field names and values are the values to exclude. |
{}
|
Source code in supadantic/query_builder.py
244 245 246 247 248 249 250 251 252 253 254 255 |
|
set_not_equal
¶
set_not_equal(**kwargs) -> None
Sets the non-equality filters for the query.
This method accepts keyword arguments representing the non-equality filters and appends them to the existing set of non-equality filters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Key-value pairs where keys are field names and values are the values to exclude. |
{}
|
Source code in supadantic/query_builder.py
231 232 233 234 235 236 237 238 239 240 241 242 |
|
set_select_fields
¶
set_select_fields(fields: Iterable[str]) -> None
Sets the selected fields for the query.
This method appends the provided fields to the existing set of selected fields. It converts the input to a tuple.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fields
|
Iterable[str]
|
An iterable of strings representing the fields to select. |
required |
Source code in supadantic/query_builder.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
set_update_data
¶
set_update_data(data: dict[str, Any]) -> None
Sets the data to be updated in an update query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict[str, Any]
|
A dictionary representing the data to be updated, where keys are field names and values are the new values. |
required |
Source code in supadantic/query_builder.py
307 308 309 310 311 312 313 314 315 316 |
|