MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / UserStyleOne

Class UserStyleOne

test/typing/plain_files/ext/hybrid/hybrid_three.py:30–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28
29
30class UserStyleOne(Base):
31 __tablename__ = "user"
32 id: Mapped[int] = mapped_column(primary_key=True)
33 name: Mapped[str] = mapped_column(String(100))
34
35 accounts: Mapped[List[SavingsAccount]] = relationship()
36
37 @hybrid_property
38 def _balance_getter(self) -> Optional[Decimal]:
39 if self.accounts:
40 return self.accounts[0].balance
41 else:
42 return None
43
44 @_balance_getter.setter
45 def _balance_setter(self, value: Optional[Decimal]) -> None:
46 assert value is not None
47 if not self.accounts:
48 account = SavingsAccount(owner=self)
49 else:
50 account = self.accounts[0]
51 account.balance = value
52
53 @_balance_setter.expression
54 def balance(cls) -> SQLColumnExpression[Optional[Decimal]]:
55 return cast(
56 "SQLColumnExpression[Optional[Decimal]]", SavingsAccount.balance
57 )
58
59
60class UserStyleTwo(Base):

Callers

nothing calls this directly

Calls 3

mapped_columnFunction · 0.90
StringClass · 0.90
relationshipFunction · 0.90

Tested by

no test coverage detected