示例#1
0
 async def create(cls: t.Type[C],
                  autoflush: bool = True,
                  autocommit: bool = False,
                  **values: t.Any) -> C:
     instance = cls(**values)  # type: ignore
     get_current_session().add(instance)
     if autoflush:
         await get_current_session().flush([instance])
     await instance.save(commit=autocommit)  # type: ignore
     return instance
示例#2
0
 async def delete(self, commit: bool = True) -> None:
     session = get_current_session()
     await session.delete(self)
     if commit:
         await session.commit()
示例#3
0
 async def save(self, commit: bool = True) -> None:
     session = get_current_session()
     session.add(self)  # type: ignore
     if commit:
         await session.commit()
示例#4
0
 def query(cls: t.Type[C]) -> SelectQuery[C]:
     return get_current_session().query(cls)
示例#5
0
 def __get__(self, obj: t.Optional[C], type: t.Type[C]) -> SelectQuery[C]:
     return get_current_session().query(type)
示例#6
0
 async def refresh(self) -> None:
     session = get_current_session()
     await session.refresh(self)