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
async def delete(self, commit: bool = True) -> None: session = get_current_session() await session.delete(self) if commit: await session.commit()
async def save(self, commit: bool = True) -> None: session = get_current_session() session.add(self) # type: ignore if commit: await session.commit()
def query(cls: t.Type[C]) -> SelectQuery[C]: return get_current_session().query(cls)
def __get__(self, obj: t.Optional[C], type: t.Type[C]) -> SelectQuery[C]: return get_current_session().query(type)
async def refresh(self) -> None: session = get_current_session() await session.refresh(self)