API refactor
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-10-07 16:25:52 +09:00
parent 76d0d86211
commit 91c7e04474
1171 changed files with 81940 additions and 44117 deletions

View File

@@ -1,5 +1,5 @@
# ext/asyncio/scoping.py
# Copyright (C) 2005-2023 the SQLAlchemy authors and contributors
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
@@ -364,7 +364,7 @@ class async_scoped_session(Generic[_AS]):
object is entered::
async with async_session.begin():
# .. ORM transaction is begun
... # ORM transaction is begun
Note that database IO will not normally occur when the session-level
transaction is begun, as database transactions begin on an
@@ -536,8 +536,7 @@ class async_scoped_session(Generic[_AS]):
bind_arguments: Optional[_BindArguments] = None,
_parent_execute_state: Optional[Any] = None,
_add_event: Optional[Any] = None,
) -> Result[_T]:
...
) -> Result[_T]: ...
@overload
async def execute(
@@ -549,8 +548,7 @@ class async_scoped_session(Generic[_AS]):
bind_arguments: Optional[_BindArguments] = None,
_parent_execute_state: Optional[Any] = None,
_add_event: Optional[Any] = None,
) -> CursorResult[Any]:
...
) -> CursorResult[Any]: ...
@overload
async def execute(
@@ -562,8 +560,7 @@ class async_scoped_session(Generic[_AS]):
bind_arguments: Optional[_BindArguments] = None,
_parent_execute_state: Optional[Any] = None,
_add_event: Optional[Any] = None,
) -> Result[Any]:
...
) -> Result[Any]: ...
async def execute(
self,
@@ -811,28 +808,28 @@ class async_scoped_session(Generic[_AS]):
# construct async engines w/ async drivers
engines = {
'leader':create_async_engine("sqlite+aiosqlite:///leader.db"),
'other':create_async_engine("sqlite+aiosqlite:///other.db"),
'follower1':create_async_engine("sqlite+aiosqlite:///follower1.db"),
'follower2':create_async_engine("sqlite+aiosqlite:///follower2.db"),
"leader": create_async_engine("sqlite+aiosqlite:///leader.db"),
"other": create_async_engine("sqlite+aiosqlite:///other.db"),
"follower1": create_async_engine("sqlite+aiosqlite:///follower1.db"),
"follower2": create_async_engine("sqlite+aiosqlite:///follower2.db"),
}
class RoutingSession(Session):
def get_bind(self, mapper=None, clause=None, **kw):
# within get_bind(), return sync engines
if mapper and issubclass(mapper.class_, MyOtherClass):
return engines['other'].sync_engine
return engines["other"].sync_engine
elif self._flushing or isinstance(clause, (Update, Delete)):
return engines['leader'].sync_engine
return engines["leader"].sync_engine
else:
return engines[
random.choice(['follower1','follower2'])
random.choice(["follower1", "follower2"])
].sync_engine
# apply to AsyncSession using sync_session_class
AsyncSessionMaker = async_sessionmaker(
sync_session_class=RoutingSession
)
AsyncSessionMaker = async_sessionmaker(sync_session_class=RoutingSession)
The :meth:`_orm.Session.get_bind` method is called in a non-asyncio,
implicitly non-blocking context in the same manner as ORM event hooks
@@ -867,7 +864,7 @@ class async_scoped_session(Generic[_AS]):
This method retrieves the history for each instrumented
attribute on the instance and performs a comparison of the current
value to its previously committed value, if any.
value to its previously flushed or committed value, if any.
It is in effect a more expensive and accurate
version of checking for the given instance in the
@@ -1015,8 +1012,7 @@ class async_scoped_session(Generic[_AS]):
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
**kw: Any,
) -> Optional[_T]:
...
) -> Optional[_T]: ...
@overload
async def scalar(
@@ -1027,8 +1023,7 @@ class async_scoped_session(Generic[_AS]):
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
**kw: Any,
) -> Any:
...
) -> Any: ...
async def scalar(
self,
@@ -1070,8 +1065,7 @@ class async_scoped_session(Generic[_AS]):
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
**kw: Any,
) -> ScalarResult[_T]:
...
) -> ScalarResult[_T]: ...
@overload
async def scalars(
@@ -1082,8 +1076,7 @@ class async_scoped_session(Generic[_AS]):
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
**kw: Any,
) -> ScalarResult[Any]:
...
) -> ScalarResult[Any]: ...
async def scalars(
self,
@@ -1182,8 +1175,7 @@ class async_scoped_session(Generic[_AS]):
Proxied for the :class:`_asyncio.AsyncSession` class on
behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
Raises ``sqlalchemy.orm.exc.NoResultFound`` if the query selects
no rows.
Raises :class:`_exc.NoResultFound` if the query selects no rows.
..versionadded: 2.0.22
@@ -1213,8 +1205,7 @@ class async_scoped_session(Generic[_AS]):
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
**kw: Any,
) -> AsyncResult[_T]:
...
) -> AsyncResult[_T]: ...
@overload
async def stream(
@@ -1225,8 +1216,7 @@ class async_scoped_session(Generic[_AS]):
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
**kw: Any,
) -> AsyncResult[Any]:
...
) -> AsyncResult[Any]: ...
async def stream(
self,
@@ -1265,8 +1255,7 @@ class async_scoped_session(Generic[_AS]):
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
**kw: Any,
) -> AsyncScalarResult[_T]:
...
) -> AsyncScalarResult[_T]: ...
@overload
async def stream_scalars(
@@ -1277,8 +1266,7 @@ class async_scoped_session(Generic[_AS]):
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
**kw: Any,
) -> AsyncScalarResult[Any]:
...
) -> AsyncScalarResult[Any]: ...
async def stream_scalars(
self,