lol
This commit is contained in:
@@ -32,6 +32,7 @@ from .result import _ensure_sync_result
|
||||
from .result import AsyncResult
|
||||
from .result import AsyncScalarResult
|
||||
from ... import util
|
||||
from ...orm import close_all_sessions as _sync_close_all_sessions
|
||||
from ...orm import object_session
|
||||
from ...orm import Session
|
||||
from ...orm import SessionTransaction
|
||||
@@ -509,7 +510,7 @@ class AsyncSession(ReversibleProxy[Session]):
|
||||
else:
|
||||
execution_options = _EXECUTE_OPTIONS
|
||||
|
||||
result = await greenlet_spawn(
|
||||
return await greenlet_spawn(
|
||||
self.sync_session.scalar,
|
||||
statement,
|
||||
params=params,
|
||||
@@ -517,7 +518,6 @@ class AsyncSession(ReversibleProxy[Session]):
|
||||
bind_arguments=bind_arguments,
|
||||
**kw,
|
||||
)
|
||||
return result
|
||||
|
||||
@overload
|
||||
async def scalars(
|
||||
@@ -588,7 +588,7 @@ class AsyncSession(ReversibleProxy[Session]):
|
||||
with_for_update: ForUpdateParameter = None,
|
||||
identity_token: Optional[Any] = None,
|
||||
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
|
||||
) -> Optional[_O]:
|
||||
) -> Union[_O, None]:
|
||||
"""Return an instance based on the given primary key identifier,
|
||||
or ``None`` if not found.
|
||||
|
||||
@@ -599,9 +599,7 @@ class AsyncSession(ReversibleProxy[Session]):
|
||||
|
||||
"""
|
||||
|
||||
# result_obj = self.sync_session.get(entity, ident)
|
||||
|
||||
result_obj = await greenlet_spawn(
|
||||
return await greenlet_spawn(
|
||||
cast("Callable[..., _O]", self.sync_session.get),
|
||||
entity,
|
||||
ident,
|
||||
@@ -609,8 +607,44 @@ class AsyncSession(ReversibleProxy[Session]):
|
||||
populate_existing=populate_existing,
|
||||
with_for_update=with_for_update,
|
||||
identity_token=identity_token,
|
||||
execution_options=execution_options,
|
||||
)
|
||||
|
||||
async def get_one(
|
||||
self,
|
||||
entity: _EntityBindKey[_O],
|
||||
ident: _PKIdentityArgument,
|
||||
*,
|
||||
options: Optional[Sequence[ORMOption]] = None,
|
||||
populate_existing: bool = False,
|
||||
with_for_update: ForUpdateParameter = None,
|
||||
identity_token: Optional[Any] = None,
|
||||
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
|
||||
) -> _O:
|
||||
"""Return an instance based on the given primary key identifier,
|
||||
or raise an exception if not found.
|
||||
|
||||
Raises ``sqlalchemy.orm.exc.NoResultFound`` if the query selects
|
||||
no rows.
|
||||
|
||||
..versionadded: 2.0.22
|
||||
|
||||
.. seealso::
|
||||
|
||||
:meth:`_orm.Session.get_one` - main documentation for get_one
|
||||
|
||||
"""
|
||||
|
||||
return await greenlet_spawn(
|
||||
cast("Callable[..., _O]", self.sync_session.get_one),
|
||||
entity,
|
||||
ident,
|
||||
options=options,
|
||||
populate_existing=populate_existing,
|
||||
with_for_update=with_for_update,
|
||||
identity_token=identity_token,
|
||||
execution_options=execution_options,
|
||||
)
|
||||
return result_obj
|
||||
|
||||
@overload
|
||||
async def stream(
|
||||
@@ -946,48 +980,70 @@ class AsyncSession(ReversibleProxy[Session]):
|
||||
For a general description of ORM begin nested, see
|
||||
:meth:`_orm.Session.begin_nested`.
|
||||
|
||||
.. seealso::
|
||||
|
||||
:ref:`aiosqlite_serializable` - special workarounds required
|
||||
with the SQLite asyncio driver in order for SAVEPOINT to work
|
||||
correctly.
|
||||
|
||||
"""
|
||||
|
||||
return AsyncSessionTransaction(self, nested=True)
|
||||
|
||||
async def rollback(self) -> None:
|
||||
"""Rollback the current transaction in progress."""
|
||||
"""Rollback the current transaction in progress.
|
||||
|
||||
.. seealso::
|
||||
|
||||
:meth:`_orm.Session.rollback` - main documentation for
|
||||
"rollback"
|
||||
"""
|
||||
await greenlet_spawn(self.sync_session.rollback)
|
||||
|
||||
async def commit(self) -> None:
|
||||
"""Commit the current transaction in progress."""
|
||||
"""Commit the current transaction in progress.
|
||||
|
||||
.. seealso::
|
||||
|
||||
:meth:`_orm.Session.commit` - main documentation for
|
||||
"commit"
|
||||
"""
|
||||
await greenlet_spawn(self.sync_session.commit)
|
||||
|
||||
async def close(self) -> None:
|
||||
"""Close out the transactional resources and ORM objects used by this
|
||||
:class:`_asyncio.AsyncSession`.
|
||||
|
||||
This expunges all ORM objects associated with this
|
||||
:class:`_asyncio.AsyncSession`, ends any transaction in progress and
|
||||
:term:`releases` any :class:`_asyncio.AsyncConnection` objects which
|
||||
this :class:`_asyncio.AsyncSession` itself has checked out from
|
||||
associated :class:`_asyncio.AsyncEngine` objects. The operation then
|
||||
leaves the :class:`_asyncio.AsyncSession` in a state which it may be
|
||||
used again.
|
||||
|
||||
.. tip::
|
||||
|
||||
The :meth:`_asyncio.AsyncSession.close` method **does not prevent
|
||||
the Session from being used again**. The
|
||||
:class:`_asyncio.AsyncSession` itself does not actually have a
|
||||
distinct "closed" state; it merely means the
|
||||
:class:`_asyncio.AsyncSession` will release all database
|
||||
connections and ORM objects.
|
||||
|
||||
|
||||
.. seealso::
|
||||
|
||||
:meth:`_orm.Session.close` - main documentation for
|
||||
"close"
|
||||
|
||||
:ref:`session_closing` - detail on the semantics of
|
||||
:meth:`_asyncio.AsyncSession.close`
|
||||
:meth:`_asyncio.AsyncSession.close` and
|
||||
:meth:`_asyncio.AsyncSession.reset`.
|
||||
|
||||
"""
|
||||
await greenlet_spawn(self.sync_session.close)
|
||||
|
||||
async def reset(self) -> None:
|
||||
"""Close out the transactional resources and ORM objects used by this
|
||||
:class:`_orm.Session`, resetting the session to its initial state.
|
||||
|
||||
.. versionadded:: 2.0.22
|
||||
|
||||
.. seealso::
|
||||
|
||||
:meth:`_orm.Session.reset` - main documentation for
|
||||
"reset"
|
||||
|
||||
:ref:`session_closing` - detail on the semantics of
|
||||
:meth:`_asyncio.AsyncSession.close` and
|
||||
:meth:`_asyncio.AsyncSession.reset`.
|
||||
|
||||
"""
|
||||
await greenlet_spawn(self.sync_session.reset)
|
||||
|
||||
async def aclose(self) -> None:
|
||||
"""A synonym for :meth:`_asyncio.AsyncSession.close`.
|
||||
|
||||
@@ -1008,9 +1064,15 @@ class AsyncSession(ReversibleProxy[Session]):
|
||||
await greenlet_spawn(self.sync_session.invalidate)
|
||||
|
||||
@classmethod
|
||||
async def close_all(self) -> None:
|
||||
@util.deprecated(
|
||||
"2.0",
|
||||
"The :meth:`.AsyncSession.close_all` method is deprecated and will be "
|
||||
"removed in a future release. Please refer to "
|
||||
":func:`_asyncio.close_all_sessions`.",
|
||||
)
|
||||
async def close_all(cls) -> None:
|
||||
"""Close all :class:`_asyncio.AsyncSession` sessions."""
|
||||
await greenlet_spawn(self.sync_session.close_all)
|
||||
await close_all_sessions()
|
||||
|
||||
async def __aenter__(self: _AS) -> _AS:
|
||||
return self
|
||||
@@ -1862,4 +1924,17 @@ def async_session(session: Session) -> Optional[AsyncSession]:
|
||||
return AsyncSession._retrieve_proxy_for_target(session, regenerate=False)
|
||||
|
||||
|
||||
async def close_all_sessions() -> None:
|
||||
"""Close all :class:`_asyncio.AsyncSession` sessions.
|
||||
|
||||
.. versionadded:: 2.0.23
|
||||
|
||||
.. seealso::
|
||||
|
||||
:func:`.session.close_all_sessions`
|
||||
|
||||
"""
|
||||
await greenlet_spawn(_sync_close_all_sessions)
|
||||
|
||||
|
||||
_instance_state._async_provider = async_session # type: ignore
|
||||
|
||||
Reference in New Issue
Block a user