class documentation

class BakedQuery: (source)

View In Hierarchy

A builder object for :class:`.query.Query` objects.

Class Method bakery Construct a new bakery.
Method __add__ Undocumented
Method __call__ Undocumented
Method __iadd__ Undocumented
Method __init__ Undocumented
Method add_criteria Add a criteria function to this :class:`.BakedQuery`.
Method for_session Return a :class:`_baked.Result` object for this :class:`.BakedQuery`.
Method spoil Cancel any query caching that will occur on this BakedQuery object.
Method to_query Return the :class:`_query.Query` object for use as a subquery.
Method with_criteria Add a criteria function to a :class:`.BakedQuery` cloned from this one.
Class Variable __slots__ Undocumented
Instance Variable steps Undocumented
Method _add_lazyload_options Used by per-state lazy loaders to add options to the "lazy load" query from a parent query.
Method _as_query Undocumented
Method _bake Undocumented
Method _clone Undocumented
Method _effective_key Return the key that actually goes into the cache dictionary for this :class:`.BakedQuery`, taking into account the given :class:`.Session`.
Method _retrieve_baked_query Undocumented
Method _update_cache_key Undocumented
Method _with_lazyload_options Cloning version of _add_lazyload_options.
Instance Variable _bakery Undocumented
Instance Variable _cache_key Undocumented
Instance Variable _spoiled Undocumented
@classmethod
def bakery(cls, size=200, _size_alert=None): (source)

Construct a new bakery. :return: an instance of :class:`.Bakery`

def __add__(self, other): (source)

Undocumented

def __call__(self, session): (source)

Undocumented

def __iadd__(self, other): (source)

Undocumented

def __init__(self, bakery, initial_fn, args=()): (source)

Undocumented

def add_criteria(self, fn, *args): (source)

Add a criteria function to this :class:`.BakedQuery`. This is equivalent to using the ``+=`` operator to modify a :class:`.BakedQuery` in-place.

def for_session(self, session): (source)

Return a :class:`_baked.Result` object for this :class:`.BakedQuery`. This is equivalent to calling the :class:`.BakedQuery` as a Python callable, e.g. ``result = my_baked_query(session)``.

def spoil(self, full=False): (source)

Cancel any query caching that will occur on this BakedQuery object. The BakedQuery can continue to be used normally, however additional creational functions will not be cached; they will be called on every invocation. This is to support the case where a particular step in constructing a baked query disqualifies the query from being cacheable, such as a variant that relies upon some uncacheable value. :param full: if False, only functions added to this :class:`.BakedQuery` object subsequent to the spoil step will be non-cached; the state of the :class:`.BakedQuery` up until this point will be pulled from the cache. If True, then the entire :class:`_query.Query` object is built from scratch each time, with all creational functions being called on each invocation.

def to_query(self, query_or_session): (source)

Return the :class:`_query.Query` object for use as a subquery. This method should be used within the lambda callable being used to generate a step of an enclosing :class:`.BakedQuery`. The parameter should normally be the :class:`_query.Query` object that is passed to the lambda:: sub_bq = self.bakery(lambda s: s.query(User.name)) sub_bq += lambda q: q.filter( User.id == Address.user_id).correlate(Address) main_bq = self.bakery(lambda s: s.query(Address)) main_bq += lambda q: q.filter( sub_bq.to_query(q).exists()) In the case where the subquery is used in the first callable against a :class:`.Session`, the :class:`.Session` is also accepted:: sub_bq = self.bakery(lambda s: s.query(User.name)) sub_bq += lambda q: q.filter( User.id == Address.user_id).correlate(Address) main_bq = self.bakery( lambda s: s.query( Address.id, sub_bq.to_query(q).scalar_subquery()) ) :param query_or_session: a :class:`_query.Query` object or a class :class:`.Session` object, that is assumed to be within the context of an enclosing :class:`.BakedQuery` callable. .. versionadded:: 1.3

def with_criteria(self, fn, *args): (source)

Add a criteria function to a :class:`.BakedQuery` cloned from this one. This is equivalent to using the ``+`` operator to produce a new :class:`.BakedQuery` with modifications.

__slots__: tuple[str, ...] = (source)

Undocumented

Undocumented

def _add_lazyload_options(self, options, effective_path, cache_path=None): (source)

Used by per-state lazy loaders to add options to the "lazy load" query from a parent query. Creates a cache key based on given load path and query options; if a repeatable cache key cannot be generated, the query is "spoiled" so that it won't use caching.

def _as_query(self, session): (source)

Undocumented

def _bake(self, session): (source)

Undocumented

def _clone(self): (source)

Undocumented

def _effective_key(self, session): (source)

Return the key that actually goes into the cache dictionary for this :class:`.BakedQuery`, taking into account the given :class:`.Session`. This basically means we also will include the session's query_class, as the actual :class:`_query.Query` object is part of what's cached and needs to match the type of :class:`_query.Query` that a later session will want to use.

def _retrieve_baked_query(self, session): (source)

Undocumented

def _update_cache_key(self, fn, args=()): (source)

Undocumented

def _with_lazyload_options(self, options, effective_path, cache_path=None): (source)

Cloning version of _add_lazyload_options.

Undocumented

_cache_key: tuple = (source)

Undocumented

_spoiled: bool = (source)

Undocumented