MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / __init__

Method __init__

lib/sqlalchemy/orm/util.py:1580–1612  ·  view source on GitHub ↗

r"""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.

(
        self, name: str, *exprs: _ColumnExpressionArgument[Any], **kw: Any
    )

Source from the content-addressed store, hash-verified

1578 exprs: List[_ColumnsClauseElement]
1579
1580 def __init__(
1581 self, name: str, *exprs: _ColumnExpressionArgument[Any], **kw: Any
1582 ):
1583 r"""Construct a new :class:`.Bundle`.
1584
1585 e.g.::
1586
1587 bn = Bundle("mybundle", MyClass.x, MyClass.y)
1588
1589 for row in session.query(bn).filter(bn.c.x == 5).filter(bn.c.y == 4):
1590 print(row.mybundle.x, row.mybundle.y)
1591
1592 :param name: name of the bundle.
1593 :param \*exprs: columns or SQL expressions comprising the bundle.
1594 :param single_entity=False: if True, rows for this :class:`.Bundle`
1595 can be returned as a "single entity" outside of any enclosing tuple
1596 in the same manner as a mapped entity.
1597
1598 """ # noqa: E501
1599 self.name = self._label = name
1600 coerced_exprs = [
1601 coercions.expect(
1602 roles.ColumnsClauseRole, expr, apply_propagate_attrs=self
1603 )
1604 for expr in exprs
1605 ]
1606 self.exprs = coerced_exprs
1607
1608 self.c = self.columns = ColumnCollection(
1609 (getattr(col, "key", col._label), col)
1610 for col in [e._annotations.get("bundle", e) for e in coerced_exprs]
1611 ).as_readonly()
1612 self.single_entity = kw.pop("single_entity", self.single_entity)
1613
1614 def _gen_cache_key(
1615 self, anon_map: anon_map, bindparams: List[BindParameter[Any]]

Callers 7

create_for_statementMethod · 0.45
_setup_for_orm_updateMethod · 0.45
create_for_statementMethod · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 4

ColumnCollectionClass · 0.85
as_readonlyMethod · 0.45
getMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected