Invokes a :class:`.BakedQuery` against a :class:`.Session`. The :class:`_baked.Result` object is where the actual :class:`.query.Query` object gets created, or retrieved from the cache, against a target :class:`.Session`, and is then invoked for results.
| 300 | |
| 301 | |
| 302 | class Result: |
| 303 | """Invokes a :class:`.BakedQuery` against a :class:`.Session`. |
| 304 | |
| 305 | The :class:`_baked.Result` object is where the actual :class:`.query.Query` |
| 306 | object gets created, or retrieved from the cache, |
| 307 | against a target :class:`.Session`, and is then invoked for results. |
| 308 | |
| 309 | """ |
| 310 | |
| 311 | __slots__ = "bq", "session", "_params", "_post_criteria" |
| 312 | |
| 313 | def __init__(self, bq, session): |
| 314 | self.bq = bq |
| 315 | self.session = session |
| 316 | self._params = {} |
| 317 | self._post_criteria = [] |
| 318 | |
| 319 | def params(self, *args, **kw): |
| 320 | """Specify parameters to be replaced into the string SQL statement.""" |
| 321 | |
| 322 | if len(args) == 1: |
| 323 | kw.update(args[0]) |
| 324 | elif len(args) > 0: |
| 325 | raise sa_exc.ArgumentError( |
| 326 | "params() takes zero or one positional argument, " |
| 327 | "which is a dictionary." |
| 328 | ) |
| 329 | self._params.update(kw) |
| 330 | return self |
| 331 | |
| 332 | def _using_post_criteria(self, fns): |
| 333 | if fns: |
| 334 | self._post_criteria.extend(fns) |
| 335 | return self |
| 336 | |
| 337 | def with_post_criteria(self, fn): |
| 338 | """Add a criteria function that will be applied post-cache. |
| 339 | |
| 340 | This adds a function that will be run against the |
| 341 | :class:`_query.Query` object after it is retrieved from the |
| 342 | cache. This currently includes **only** the |
| 343 | :meth:`_query.Query.params` and :meth:`_query.Query.execution_options` |
| 344 | methods. |
| 345 | |
| 346 | .. warning:: :meth:`_baked.Result.with_post_criteria` |
| 347 | functions are applied |
| 348 | to the :class:`_query.Query` |
| 349 | object **after** the query's SQL statement |
| 350 | object has been retrieved from the cache. Only |
| 351 | :meth:`_query.Query.params` and |
| 352 | :meth:`_query.Query.execution_options` |
| 353 | methods should be used. |
| 354 | |
| 355 | """ |
| 356 | return self._using_post_criteria([fn]) |
| 357 | |
| 358 | def _as_query(self): |
| 359 | q = self.bq._as_query(self.session).params(self._params) |