Compare commits
No commits in common. "76921a28417c4714f0edcdc135771d15b61b6cc9" and "6055c4ed3b3496c5ac777e1c3057dab01b279073" have entirely different histories.
76921a2841
...
6055c4ed3b
2 changed files with 5 additions and 7 deletions
|
|
@ -204,7 +204,7 @@ def age_pair(*, nullable: bool = False, **ka) -> tuple[Column, Column]:
|
||||||
return (date_col, acc_col)
|
return (date_col, acc_col)
|
||||||
|
|
||||||
|
|
||||||
def parent_children(keyword: str, /, *, lazy: str = 'selectin', **kwargs):
|
def parent_children(keyword: str, /, **kwargs):
|
||||||
"""
|
"""
|
||||||
Self-referential one-to-many relationship pair.
|
Self-referential one-to-many relationship pair.
|
||||||
Parent comes first, children come later.
|
Parent comes first, children come later.
|
||||||
|
|
@ -214,15 +214,13 @@ def parent_children(keyword: str, /, *, lazy: str = 'selectin', **kwargs):
|
||||||
|
|
||||||
Additional keyword arguments can be sourced with parent_ and child_ argument prefixes,
|
Additional keyword arguments can be sourced with parent_ and child_ argument prefixes,
|
||||||
obviously.
|
obviously.
|
||||||
|
|
||||||
CHANGED 0.5.0: the both relationship()s use lazy='selectin' attribute now by default.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
parent_kwargs = kwargs_prefix(kwargs, 'parent_')
|
parent_kwargs = kwargs_prefix(kwargs, 'parent_')
|
||||||
child_kwargs = kwargs_prefix(kwargs, 'child_')
|
child_kwargs = kwargs_prefix(kwargs, 'child_')
|
||||||
|
|
||||||
parent = Incomplete(relationship, Wanted(lambda o, n: o.__name__), back_populates=f'child_{keyword}s', lazy=lazy, **parent_kwargs)
|
parent = Incomplete(relationship, Wanted(lambda o, n: o.__name__), back_populates=f'child_{keyword}s', **parent_kwargs)
|
||||||
child = Incomplete(relationship, Wanted(lambda o, n: o.__name__), back_populates=f'parent_{keyword}', lazy=lazy, **child_kwargs)
|
child = Incomplete(relationship, Wanted(lambda o, n: o.__name__), back_populates=f'parent_{keyword}', **child_kwargs)
|
||||||
|
|
||||||
return parent, child
|
return parent, child
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,10 +45,10 @@ class SQLAlchemy:
|
||||||
def _ensure_engine(self):
|
def _ensure_engine(self):
|
||||||
if self.engine is None:
|
if self.engine is None:
|
||||||
raise RuntimeError('database is not connected')
|
raise RuntimeError('database is not connected')
|
||||||
async def begin(self, *, expire_on_commit = False, **kw) -> AsyncSession:
|
async def begin(self) -> AsyncSession:
|
||||||
self._ensure_engine()
|
self._ensure_engine()
|
||||||
## XXX is it accurate?
|
## XXX is it accurate?
|
||||||
s = AsyncSession(self.engine, expire_on_commit=expire_on_commit, **kw)
|
s = AsyncSession(self.engine)
|
||||||
self._sessions.append(s)
|
self._sessions.append(s)
|
||||||
return s
|
return s
|
||||||
async def __aenter__(self) -> AsyncSession:
|
async def __aenter__(self) -> AsyncSession:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue