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_insert_data |
Sets the data to be inserted in an insert 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. |
insert_data |
dict[str, Any] | None
|
Gets the data to be inserted in an insert 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 |
|
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. |
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. |
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
224 225 226 227 228 229 230 231 232 |
|
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
214 215 216 217 218 219 220 221 222 |
|
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
166 167 168 169 170 171 172 173 174 175 176 177 |
|
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
192 193 194 195 196 197 198 199 200 201 |
|
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
179 180 181 182 183 184 185 186 187 188 189 190 |
|
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
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
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
203 204 205 206 207 208 209 210 211 212 |
|