class documentation

class BakedQuery(object):

View In Hierarchy

A builder object for .query.Query objects.
Class Method bakery Construct a new bakery.
Method add​_criteria Add a criteria function to this .BakedQuery.
Method for​_session Return a _baked.Result object for this .BakedQuery.
Method spoil Cancel any query caching that will occur on this BakedQuery object.
Method to​_query Return the _query.Query object for use as a subquery.
Method with​_criteria Add a criteria function to a .BakedQuery cloned from this one.
Method __add__ Undocumented
Method __call__ Undocumented
Method __iadd__ Undocumented
Method __init__ 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 .BakedQuery, taking into account the given .Session.
Method ​_retrieve​_baked​_query Undocumented
Method ​_update​_cache​_key Undocumented
Method ​_with​_lazyload​_options Cloning version of _add_lazyload_options.
Class Variable __slots__ Undocumented
Instance Variable ​_bakery Undocumented
Instance Variable ​_cache​_key Undocumented
Instance Variable ​_spoiled Undocumented
Instance Variable steps Undocumented
@classmethod
def bakery(cls, size=200, _size_alert=None):
Construct a new bakery.
Returns
an instance of .Bakery
def add_criteria(self, fn, *args):

Add a criteria function to this .BakedQuery.

This is equivalent to using the += operator to modify a .BakedQuery in-place.

def for_session(self, session):

Return a _baked.Result object for this .BakedQuery.

This is equivalent to calling the .BakedQuery as a Python callable, e.g. result = my_baked_query(session).

def spoil(self, full=False):

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.

Parameters
fullif False, only functions added to this .BakedQuery object subsequent to the spoil step will be non-cached; the state of the .BakedQuery up until this point will be pulled from the cache. If True, then the entire _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):

Return the _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 .BakedQuery. The parameter should normally be the _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 .Session, the .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())
)
Parameters
query​_or​_session

a _query.Query object or a class .Session object, that is assumed to be within the context of an enclosing .BakedQuery callable.

New in version 1.3.
def with_criteria(self, fn, *args):

Add a criteria function to a .BakedQuery cloned from this one.

This is equivalent to using the + operator to produce a new .BakedQuery with modifications.

def __add__(self, other):

Undocumented

def __call__(self, session):

Undocumented

def __iadd__(self, other):

Undocumented

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

Undocumented

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

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):

Undocumented

def _bake(self, session):

Undocumented

def _clone(self):

Undocumented

def _effective_key(self, session):

Return the key that actually goes into the cache dictionary for this .BakedQuery, taking into account the given .Session.

This basically means we also will include the session's query_class, as the actual _query.Query object is part of what's cached and needs to match the type of _query.Query that a later session will want to use.

def _retrieve_baked_query(self, session):

Undocumented

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

Undocumented

def _with_lazyload_options(self, options, effective_path, cache_path=None):
Cloning version of _add_lazyload_options.
__slots__: tuple[str, ...] =

Undocumented

_bakery =

Undocumented

_cache_key: tuple =

Undocumented

_spoiled: bool =

Undocumented

steps =

Undocumented