class Bundle(ORMColumnsClauseRole[
Known subclasses: sqlalchemy.orm.descriptor_props.CompositeProperty.CompositeBundle
A grouping of SQL expressions that are returned by a :class:`.Query` under one namespace. The :class:`.Bundle` essentially allows nesting of the tuple-based results returned by a column-oriented :class:`_query.Query` object. It also is extensible via simple subclassing, where the primary capability to override is that of how the set of expressions should be returned, allowing post-processing as well as custom return types, without involving ORM identity-mapped classes. .. seealso:: :ref:`bundles`
Method | __clause |
Undocumented |
Method | __init__ |
Construct a new :class:`.Bundle`. |
Method | create |
Produce the "row processing" function for this :class:`.Bundle`. |
Method | label |
Provide a copy of this :class:`.Bundle` passing a new label. |
Class Variable | is |
True if this object is an instance of :class:`.AliasedClass`. |
Class Variable | is |
True if this object is an instance of :class:`.Bundle`. |
Class Variable | is |
True if this object is an instance of :class:`_expression.ClauseElement`. |
Class Variable | is |
True if this object is an instance of :class:`_orm.Mapper`. |
Instance Variable | c |
An alias for :attr:`.Bundle.columns`. |
Instance Variable | columns |
A namespace of SQL expressions referred to by this :class:`.Bundle`. |
Instance Variable | exprs |
Undocumented |
Instance Variable | name |
Undocumented |
Instance Variable | single |
If True, queries for a single Bundle will be returned as a single entity, rather than an element within a keyed tuple. |
Property | clauses |
Undocumented |
Property | entity |
Undocumented |
Property | entity |
Undocumented |
Property | mapper |
Undocumented |
Method | _clone |
clone this element |
Method | _gen |
return an optional cache key. |
Class Variable | _propagate |
Undocumented |
Instance Variable | _label |
Undocumented |
Inherited from ORMColumnsClauseRole
:
Class Variable | __slots__ |
Undocumented |
Class Variable | _role |
Undocumented |
Inherited from ColumnsClauseRole
(via ORMColumnsClauseRole
):
Property | _select |
Undocumented |
Inherited from AllowsLambdaRole
(via ORMColumnsClauseRole
, ColumnsClauseRole
):
Class Variable | allows |
Undocumented |
Inherited from UsesInspection
(via ORMColumnsClauseRole
, ColumnsClauseRole
, AllowsLambdaRole
):
Class Variable | uses |
Undocumented |
Class Variable | _post |
Undocumented |
Inherited from SupportsCloneAnnotations
(via ORMColumnsClauseRole
, ColumnsClauseRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, TypedColumnsClauseRole
):
Method | _annotate |
return a copy of this ClauseElement with annotations updated by the given dictionary. |
Method | _deannotate |
return a copy of this :class:`_expression.ClauseElement` with annotations removed. |
Method | _with |
return a copy of this ClauseElement with annotations replaced by the given dictionary. |
Class Variable | _clone |
Undocumented |
Inherited from SupportsWrappingAnnotations
(via ORMColumnsClauseRole
, ColumnsClauseRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, TypedColumnsClauseRole
, SupportsCloneAnnotations
):
Class Variable | _constructor |
Undocumented |
Inherited from SupportsAnnotations
(via ORMColumnsClauseRole
, ColumnsClauseRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, TypedColumnsClauseRole
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
):
Class Variable | proxy |
Undocumented |
Method | _gen |
Undocumented |
Class Variable | _is |
Undocumented |
Property | _annotations |
Undocumented |
Inherited from ExternallyTraversible
(via ORMColumnsClauseRole
, ColumnsClauseRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, TypedColumnsClauseRole
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
):
Method | get |
Return immediate child :class:`.visitors.HasTraverseInternals` elements of this :class:`.visitors.HasTraverseInternals`. |
Method | _copy |
Reassign internal elements to be clones of themselves. |
Inherited from HasTraverseInternals
(via ORMColumnsClauseRole
, ColumnsClauseRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, TypedColumnsClauseRole
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
, ExternallyTraversible
):
Class Variable | _traverse |
Undocumented |
Inherited from Visitable
(via ORMColumnsClauseRole
, ColumnsClauseRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, TypedColumnsClauseRole
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
, ExternallyTraversible
, HasTraverseInternals
):
Method | __class |
Undocumented |
Method | __init |
Undocumented |
Class Variable | __visit |
Undocumented |
Class Method | _generate |
Undocumented |
Method | _compiler |
Undocumented |
Class Variable | _original |
Undocumented |
Inherited from MemoizedHasCacheKey
(via ORMColumnsClauseRole
, ColumnsClauseRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, TypedColumnsClauseRole
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
, ExternallyTraversible
, HasTraverseInternals
, Visitable
):
Method | _generate |
return a cache key. |
Inherited from HasCacheKey
(via ORMColumnsClauseRole
, ColumnsClauseRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, TypedColumnsClauseRole
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
, ExternallyTraversible
, HasTraverseInternals
, Visitable
, MemoizedHasCacheKey
):
Class Variable | inherit |
Indicate if this :class:`.HasCacheKey` instance should make use of the cache key generation scheme used by its immediate superclass. |
Class Method | _generate |
generate cache key dispatcher for a new class. |
Class Method | _generate |
Undocumented |
Class Variable | _generated |
Undocumented |
Class Variable | _hierarchy |
private attribute which may be set to False to prevent the inherit_cache warning from being emitted for a hierarchy of subclasses. |
Class Variable | _is |
Undocumented |
Inherited from InspectionAttr
(via ORMColumnsClauseRole
, ColumnsClauseRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, TypedColumnsClauseRole
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
, ExternallyTraversible
, HasTraverseInternals
, Visitable
, MemoizedHasCacheKey
, HasCacheKey
, Inspectable
, SQLRole
):
Class Variable | is |
True if this object is a Python :term:`descriptor`. |
Class Variable | is |
True if this object is an instance of :class:`.InstanceState`. |
Class Variable | is |
True if this object is an instance of :class:`.MapperProperty`. |
Class Variable | is |
Return True if this object is an instance of :class:`_expression.Selectable`. |
Class Variable | _is |
True if this object is an internal proxy object. |
Construct a new :class:`.Bundle`. e.g.:: bn = Bundle("mybundle", MyClass.x, MyClass.y) for row in session.query(bn).filter( bn.c.x == 5).filter(bn.c.y == 4): print(row.mybundle.x, row.mybundle.y) :param name: name of the bundle. :param \*exprs: columns or SQL expressions comprising the bundle. :param single_entity=False: if True, rows for this :class:`.Bundle` can be returned as a "single entity" outside of any enclosing tuple in the same manner as a mapped entity.
Select[ Any]
, procs: Sequence[ Callable[ [ Row[ Any]], Any]]
, labels: Sequence[ str]
) -> Callable[ [ Row[ Any]], Any]
:
(source)
¶
Produce the "row processing" function for this :class:`.Bundle`. May be overridden by subclasses to provide custom behaviors when results are fetched. The method is passed the statement object and a set of "row processor" functions at query execution time; these processor functions when given a result row will return the individual attribute value, which can then be adapted into any kind of return data structure. The example below illustrates replacing the usual :class:`.Row` return structure with a straight Python dictionary:: from sqlalchemy.orm import Bundle class DictBundle(Bundle): def create_row_processor(self, query, procs, labels): 'Override create_row_processor to return values as dictionaries' def proc(row): return dict( zip(labels, (proc(row) for proc in procs)) ) return proc A result from the above :class:`_orm.Bundle` will return dictionary values:: bn = DictBundle('mybundle', MyClass.data1, MyClass.data2) for row in session.execute(select(bn)).where(bn.c.data1 == 'd1'): print(row.mybundle['data1'], row.mybundle['data2'])
A namespace of SQL expressions referred to by this :class:`.Bundle`. e.g.:: bn = Bundle("mybundle", MyClass.x, MyClass.y) q = sess.query(bn).filter(bn.c.x == 5) Nesting of bundles is also supported:: b1 = Bundle("b1", Bundle('b2', MyClass.a, MyClass.b), Bundle('b3', MyClass.x, MyClass.y) ) q = sess.query(b1).filter( b1.c.b2.c.a == 5).filter(b1.c.b3.c.y == 9) .. seealso:: :attr:`.Bundle.c`
If True, queries for a single Bundle will be returned as a single entity, rather than an element within a keyed tuple.
anon_map
, bindparams: List[ BindParameter[ Any]]
) -> Tuple[ Any, ...]
:
(source)
¶
return an optional cache key. The cache key is a tuple which can contain any series of objects that are hashable and also identifies this object uniquely within the presence of a larger SQL expression or statement, for the purposes of caching the resulting query. The cache key should be based on the SQL compiled structure that would ultimately be produced. That is, two structures that are composed in exactly the same way should produce the same cache key; any difference in the structures that would affect the SQL string or the type handlers should result in a different cache key. If a structure cannot produce a useful cache key, the NO_CACHE symbol should be added to the anon_map and the method should return None.