Utilities
plateforme.core.database.utils
This module provides utility functions for working with database and queries within the Plateforme framework.
apply_filter
apply_filter(
query: Select[tuple[_T]],
criteria: Filter,
*,
entity: type[Any] | None = None,
refs: dict[str, InstrumentedAttribute[Any]]
| None = None,
raise_errors: bool = True,
) -> Select[tuple[_T]]
Apply the filter criteria to the given query.
Recursively builds and applies a filter to the provided query based on the given criteria. The function constructs a filter for the inferred or specified target entity, performs join operations on entity relationships specified in the criteria, and updates the query with the filter value assignments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
Select[tuple[_T]]
|
The query to build and update recursively with the filter assignments. |
required |
criteria
|
Filter
|
The filter dictionary containing the conditions to build the query with. |
required |
entity
|
type[Any] | None
|
The entity class used to build the filter query. When not
provided, the function attempts to infer the entity from the query
column descriptions. Defaults to |
None
|
refs
|
dict[str, InstrumentedAttribute[Any]] | None
|
The reference attributes mapping used to resolve the reference
values in the filter conditions. Defaults to |
None
|
raise_errors
|
bool
|
Whether to raise errors when invalid attributes or values
are found in the criteria. Defaults to |
True
|
Returns:
Type | Description |
---|---|
Select[tuple[_T]]
|
The updated query with the applied filters. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/utils.py
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
apply_reference
apply_reference(
query: Select[tuple[_T]],
keys: list[str],
*,
entity: type[Any] | None = None,
raise_errors: bool = True,
) -> tuple[
Select[tuple[_T]], dict[str, InstrumentedAttribute[Any]]
]
Apply and resolve the reference mapping against the given query.
Builds and applies the reference mapping to the provided query based on the given keys. The function constructs a mapping of reference attributes for the inferred or specified target entity, performs join operations on entity relationships specified in the keys, and returns the updated query with the reference attribute assignments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
Select[tuple[_T]]
|
The query to build and update recursively with the reference assignments. |
required |
keys
|
list[str]
|
The reference keys to resolve and apply to the query. |
required |
entity
|
type[Any] | None
|
The entity class used to build the reference query. When not
provided, the function attempts to infer the entity from the query
column descriptions. Defaults to |
None
|
raise_errors
|
bool
|
Whether to raise errors when invalid attributes or values
are found in the keys. Defaults to |
True
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/utils.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
apply_sort
apply_sort(
query: Select[tuple[_T]],
criteria: Sort,
*,
entity: type[Any] | None = None,
raise_errors: bool = True,
) -> Select[tuple[_T]]
Apply the sort criteria to the given query.
Builds and applies a sort to the provided query based on the given criteria. The function constructs a sort for the inferred or specified target entity, performs join operations on entity relationships specified in the criteria, and updates the query with the sort value assignments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
Select[tuple[_T]]
|
The query to build and update recursively with the sort assignments. |
required |
criteria
|
Sort
|
The sort list containing the criteria to build the query with. |
required |
entity
|
type[Any] | None
|
The entity class used to build the sort query. When not
provided, the function attempts to infer the entity from the query
column descriptions. Defaults to |
None
|
raise_errors
|
bool
|
Whether to raise errors when invalid attributes or values
are found in the criteria. Defaults to |
True
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/utils.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
|
build_options
build_options(
entity: type[Any],
*,
eager_load: set[str] | None = None,
raise_errors: bool = True,
) -> list[ExecutableOption]
Builds query options from the given configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity
|
type[Any]
|
The entity class to build the query options for. |
required |
eager_load
|
set[str] | None
|
The set of relationship attributes to eagerly load in the
executable operation. Defaults to |
None
|
raise_errors
|
bool
|
Whether to raise errors when invalid attributes or values
are found in the configuration. Defaults to |
True
|
Returns:
Type | Description |
---|---|
list[ExecutableOption]
|
The list of query options to apply to the executable operation. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/utils.py
build_query
build_query(
entity: type[_T],
selection: dict[str, Any],
__query: Select[tuple[_T]] | None = None,
*,
filter_criteria: Filter | None = None,
sort_criteria: Sort | None = None,
options: Sequence[ExecutableOption] | None = None,
raise_errors: bool = True,
) -> Select[tuple[_T]]
Builds a query for the given entity and selection.
Recursively builds a query for the given entity and selection dictionary, by performing a join operation on the entity relationships found in the selection and filtering the query based on the selection value assignments. Optionally, the function can apply filter and sort criteria to the query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity
|
type[_T]
|
The entity class to build the query for. |
required |
selection
|
dict[str, Any]
|
The selection dictionary containing the conditions to build the query with. |
required |
__query
|
Select[tuple[_T]] | None
|
The query to build and update recursively with the selection
assignments. Defaults to |
None
|
filter_criteria
|
Filter | None
|
The filter criteria to apply to the query.
Defaults to |
None
|
sort_criteria
|
Sort | None
|
The sort criteria to apply to the query.
Defaults to |
None
|
options
|
Sequence[ExecutableOption] | None
|
The options to apply to the query.
Defaults to |
None
|
raise_errors
|
bool
|
Whether to raise errors when invalid attributes or values
are found in the selection. Defaults to |
True
|
Returns:
Type | Description |
---|---|
Select[tuple[_T]]
|
The built query for the given entity and selection with the applied |
Select[tuple[_T]]
|
filter and sort criteria. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/utils.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
|