main commit
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-10-16 16:30:25 +09:00
parent 91c7e04474
commit 537e7b363f
1146 changed files with 45926 additions and 77196 deletions

View File

@@ -1,5 +1,5 @@
# orm/scoping.py
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
# Copyright (C) 2005-2023 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
@@ -86,7 +86,8 @@ class QueryPropertyDescriptor(Protocol):
"""
def __get__(self, instance: Any, owner: Type[_T]) -> Query[_T]: ...
def __get__(self, instance: Any, owner: Type[_T]) -> Query[_T]:
...
_O = TypeVar("_O", bound=object)
@@ -280,13 +281,11 @@ class scoped_session(Generic[_S]):
Session = scoped_session(sessionmaker())
class MyClass:
query: QueryPropertyDescriptor = Session.query_property()
# after mappers are defined
result = MyClass.query.filter(MyClass.name == "foo").all()
result = MyClass.query.filter(MyClass.name=='foo').all()
Produces instances of the session's configured query class by
default. To override and use a custom implementation, provide
@@ -535,12 +534,12 @@ class scoped_session(Generic[_S]):
behalf of the :class:`_orm.scoping.scoped_session` class.
This method provides for same "reset-only" behavior that the
:meth:`_orm.Session.close` method has provided historically, where the
:meth:_orm.Session.close method has provided historically, where the
state of the :class:`_orm.Session` is reset as though the object were
brand new, and ready to be used again.
This method may then be useful for :class:`_orm.Session` objects
The method may then be useful for :class:`_orm.Session` objects
which set :paramref:`_orm.Session.close_resets_only` to ``False``,
so that "reset only" behavior is still available.
so that "reset only" behavior is still available from this method.
.. versionadded:: 2.0.22
@@ -683,7 +682,8 @@ class scoped_session(Generic[_S]):
bind_arguments: Optional[_BindArguments] = None,
_parent_execute_state: Optional[Any] = None,
_add_event: Optional[Any] = None,
) -> Result[_T]: ...
) -> Result[_T]:
...
@overload
def execute(
@@ -695,7 +695,8 @@ class scoped_session(Generic[_S]):
bind_arguments: Optional[_BindArguments] = None,
_parent_execute_state: Optional[Any] = None,
_add_event: Optional[Any] = None,
) -> CursorResult[Any]: ...
) -> CursorResult[Any]:
...
@overload
def execute(
@@ -707,7 +708,8 @@ class scoped_session(Generic[_S]):
bind_arguments: Optional[_BindArguments] = None,
_parent_execute_state: Optional[Any] = None,
_add_event: Optional[Any] = None,
) -> Result[Any]: ...
) -> Result[Any]:
...
def execute(
self,
@@ -732,8 +734,9 @@ class scoped_session(Generic[_S]):
E.g.::
from sqlalchemy import select
result = session.execute(select(User).where(User.id == 5))
result = session.execute(
select(User).where(User.id == 5)
)
The API contract of :meth:`_orm.Session.execute` is similar to that
of :meth:`_engine.Connection.execute`, the :term:`2.0 style` version
@@ -963,7 +966,10 @@ class scoped_session(Generic[_S]):
some_object = session.get(VersionedFoo, (5, 10))
some_object = session.get(VersionedFoo, {"id": 5, "version_id": 10})
some_object = session.get(
VersionedFoo,
{"id": 5, "version_id": 10}
)
.. versionadded:: 1.4 Added :meth:`_orm.Session.get`, which is moved
from the now legacy :meth:`_orm.Query.get` method.
@@ -1086,7 +1092,8 @@ class scoped_session(Generic[_S]):
Proxied for the :class:`_orm.Session` class on
behalf of the :class:`_orm.scoping.scoped_session` class.
Raises :class:`_exc.NoResultFound` if the query selects no rows.
Raises ``sqlalchemy.orm.exc.NoResultFound`` if the query
selects no rows.
For a detailed documentation of the arguments see the
method :meth:`.Session.get`.
@@ -1225,7 +1232,7 @@ class scoped_session(Generic[_S]):
This method retrieves the history for each instrumented
attribute on the instance and performs a comparison of the current
value to its previously flushed or committed value, if any.
value to its previously committed value, if any.
It is in effect a more expensive and accurate
version of checking for the given instance in the
@@ -1567,12 +1574,14 @@ class scoped_session(Generic[_S]):
return self._proxied.merge(instance, load=load, options=options)
@overload
def query(self, _entity: _EntityType[_O]) -> Query[_O]: ...
def query(self, _entity: _EntityType[_O]) -> Query[_O]:
...
@overload
def query(
self, _colexpr: TypedColumnsClauseRole[_T]
) -> RowReturningQuery[Tuple[_T]]: ...
) -> RowReturningQuery[Tuple[_T]]:
...
# START OVERLOADED FUNCTIONS self.query RowReturningQuery 2-8
@@ -1582,12 +1591,14 @@ class scoped_session(Generic[_S]):
@overload
def query(
self, __ent0: _TCCA[_T0], __ent1: _TCCA[_T1]
) -> RowReturningQuery[Tuple[_T0, _T1]]: ...
) -> RowReturningQuery[Tuple[_T0, _T1]]:
...
@overload
def query(
self, __ent0: _TCCA[_T0], __ent1: _TCCA[_T1], __ent2: _TCCA[_T2]
) -> RowReturningQuery[Tuple[_T0, _T1, _T2]]: ...
) -> RowReturningQuery[Tuple[_T0, _T1, _T2]]:
...
@overload
def query(
@@ -1596,7 +1607,8 @@ class scoped_session(Generic[_S]):
__ent1: _TCCA[_T1],
__ent2: _TCCA[_T2],
__ent3: _TCCA[_T3],
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3]]: ...
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3]]:
...
@overload
def query(
@@ -1606,7 +1618,8 @@ class scoped_session(Generic[_S]):
__ent2: _TCCA[_T2],
__ent3: _TCCA[_T3],
__ent4: _TCCA[_T4],
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4]]: ...
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4]]:
...
@overload
def query(
@@ -1617,7 +1630,8 @@ class scoped_session(Generic[_S]):
__ent3: _TCCA[_T3],
__ent4: _TCCA[_T4],
__ent5: _TCCA[_T5],
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4, _T5]]: ...
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4, _T5]]:
...
@overload
def query(
@@ -1629,7 +1643,8 @@ class scoped_session(Generic[_S]):
__ent4: _TCCA[_T4],
__ent5: _TCCA[_T5],
__ent6: _TCCA[_T6],
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4, _T5, _T6]]: ...
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4, _T5, _T6]]:
...
@overload
def query(
@@ -1642,14 +1657,16 @@ class scoped_session(Generic[_S]):
__ent5: _TCCA[_T5],
__ent6: _TCCA[_T6],
__ent7: _TCCA[_T7],
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7]]: ...
) -> RowReturningQuery[Tuple[_T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7]]:
...
# END OVERLOADED FUNCTIONS self.query
@overload
def query(
self, *entities: _ColumnsClauseArgument[Any], **kwargs: Any
) -> Query[Any]: ...
) -> Query[Any]:
...
def query(
self, *entities: _ColumnsClauseArgument[Any], **kwargs: Any
@@ -1801,7 +1818,8 @@ class scoped_session(Generic[_S]):
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
**kw: Any,
) -> Optional[_T]: ...
) -> Optional[_T]:
...
@overload
def scalar(
@@ -1812,7 +1830,8 @@ class scoped_session(Generic[_S]):
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
**kw: Any,
) -> Any: ...
) -> Any:
...
def scalar(
self,
@@ -1854,7 +1873,8 @@ class scoped_session(Generic[_S]):
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
**kw: Any,
) -> ScalarResult[_T]: ...
) -> ScalarResult[_T]:
...
@overload
def scalars(
@@ -1865,7 +1885,8 @@ class scoped_session(Generic[_S]):
execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
bind_arguments: Optional[_BindArguments] = None,
**kw: Any,
) -> ScalarResult[Any]: ...
) -> ScalarResult[Any]:
...
def scalars(
self,