SQLAlchemy 2.1.0b2__cp313-cp313t-win_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. sqlalchemy/__init__.py +298 -0
  2. sqlalchemy/connectors/__init__.py +18 -0
  3. sqlalchemy/connectors/aioodbc.py +171 -0
  4. sqlalchemy/connectors/asyncio.py +476 -0
  5. sqlalchemy/connectors/pyodbc.py +250 -0
  6. sqlalchemy/dialects/__init__.py +62 -0
  7. sqlalchemy/dialects/_typing.py +30 -0
  8. sqlalchemy/dialects/mssql/__init__.py +89 -0
  9. sqlalchemy/dialects/mssql/aioodbc.py +63 -0
  10. sqlalchemy/dialects/mssql/base.py +4166 -0
  11. sqlalchemy/dialects/mssql/information_schema.py +285 -0
  12. sqlalchemy/dialects/mssql/json.py +140 -0
  13. sqlalchemy/dialects/mssql/mssqlpython.py +220 -0
  14. sqlalchemy/dialects/mssql/provision.py +196 -0
  15. sqlalchemy/dialects/mssql/pymssql.py +126 -0
  16. sqlalchemy/dialects/mssql/pyodbc.py +698 -0
  17. sqlalchemy/dialects/mysql/__init__.py +106 -0
  18. sqlalchemy/dialects/mysql/_mariadb_shim.py +312 -0
  19. sqlalchemy/dialects/mysql/aiomysql.py +226 -0
  20. sqlalchemy/dialects/mysql/asyncmy.py +214 -0
  21. sqlalchemy/dialects/mysql/base.py +3877 -0
  22. sqlalchemy/dialects/mysql/cymysql.py +106 -0
  23. sqlalchemy/dialects/mysql/dml.py +279 -0
  24. sqlalchemy/dialects/mysql/enumerated.py +277 -0
  25. sqlalchemy/dialects/mysql/expression.py +146 -0
  26. sqlalchemy/dialects/mysql/json.py +92 -0
  27. sqlalchemy/dialects/mysql/mariadb.py +67 -0
  28. sqlalchemy/dialects/mysql/mariadbconnector.py +330 -0
  29. sqlalchemy/dialects/mysql/mysqlconnector.py +296 -0
  30. sqlalchemy/dialects/mysql/mysqldb.py +312 -0
  31. sqlalchemy/dialects/mysql/provision.py +153 -0
  32. sqlalchemy/dialects/mysql/pymysql.py +157 -0
  33. sqlalchemy/dialects/mysql/pyodbc.py +156 -0
  34. sqlalchemy/dialects/mysql/reflection.py +724 -0
  35. sqlalchemy/dialects/mysql/reserved_words.py +570 -0
  36. sqlalchemy/dialects/mysql/types.py +845 -0
  37. sqlalchemy/dialects/oracle/__init__.py +85 -0
  38. sqlalchemy/dialects/oracle/base.py +3977 -0
  39. sqlalchemy/dialects/oracle/cx_oracle.py +1601 -0
  40. sqlalchemy/dialects/oracle/dictionary.py +507 -0
  41. sqlalchemy/dialects/oracle/json.py +158 -0
  42. sqlalchemy/dialects/oracle/oracledb.py +909 -0
  43. sqlalchemy/dialects/oracle/provision.py +288 -0
  44. sqlalchemy/dialects/oracle/types.py +367 -0
  45. sqlalchemy/dialects/oracle/vector.py +368 -0
  46. sqlalchemy/dialects/postgresql/__init__.py +171 -0
  47. sqlalchemy/dialects/postgresql/_psycopg_common.py +229 -0
  48. sqlalchemy/dialects/postgresql/array.py +534 -0
  49. sqlalchemy/dialects/postgresql/asyncpg.py +1323 -0
  50. sqlalchemy/dialects/postgresql/base.py +5789 -0
  51. sqlalchemy/dialects/postgresql/bitstring.py +327 -0
  52. sqlalchemy/dialects/postgresql/dml.py +360 -0
  53. sqlalchemy/dialects/postgresql/ext.py +593 -0
  54. sqlalchemy/dialects/postgresql/hstore.py +423 -0
  55. sqlalchemy/dialects/postgresql/json.py +408 -0
  56. sqlalchemy/dialects/postgresql/named_types.py +521 -0
  57. sqlalchemy/dialects/postgresql/operators.py +130 -0
  58. sqlalchemy/dialects/postgresql/pg8000.py +670 -0
  59. sqlalchemy/dialects/postgresql/pg_catalog.py +344 -0
  60. sqlalchemy/dialects/postgresql/provision.py +184 -0
  61. sqlalchemy/dialects/postgresql/psycopg.py +799 -0
  62. sqlalchemy/dialects/postgresql/psycopg2.py +860 -0
  63. sqlalchemy/dialects/postgresql/psycopg2cffi.py +61 -0
  64. sqlalchemy/dialects/postgresql/ranges.py +1002 -0
  65. sqlalchemy/dialects/postgresql/types.py +388 -0
  66. sqlalchemy/dialects/sqlite/__init__.py +57 -0
  67. sqlalchemy/dialects/sqlite/aiosqlite.py +321 -0
  68. sqlalchemy/dialects/sqlite/base.py +3063 -0
  69. sqlalchemy/dialects/sqlite/dml.py +279 -0
  70. sqlalchemy/dialects/sqlite/json.py +100 -0
  71. sqlalchemy/dialects/sqlite/provision.py +229 -0
  72. sqlalchemy/dialects/sqlite/pysqlcipher.py +161 -0
  73. sqlalchemy/dialects/sqlite/pysqlite.py +754 -0
  74. sqlalchemy/dialects/type_migration_guidelines.txt +145 -0
  75. sqlalchemy/engine/__init__.py +62 -0
  76. sqlalchemy/engine/_processors_cy.cp313t-win_arm64.pyd +0 -0
  77. sqlalchemy/engine/_processors_cy.py +92 -0
  78. sqlalchemy/engine/_result_cy.cp313t-win_arm64.pyd +0 -0
  79. sqlalchemy/engine/_result_cy.py +633 -0
  80. sqlalchemy/engine/_row_cy.cp313t-win_arm64.pyd +0 -0
  81. sqlalchemy/engine/_row_cy.py +232 -0
  82. sqlalchemy/engine/_util_cy.cp313t-win_arm64.pyd +0 -0
  83. sqlalchemy/engine/_util_cy.py +136 -0
  84. sqlalchemy/engine/base.py +3354 -0
  85. sqlalchemy/engine/characteristics.py +155 -0
  86. sqlalchemy/engine/create.py +877 -0
  87. sqlalchemy/engine/cursor.py +2421 -0
  88. sqlalchemy/engine/default.py +2402 -0
  89. sqlalchemy/engine/events.py +965 -0
  90. sqlalchemy/engine/interfaces.py +3495 -0
  91. sqlalchemy/engine/mock.py +134 -0
  92. sqlalchemy/engine/processors.py +82 -0
  93. sqlalchemy/engine/reflection.py +2100 -0
  94. sqlalchemy/engine/result.py +1966 -0
  95. sqlalchemy/engine/row.py +397 -0
  96. sqlalchemy/engine/strategies.py +16 -0
  97. sqlalchemy/engine/url.py +922 -0
  98. sqlalchemy/engine/util.py +156 -0
  99. sqlalchemy/event/__init__.py +26 -0
  100. sqlalchemy/event/api.py +220 -0
  101. sqlalchemy/event/attr.py +674 -0
  102. sqlalchemy/event/base.py +472 -0
  103. sqlalchemy/event/legacy.py +258 -0
  104. sqlalchemy/event/registry.py +390 -0
  105. sqlalchemy/events.py +17 -0
  106. sqlalchemy/exc.py +922 -0
  107. sqlalchemy/ext/__init__.py +11 -0
  108. sqlalchemy/ext/associationproxy.py +2072 -0
  109. sqlalchemy/ext/asyncio/__init__.py +29 -0
  110. sqlalchemy/ext/asyncio/base.py +281 -0
  111. sqlalchemy/ext/asyncio/engine.py +1487 -0
  112. sqlalchemy/ext/asyncio/exc.py +21 -0
  113. sqlalchemy/ext/asyncio/result.py +994 -0
  114. sqlalchemy/ext/asyncio/scoping.py +1679 -0
  115. sqlalchemy/ext/asyncio/session.py +2007 -0
  116. sqlalchemy/ext/automap.py +1701 -0
  117. sqlalchemy/ext/baked.py +559 -0
  118. sqlalchemy/ext/compiler.py +600 -0
  119. sqlalchemy/ext/declarative/__init__.py +65 -0
  120. sqlalchemy/ext/declarative/extensions.py +560 -0
  121. sqlalchemy/ext/horizontal_shard.py +481 -0
  122. sqlalchemy/ext/hybrid.py +1877 -0
  123. sqlalchemy/ext/indexable.py +364 -0
  124. sqlalchemy/ext/instrumentation.py +450 -0
  125. sqlalchemy/ext/mutable.py +1081 -0
  126. sqlalchemy/ext/orderinglist.py +439 -0
  127. sqlalchemy/ext/serializer.py +185 -0
  128. sqlalchemy/future/__init__.py +16 -0
  129. sqlalchemy/future/engine.py +15 -0
  130. sqlalchemy/inspection.py +174 -0
  131. sqlalchemy/log.py +283 -0
  132. sqlalchemy/orm/__init__.py +176 -0
  133. sqlalchemy/orm/_orm_constructors.py +2694 -0
  134. sqlalchemy/orm/_typing.py +179 -0
  135. sqlalchemy/orm/attributes.py +2868 -0
  136. sqlalchemy/orm/base.py +976 -0
  137. sqlalchemy/orm/bulk_persistence.py +2152 -0
  138. sqlalchemy/orm/clsregistry.py +582 -0
  139. sqlalchemy/orm/collections.py +1568 -0
  140. sqlalchemy/orm/context.py +3471 -0
  141. sqlalchemy/orm/decl_api.py +2280 -0
  142. sqlalchemy/orm/decl_base.py +2309 -0
  143. sqlalchemy/orm/dependency.py +1306 -0
  144. sqlalchemy/orm/descriptor_props.py +1183 -0
  145. sqlalchemy/orm/dynamic.py +307 -0
  146. sqlalchemy/orm/evaluator.py +379 -0
  147. sqlalchemy/orm/events.py +3386 -0
  148. sqlalchemy/orm/exc.py +237 -0
  149. sqlalchemy/orm/identity.py +302 -0
  150. sqlalchemy/orm/instrumentation.py +746 -0
  151. sqlalchemy/orm/interfaces.py +1589 -0
  152. sqlalchemy/orm/loading.py +1684 -0
  153. sqlalchemy/orm/mapped_collection.py +557 -0
  154. sqlalchemy/orm/mapper.py +4411 -0
  155. sqlalchemy/orm/path_registry.py +829 -0
  156. sqlalchemy/orm/persistence.py +1789 -0
  157. sqlalchemy/orm/properties.py +973 -0
  158. sqlalchemy/orm/query.py +3528 -0
  159. sqlalchemy/orm/relationships.py +3570 -0
  160. sqlalchemy/orm/scoping.py +2232 -0
  161. sqlalchemy/orm/session.py +5403 -0
  162. sqlalchemy/orm/state.py +1175 -0
  163. sqlalchemy/orm/state_changes.py +196 -0
  164. sqlalchemy/orm/strategies.py +3492 -0
  165. sqlalchemy/orm/strategy_options.py +2562 -0
  166. sqlalchemy/orm/sync.py +164 -0
  167. sqlalchemy/orm/unitofwork.py +798 -0
  168. sqlalchemy/orm/util.py +2438 -0
  169. sqlalchemy/orm/writeonly.py +694 -0
  170. sqlalchemy/pool/__init__.py +41 -0
  171. sqlalchemy/pool/base.py +1522 -0
  172. sqlalchemy/pool/events.py +375 -0
  173. sqlalchemy/pool/impl.py +582 -0
  174. sqlalchemy/py.typed +0 -0
  175. sqlalchemy/schema.py +74 -0
  176. sqlalchemy/sql/__init__.py +156 -0
  177. sqlalchemy/sql/_annotated_cols.py +397 -0
  178. sqlalchemy/sql/_dml_constructors.py +132 -0
  179. sqlalchemy/sql/_elements_constructors.py +2164 -0
  180. sqlalchemy/sql/_orm_types.py +20 -0
  181. sqlalchemy/sql/_selectable_constructors.py +840 -0
  182. sqlalchemy/sql/_typing.py +487 -0
  183. sqlalchemy/sql/_util_cy.cp313t-win_arm64.pyd +0 -0
  184. sqlalchemy/sql/_util_cy.py +127 -0
  185. sqlalchemy/sql/annotation.py +590 -0
  186. sqlalchemy/sql/base.py +2699 -0
  187. sqlalchemy/sql/cache_key.py +1066 -0
  188. sqlalchemy/sql/coercions.py +1373 -0
  189. sqlalchemy/sql/compiler.py +8327 -0
  190. sqlalchemy/sql/crud.py +1815 -0
  191. sqlalchemy/sql/ddl.py +1928 -0
  192. sqlalchemy/sql/default_comparator.py +654 -0
  193. sqlalchemy/sql/dml.py +1977 -0
  194. sqlalchemy/sql/elements.py +6033 -0
  195. sqlalchemy/sql/events.py +458 -0
  196. sqlalchemy/sql/expression.py +172 -0
  197. sqlalchemy/sql/functions.py +2305 -0
  198. sqlalchemy/sql/lambdas.py +1443 -0
  199. sqlalchemy/sql/naming.py +209 -0
  200. sqlalchemy/sql/operators.py +2897 -0
  201. sqlalchemy/sql/roles.py +332 -0
  202. sqlalchemy/sql/schema.py +6703 -0
  203. sqlalchemy/sql/selectable.py +7553 -0
  204. sqlalchemy/sql/sqltypes.py +4093 -0
  205. sqlalchemy/sql/traversals.py +1042 -0
  206. sqlalchemy/sql/type_api.py +2446 -0
  207. sqlalchemy/sql/util.py +1495 -0
  208. sqlalchemy/sql/visitors.py +1157 -0
  209. sqlalchemy/testing/__init__.py +96 -0
  210. sqlalchemy/testing/assertions.py +1007 -0
  211. sqlalchemy/testing/assertsql.py +519 -0
  212. sqlalchemy/testing/asyncio.py +128 -0
  213. sqlalchemy/testing/config.py +440 -0
  214. sqlalchemy/testing/engines.py +483 -0
  215. sqlalchemy/testing/entities.py +117 -0
  216. sqlalchemy/testing/exclusions.py +476 -0
  217. sqlalchemy/testing/fixtures/__init__.py +30 -0
  218. sqlalchemy/testing/fixtures/base.py +384 -0
  219. sqlalchemy/testing/fixtures/mypy.py +247 -0
  220. sqlalchemy/testing/fixtures/orm.py +227 -0
  221. sqlalchemy/testing/fixtures/sql.py +538 -0
  222. sqlalchemy/testing/pickleable.py +155 -0
  223. sqlalchemy/testing/plugin/__init__.py +6 -0
  224. sqlalchemy/testing/plugin/bootstrap.py +51 -0
  225. sqlalchemy/testing/plugin/plugin_base.py +828 -0
  226. sqlalchemy/testing/plugin/pytestplugin.py +892 -0
  227. sqlalchemy/testing/profiling.py +329 -0
  228. sqlalchemy/testing/provision.py +613 -0
  229. sqlalchemy/testing/requirements.py +1978 -0
  230. sqlalchemy/testing/schema.py +198 -0
  231. sqlalchemy/testing/suite/__init__.py +19 -0
  232. sqlalchemy/testing/suite/test_cte.py +237 -0
  233. sqlalchemy/testing/suite/test_ddl.py +420 -0
  234. sqlalchemy/testing/suite/test_dialect.py +776 -0
  235. sqlalchemy/testing/suite/test_insert.py +630 -0
  236. sqlalchemy/testing/suite/test_reflection.py +3557 -0
  237. sqlalchemy/testing/suite/test_results.py +660 -0
  238. sqlalchemy/testing/suite/test_rowcount.py +258 -0
  239. sqlalchemy/testing/suite/test_select.py +2112 -0
  240. sqlalchemy/testing/suite/test_sequence.py +317 -0
  241. sqlalchemy/testing/suite/test_table_via_select.py +686 -0
  242. sqlalchemy/testing/suite/test_types.py +2271 -0
  243. sqlalchemy/testing/suite/test_unicode_ddl.py +189 -0
  244. sqlalchemy/testing/suite/test_update_delete.py +139 -0
  245. sqlalchemy/testing/util.py +535 -0
  246. sqlalchemy/testing/warnings.py +52 -0
  247. sqlalchemy/types.py +76 -0
  248. sqlalchemy/util/__init__.py +158 -0
  249. sqlalchemy/util/_collections.py +688 -0
  250. sqlalchemy/util/_collections_cy.cp313t-win_arm64.pyd +0 -0
  251. sqlalchemy/util/_collections_cy.pxd +8 -0
  252. sqlalchemy/util/_collections_cy.py +516 -0
  253. sqlalchemy/util/_has_cython.py +46 -0
  254. sqlalchemy/util/_immutabledict_cy.cp313t-win_arm64.pyd +0 -0
  255. sqlalchemy/util/_immutabledict_cy.py +240 -0
  256. sqlalchemy/util/compat.py +299 -0
  257. sqlalchemy/util/concurrency.py +322 -0
  258. sqlalchemy/util/cython.py +79 -0
  259. sqlalchemy/util/deprecations.py +401 -0
  260. sqlalchemy/util/langhelpers.py +2320 -0
  261. sqlalchemy/util/preloaded.py +152 -0
  262. sqlalchemy/util/queue.py +304 -0
  263. sqlalchemy/util/tool_support.py +201 -0
  264. sqlalchemy/util/topological.py +120 -0
  265. sqlalchemy/util/typing.py +711 -0
  266. sqlalchemy-2.1.0b2.dist-info/METADATA +269 -0
  267. sqlalchemy-2.1.0b2.dist-info/RECORD +270 -0
  268. sqlalchemy-2.1.0b2.dist-info/WHEEL +5 -0
  269. sqlalchemy-2.1.0b2.dist-info/licenses/LICENSE +19 -0
  270. sqlalchemy-2.1.0b2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1679 @@
1
+ # ext/asyncio/scoping.py
2
+ # Copyright (C) 2005-2026 the SQLAlchemy authors and contributors
3
+ # <see AUTHORS file>
4
+ #
5
+ # This module is part of SQLAlchemy and is released under
6
+ # the MIT License: https://www.opensource.org/licenses/mit-license.php
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import Any
11
+ from typing import Callable
12
+ from typing import Generic
13
+ from typing import Iterable
14
+ from typing import Iterator
15
+ from typing import Optional
16
+ from typing import overload
17
+ from typing import Sequence
18
+ from typing import Tuple
19
+ from typing import Type
20
+ from typing import TYPE_CHECKING
21
+ from typing import TypeVar
22
+ from typing import Union
23
+
24
+ from .session import _AS
25
+ from .session import async_sessionmaker
26
+ from .session import AsyncSession
27
+ from ... import exc as sa_exc
28
+ from ... import util
29
+ from ...orm.session import Session
30
+ from ...util import create_proxy_methods
31
+ from ...util import ScopedRegistry
32
+ from ...util import warn
33
+ from ...util import warn_deprecated
34
+ from ...util.typing import Never
35
+ from ...util.typing import TupleAny
36
+ from ...util.typing import TypeVarTuple
37
+ from ...util.typing import Unpack
38
+
39
+ if TYPE_CHECKING:
40
+ from .engine import AsyncConnection
41
+ from .result import AsyncResult
42
+ from .result import AsyncScalarResult
43
+ from .session import AsyncSessionTransaction
44
+ from ...engine import Connection
45
+ from ...engine import Engine
46
+ from ...engine import Result
47
+ from ...engine import Row
48
+ from ...engine import RowMapping
49
+ from ...engine.interfaces import _CoreAnyExecuteParams
50
+ from ...engine.interfaces import CoreExecuteOptionsParameter
51
+ from ...engine.result import ScalarResult
52
+ from ...orm._typing import _IdentityKeyType
53
+ from ...orm._typing import _O
54
+ from ...orm._typing import OrmExecuteOptionsParameter
55
+ from ...orm.interfaces import ORMOption
56
+ from ...orm.session import _BindArguments
57
+ from ...orm.session import _EntityBindKey
58
+ from ...orm.session import _PKIdentityArgument
59
+ from ...orm.session import _SessionBind
60
+ from ...sql.base import Executable
61
+ from ...sql.elements import ClauseElement
62
+ from ...sql.selectable import ForUpdateParameter
63
+ from ...sql.selectable import TypedReturnsRows
64
+
65
+ _T = TypeVar("_T", bound=Any)
66
+ _Ts = TypeVarTuple("_Ts")
67
+
68
+
69
+ @create_proxy_methods(
70
+ AsyncSession,
71
+ ":class:`_asyncio.AsyncSession`",
72
+ ":class:`_asyncio.scoping.async_scoped_session`",
73
+ classmethods=["close_all", "object_session", "identity_key"],
74
+ methods=[
75
+ "__contains__",
76
+ "__iter__",
77
+ "aclose",
78
+ "add",
79
+ "add_all",
80
+ "begin",
81
+ "begin_nested",
82
+ "close",
83
+ "reset",
84
+ "commit",
85
+ "connection",
86
+ "delete",
87
+ "delete_all",
88
+ "execute",
89
+ "expire",
90
+ "expire_all",
91
+ "expunge",
92
+ "expunge_all",
93
+ "flush",
94
+ "get_bind",
95
+ "is_modified",
96
+ "invalidate",
97
+ "merge",
98
+ "merge_all",
99
+ "refresh",
100
+ "rollback",
101
+ "scalar",
102
+ "scalars",
103
+ "get",
104
+ "get_one",
105
+ "stream",
106
+ "stream_scalars",
107
+ ],
108
+ attributes=[
109
+ "bind",
110
+ "dirty",
111
+ "deleted",
112
+ "new",
113
+ "identity_map",
114
+ "is_active",
115
+ "autoflush",
116
+ "no_autoflush",
117
+ "info",
118
+ "execution_options",
119
+ ],
120
+ use_intermediate_variable=["get"],
121
+ )
122
+ class async_scoped_session(Generic[_AS]):
123
+ """Provides scoped management of :class:`.AsyncSession` objects.
124
+
125
+ See the section :ref:`asyncio_scoped_session` for usage details.
126
+
127
+ .. versionadded:: 1.4.19
128
+
129
+
130
+ """
131
+
132
+ _support_async = True
133
+
134
+ session_factory: async_sessionmaker[_AS]
135
+ """The `session_factory` provided to `__init__` is stored in this
136
+ attribute and may be accessed at a later time. This can be useful when
137
+ a new non-scoped :class:`.AsyncSession` is needed."""
138
+
139
+ registry: ScopedRegistry[_AS]
140
+
141
+ def __init__(
142
+ self,
143
+ session_factory: async_sessionmaker[_AS],
144
+ scopefunc: Callable[[], Any],
145
+ ):
146
+ """Construct a new :class:`_asyncio.async_scoped_session`.
147
+
148
+ :param session_factory: a factory to create new :class:`_asyncio.AsyncSession`
149
+ instances. This is usually, but not necessarily, an instance
150
+ of :class:`_asyncio.async_sessionmaker`.
151
+
152
+ :param scopefunc: function which defines
153
+ the current scope. A function such as ``asyncio.current_task``
154
+ may be useful here.
155
+
156
+ """ # noqa: E501
157
+
158
+ self.session_factory = session_factory
159
+ self.registry = ScopedRegistry(session_factory, scopefunc)
160
+
161
+ @property
162
+ def _proxied(self) -> _AS:
163
+ return self.registry()
164
+
165
+ def __call__(self, **kw: Any) -> _AS:
166
+ r"""Return the current :class:`.AsyncSession`, creating it
167
+ using the :attr:`.scoped_session.session_factory` if not present.
168
+
169
+ :param \**kw: Keyword arguments will be passed to the
170
+ :attr:`.scoped_session.session_factory` callable, if an existing
171
+ :class:`.AsyncSession` is not present. If the
172
+ :class:`.AsyncSession` is present
173
+ and keyword arguments have been passed,
174
+ :exc:`~sqlalchemy.exc.InvalidRequestError` is raised.
175
+
176
+ """
177
+ if kw:
178
+ if self.registry.has():
179
+ raise sa_exc.InvalidRequestError(
180
+ "Scoped session is already present; "
181
+ "no new arguments may be specified."
182
+ )
183
+ else:
184
+ sess = self.session_factory(**kw)
185
+ self.registry.set(sess)
186
+ else:
187
+ sess = self.registry()
188
+ if not self._support_async and sess._is_asyncio:
189
+ warn_deprecated(
190
+ "Using `scoped_session` with asyncio is deprecated and "
191
+ "will raise an error in a future version. "
192
+ "Please use `async_scoped_session` instead.",
193
+ "1.4.23",
194
+ )
195
+ return sess
196
+
197
+ def configure(self, **kwargs: Any) -> None:
198
+ """reconfigure the :class:`.sessionmaker` used by this
199
+ :class:`.scoped_session`.
200
+
201
+ See :meth:`.sessionmaker.configure`.
202
+
203
+ """
204
+
205
+ if self.registry.has():
206
+ warn(
207
+ "At least one scoped session is already present. "
208
+ " configure() can not affect sessions that have "
209
+ "already been created."
210
+ )
211
+
212
+ self.session_factory.configure(**kwargs)
213
+
214
+ async def remove(self) -> None:
215
+ """Dispose of the current :class:`.AsyncSession`, if present.
216
+
217
+ Different from scoped_session's remove method, this method would use
218
+ await to wait for the close method of AsyncSession.
219
+
220
+ """
221
+
222
+ if self.registry.has():
223
+ await self.registry().close()
224
+ self.registry.clear()
225
+
226
+ # START PROXY METHODS async_scoped_session
227
+
228
+ # code within this block is **programmatically,
229
+ # statically generated** by tools/generate_proxy_methods.py
230
+
231
+ def __contains__(self, instance: object) -> bool:
232
+ r"""Return True if the instance is associated with this session.
233
+
234
+ .. container:: class_bases
235
+
236
+ Proxied for the :class:`_asyncio.AsyncSession` class on
237
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
238
+
239
+ .. container:: class_bases
240
+
241
+ Proxied for the :class:`_orm.Session` class on
242
+ behalf of the :class:`_asyncio.AsyncSession` class.
243
+
244
+ The instance may be pending or persistent within the Session for a
245
+ result of True.
246
+
247
+
248
+
249
+ """ # noqa: E501
250
+
251
+ return self._proxied.__contains__(instance)
252
+
253
+ def __iter__(self) -> Iterator[object]:
254
+ r"""Iterate over all pending or persistent instances within this
255
+ Session.
256
+
257
+ .. container:: class_bases
258
+
259
+ Proxied for the :class:`_asyncio.AsyncSession` class on
260
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
261
+
262
+ .. container:: class_bases
263
+
264
+ Proxied for the :class:`_orm.Session` class on
265
+ behalf of the :class:`_asyncio.AsyncSession` class.
266
+
267
+
268
+
269
+ """ # noqa: E501
270
+
271
+ return self._proxied.__iter__()
272
+
273
+ async def aclose(self) -> None:
274
+ r"""A synonym for :meth:`_asyncio.AsyncSession.close`.
275
+
276
+ .. container:: class_bases
277
+
278
+ Proxied for the :class:`_asyncio.AsyncSession` class on
279
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
280
+
281
+ The :meth:`_asyncio.AsyncSession.aclose` name is specifically
282
+ to support the Python standard library ``@contextlib.aclosing``
283
+ context manager function.
284
+
285
+ .. versionadded:: 2.0.20
286
+
287
+
288
+ """ # noqa: E501
289
+
290
+ return await self._proxied.aclose()
291
+
292
+ def add(self, instance: object, *, _warn: bool = True) -> None:
293
+ r"""Place an object into this :class:`_orm.Session`.
294
+
295
+ .. container:: class_bases
296
+
297
+ Proxied for the :class:`_asyncio.AsyncSession` class on
298
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
299
+
300
+ .. container:: class_bases
301
+
302
+ Proxied for the :class:`_orm.Session` class on
303
+ behalf of the :class:`_asyncio.AsyncSession` class.
304
+
305
+ Objects that are in the :term:`transient` state when passed to the
306
+ :meth:`_orm.Session.add` method will move to the
307
+ :term:`pending` state, until the next flush, at which point they
308
+ will move to the :term:`persistent` state.
309
+
310
+ Objects that are in the :term:`detached` state when passed to the
311
+ :meth:`_orm.Session.add` method will move to the :term:`persistent`
312
+ state directly.
313
+
314
+ If the transaction used by the :class:`_orm.Session` is rolled back,
315
+ objects which were transient when they were passed to
316
+ :meth:`_orm.Session.add` will be moved back to the
317
+ :term:`transient` state, and will no longer be present within this
318
+ :class:`_orm.Session`.
319
+
320
+ .. seealso::
321
+
322
+ :meth:`_orm.Session.add_all`
323
+
324
+ :ref:`session_adding` - at :ref:`session_basics`
325
+
326
+
327
+
328
+ """ # noqa: E501
329
+
330
+ return self._proxied.add(instance, _warn=_warn)
331
+
332
+ def add_all(self, instances: Iterable[object]) -> None:
333
+ r"""Add the given collection of instances to this :class:`_orm.Session`.
334
+
335
+ .. container:: class_bases
336
+
337
+ Proxied for the :class:`_asyncio.AsyncSession` class on
338
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
339
+
340
+ .. container:: class_bases
341
+
342
+ Proxied for the :class:`_orm.Session` class on
343
+ behalf of the :class:`_asyncio.AsyncSession` class.
344
+
345
+ See the documentation for :meth:`_orm.Session.add` for a general
346
+ behavioral description.
347
+
348
+ .. seealso::
349
+
350
+ :meth:`_orm.Session.add`
351
+
352
+ :ref:`session_adding` - at :ref:`session_basics`
353
+
354
+
355
+
356
+ """ # noqa: E501
357
+
358
+ return self._proxied.add_all(instances)
359
+
360
+ def begin(self) -> AsyncSessionTransaction:
361
+ r"""Return an :class:`_asyncio.AsyncSessionTransaction` object.
362
+
363
+ .. container:: class_bases
364
+
365
+ Proxied for the :class:`_asyncio.AsyncSession` class on
366
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
367
+
368
+ The underlying :class:`_orm.Session` will perform the
369
+ "begin" action when the :class:`_asyncio.AsyncSessionTransaction`
370
+ object is entered::
371
+
372
+ async with async_session.begin():
373
+ ... # ORM transaction is begun
374
+
375
+ Note that database IO will not normally occur when the session-level
376
+ transaction is begun, as database transactions begin on an
377
+ on-demand basis. However, the begin block is async to accommodate
378
+ for a :meth:`_orm.SessionEvents.after_transaction_create`
379
+ event hook that may perform IO.
380
+
381
+ For a general description of ORM begin, see
382
+ :meth:`_orm.Session.begin`.
383
+
384
+
385
+ """ # noqa: E501
386
+
387
+ return self._proxied.begin()
388
+
389
+ def begin_nested(self) -> AsyncSessionTransaction:
390
+ r"""Return an :class:`_asyncio.AsyncSessionTransaction` object
391
+ which will begin a "nested" transaction, e.g. SAVEPOINT.
392
+
393
+ .. container:: class_bases
394
+
395
+ Proxied for the :class:`_asyncio.AsyncSession` class on
396
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
397
+
398
+ Behavior is the same as that of :meth:`_asyncio.AsyncSession.begin`.
399
+
400
+ For a general description of ORM begin nested, see
401
+ :meth:`_orm.Session.begin_nested`.
402
+
403
+ .. seealso::
404
+
405
+ :ref:`aiosqlite_serializable` - special workarounds required
406
+ with the SQLite asyncio driver in order for SAVEPOINT to work
407
+ correctly.
408
+
409
+
410
+ """ # noqa: E501
411
+
412
+ return self._proxied.begin_nested()
413
+
414
+ async def close(self) -> None:
415
+ r"""Close out the transactional resources and ORM objects used by this
416
+ :class:`_asyncio.AsyncSession`.
417
+
418
+ .. container:: class_bases
419
+
420
+ Proxied for the :class:`_asyncio.AsyncSession` class on
421
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
422
+
423
+ .. seealso::
424
+
425
+ :meth:`_orm.Session.close` - main documentation for
426
+ "close"
427
+
428
+ :ref:`session_closing` - detail on the semantics of
429
+ :meth:`_asyncio.AsyncSession.close` and
430
+ :meth:`_asyncio.AsyncSession.reset`.
431
+
432
+
433
+ """ # noqa: E501
434
+
435
+ return await self._proxied.close()
436
+
437
+ async def reset(self) -> None:
438
+ r"""Close out the transactional resources and ORM objects used by this
439
+ :class:`_orm.Session`, resetting the session to its initial state.
440
+
441
+ .. container:: class_bases
442
+
443
+ Proxied for the :class:`_asyncio.AsyncSession` class on
444
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
445
+
446
+ .. versionadded:: 2.0.22
447
+
448
+ .. seealso::
449
+
450
+ :meth:`_orm.Session.reset` - main documentation for
451
+ "reset"
452
+
453
+ :ref:`session_closing` - detail on the semantics of
454
+ :meth:`_asyncio.AsyncSession.close` and
455
+ :meth:`_asyncio.AsyncSession.reset`.
456
+
457
+
458
+ """ # noqa: E501
459
+
460
+ return await self._proxied.reset()
461
+
462
+ async def commit(self) -> None:
463
+ r"""Commit the current transaction in progress.
464
+
465
+ .. container:: class_bases
466
+
467
+ Proxied for the :class:`_asyncio.AsyncSession` class on
468
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
469
+
470
+ .. seealso::
471
+
472
+ :meth:`_orm.Session.commit` - main documentation for
473
+ "commit"
474
+
475
+ """ # noqa: E501
476
+
477
+ return await self._proxied.commit()
478
+
479
+ async def connection(
480
+ self,
481
+ bind_arguments: Optional[_BindArguments] = None,
482
+ execution_options: Optional[CoreExecuteOptionsParameter] = None,
483
+ **kw: Any,
484
+ ) -> AsyncConnection:
485
+ r"""Return a :class:`_asyncio.AsyncConnection` object corresponding to
486
+ this :class:`.Session` object's transactional state.
487
+
488
+ .. container:: class_bases
489
+
490
+ Proxied for the :class:`_asyncio.AsyncSession` class on
491
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
492
+
493
+ This method may also be used to establish execution options for the
494
+ database connection used by the current transaction.
495
+
496
+ .. versionadded:: 1.4.24 Added \**kw arguments which are passed
497
+ through to the underlying :meth:`_orm.Session.connection` method.
498
+
499
+ .. seealso::
500
+
501
+ :meth:`_orm.Session.connection` - main documentation for
502
+ "connection"
503
+
504
+
505
+ """ # noqa: E501
506
+
507
+ return await self._proxied.connection(
508
+ bind_arguments=bind_arguments,
509
+ execution_options=execution_options,
510
+ **kw,
511
+ )
512
+
513
+ async def delete(self, instance: object) -> None:
514
+ r"""Mark an instance as deleted.
515
+
516
+ .. container:: class_bases
517
+
518
+ Proxied for the :class:`_asyncio.AsyncSession` class on
519
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
520
+
521
+ The database delete operation occurs upon ``flush()``.
522
+
523
+ As this operation may need to cascade along unloaded relationships,
524
+ it is awaitable to allow for those queries to take place.
525
+
526
+ .. seealso::
527
+
528
+ :meth:`_orm.Session.delete` - main documentation for delete
529
+
530
+
531
+ """ # noqa: E501
532
+
533
+ return await self._proxied.delete(instance)
534
+
535
+ async def delete_all(self, instances: Iterable[object]) -> None:
536
+ r"""Calls :meth:`.AsyncSession.delete` on multiple instances.
537
+
538
+ .. container:: class_bases
539
+
540
+ Proxied for the :class:`_asyncio.AsyncSession` class on
541
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
542
+
543
+ .. seealso::
544
+
545
+ :meth:`_orm.Session.delete_all` - main documentation for delete_all
546
+
547
+
548
+ """ # noqa: E501
549
+
550
+ return await self._proxied.delete_all(instances)
551
+
552
+ @overload
553
+ async def execute(
554
+ self,
555
+ statement: TypedReturnsRows[Unpack[_Ts]],
556
+ params: Optional[_CoreAnyExecuteParams] = None,
557
+ *,
558
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
559
+ bind_arguments: Optional[_BindArguments] = None,
560
+ _parent_execute_state: Optional[Any] = None,
561
+ _add_event: Optional[Any] = None,
562
+ ) -> Result[Unpack[_Ts]]: ...
563
+
564
+ @overload
565
+ async def execute(
566
+ self,
567
+ statement: Executable,
568
+ params: Optional[_CoreAnyExecuteParams] = None,
569
+ *,
570
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
571
+ bind_arguments: Optional[_BindArguments] = None,
572
+ _parent_execute_state: Optional[Any] = None,
573
+ _add_event: Optional[Any] = None,
574
+ ) -> Result[Unpack[TupleAny]]: ...
575
+
576
+ async def execute(
577
+ self,
578
+ statement: Executable,
579
+ params: Optional[_CoreAnyExecuteParams] = None,
580
+ *,
581
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
582
+ bind_arguments: Optional[_BindArguments] = None,
583
+ **kw: Any,
584
+ ) -> Result[Unpack[TupleAny]]:
585
+ r"""Execute a statement and return a buffered
586
+ :class:`_engine.Result` object.
587
+
588
+ .. container:: class_bases
589
+
590
+ Proxied for the :class:`_asyncio.AsyncSession` class on
591
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
592
+
593
+ .. seealso::
594
+
595
+ :meth:`_orm.Session.execute` - main documentation for execute
596
+
597
+
598
+ """ # noqa: E501
599
+
600
+ return await self._proxied.execute(
601
+ statement,
602
+ params=params,
603
+ execution_options=execution_options,
604
+ bind_arguments=bind_arguments,
605
+ **kw,
606
+ )
607
+
608
+ def expire(
609
+ self, instance: object, attribute_names: Optional[Iterable[str]] = None
610
+ ) -> None:
611
+ r"""Expire the attributes on an instance.
612
+
613
+ .. container:: class_bases
614
+
615
+ Proxied for the :class:`_asyncio.AsyncSession` class on
616
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
617
+
618
+ .. container:: class_bases
619
+
620
+ Proxied for the :class:`_orm.Session` class on
621
+ behalf of the :class:`_asyncio.AsyncSession` class.
622
+
623
+ Marks the attributes of an instance as out of date. When an expired
624
+ attribute is next accessed, a query will be issued to the
625
+ :class:`.Session` object's current transactional context in order to
626
+ load all expired attributes for the given instance. Note that
627
+ a highly isolated transaction will return the same values as were
628
+ previously read in that same transaction, regardless of changes
629
+ in database state outside of that transaction.
630
+
631
+ To expire all objects in the :class:`.Session` simultaneously,
632
+ use :meth:`Session.expire_all`.
633
+
634
+ The :class:`.Session` object's default behavior is to
635
+ expire all state whenever the :meth:`Session.rollback`
636
+ or :meth:`Session.commit` methods are called, so that new
637
+ state can be loaded for the new transaction. For this reason,
638
+ calling :meth:`Session.expire` only makes sense for the specific
639
+ case that a non-ORM SQL statement was emitted in the current
640
+ transaction.
641
+
642
+ :param instance: The instance to be refreshed.
643
+ :param attribute_names: optional list of string attribute names
644
+ indicating a subset of attributes to be expired.
645
+
646
+ .. seealso::
647
+
648
+ :ref:`session_expire` - introductory material
649
+
650
+ :meth:`.Session.expire`
651
+
652
+ :meth:`.Session.refresh`
653
+
654
+ :meth:`_orm.Query.populate_existing`
655
+
656
+
657
+
658
+ """ # noqa: E501
659
+
660
+ return self._proxied.expire(instance, attribute_names=attribute_names)
661
+
662
+ def expire_all(self) -> None:
663
+ r"""Expires all persistent instances within this Session.
664
+
665
+ .. container:: class_bases
666
+
667
+ Proxied for the :class:`_asyncio.AsyncSession` class on
668
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
669
+
670
+ .. container:: class_bases
671
+
672
+ Proxied for the :class:`_orm.Session` class on
673
+ behalf of the :class:`_asyncio.AsyncSession` class.
674
+
675
+ When any attributes on a persistent instance is next accessed,
676
+ a query will be issued using the
677
+ :class:`.Session` object's current transactional context in order to
678
+ load all expired attributes for the given instance. Note that
679
+ a highly isolated transaction will return the same values as were
680
+ previously read in that same transaction, regardless of changes
681
+ in database state outside of that transaction.
682
+
683
+ To expire individual objects and individual attributes
684
+ on those objects, use :meth:`Session.expire`.
685
+
686
+ The :class:`.Session` object's default behavior is to
687
+ expire all state whenever the :meth:`Session.rollback`
688
+ or :meth:`Session.commit` methods are called, so that new
689
+ state can be loaded for the new transaction. For this reason,
690
+ calling :meth:`Session.expire_all` is not usually needed,
691
+ assuming the transaction is isolated.
692
+
693
+ .. seealso::
694
+
695
+ :ref:`session_expire` - introductory material
696
+
697
+ :meth:`.Session.expire`
698
+
699
+ :meth:`.Session.refresh`
700
+
701
+ :meth:`_orm.Query.populate_existing`
702
+
703
+
704
+
705
+ """ # noqa: E501
706
+
707
+ return self._proxied.expire_all()
708
+
709
+ def expunge(self, instance: object) -> None:
710
+ r"""Remove the `instance` from this ``Session``.
711
+
712
+ .. container:: class_bases
713
+
714
+ Proxied for the :class:`_asyncio.AsyncSession` class on
715
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
716
+
717
+ .. container:: class_bases
718
+
719
+ Proxied for the :class:`_orm.Session` class on
720
+ behalf of the :class:`_asyncio.AsyncSession` class.
721
+
722
+ This will free all internal references to the instance. Cascading
723
+ will be applied according to the *expunge* cascade rule.
724
+
725
+
726
+
727
+ """ # noqa: E501
728
+
729
+ return self._proxied.expunge(instance)
730
+
731
+ def expunge_all(self) -> None:
732
+ r"""Remove all object instances from this ``Session``.
733
+
734
+ .. container:: class_bases
735
+
736
+ Proxied for the :class:`_asyncio.AsyncSession` class on
737
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
738
+
739
+ .. container:: class_bases
740
+
741
+ Proxied for the :class:`_orm.Session` class on
742
+ behalf of the :class:`_asyncio.AsyncSession` class.
743
+
744
+ This is equivalent to calling ``expunge(obj)`` on all objects in this
745
+ ``Session``.
746
+
747
+
748
+
749
+ """ # noqa: E501
750
+
751
+ return self._proxied.expunge_all()
752
+
753
+ async def flush(self, objects: Optional[Sequence[Any]] = None) -> None:
754
+ r"""Flush all the object changes to the database.
755
+
756
+ .. container:: class_bases
757
+
758
+ Proxied for the :class:`_asyncio.AsyncSession` class on
759
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
760
+
761
+ .. seealso::
762
+
763
+ :meth:`_orm.Session.flush` - main documentation for flush
764
+
765
+
766
+ """ # noqa: E501
767
+
768
+ return await self._proxied.flush(objects=objects)
769
+
770
+ def get_bind(
771
+ self,
772
+ mapper: Optional[_EntityBindKey[_O]] = None,
773
+ clause: Optional[ClauseElement] = None,
774
+ bind: Optional[_SessionBind] = None,
775
+ **kw: Any,
776
+ ) -> Union[Engine, Connection]:
777
+ r"""Return a "bind" to which the synchronous proxied :class:`_orm.Session`
778
+ is bound.
779
+
780
+ .. container:: class_bases
781
+
782
+ Proxied for the :class:`_asyncio.AsyncSession` class on
783
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
784
+
785
+ Unlike the :meth:`_orm.Session.get_bind` method, this method is
786
+ currently **not** used by this :class:`.AsyncSession` in any way
787
+ in order to resolve engines for requests.
788
+
789
+ .. note::
790
+
791
+ This method proxies directly to the :meth:`_orm.Session.get_bind`
792
+ method, however is currently **not** useful as an override target,
793
+ in contrast to that of the :meth:`_orm.Session.get_bind` method.
794
+ The example below illustrates how to implement custom
795
+ :meth:`_orm.Session.get_bind` schemes that work with
796
+ :class:`.AsyncSession` and :class:`.AsyncEngine`.
797
+
798
+ The pattern introduced at :ref:`session_custom_partitioning`
799
+ illustrates how to apply a custom bind-lookup scheme to a
800
+ :class:`_orm.Session` given a set of :class:`_engine.Engine` objects.
801
+ To apply a corresponding :meth:`_orm.Session.get_bind` implementation
802
+ for use with a :class:`.AsyncSession` and :class:`.AsyncEngine`
803
+ objects, continue to subclass :class:`_orm.Session` and apply it to
804
+ :class:`.AsyncSession` using
805
+ :paramref:`.AsyncSession.sync_session_class`. The inner method must
806
+ continue to return :class:`_engine.Engine` instances, which can be
807
+ acquired from a :class:`_asyncio.AsyncEngine` using the
808
+ :attr:`_asyncio.AsyncEngine.sync_engine` attribute::
809
+
810
+ # using example from "Custom Vertical Partitioning"
811
+
812
+
813
+ import random
814
+
815
+ from sqlalchemy.ext.asyncio import AsyncSession
816
+ from sqlalchemy.ext.asyncio import create_async_engine
817
+ from sqlalchemy.ext.asyncio import async_sessionmaker
818
+ from sqlalchemy.orm import Session
819
+
820
+ # construct async engines w/ async drivers
821
+ engines = {
822
+ "leader": create_async_engine("sqlite+aiosqlite:///leader.db"),
823
+ "other": create_async_engine("sqlite+aiosqlite:///other.db"),
824
+ "follower1": create_async_engine("sqlite+aiosqlite:///follower1.db"),
825
+ "follower2": create_async_engine("sqlite+aiosqlite:///follower2.db"),
826
+ }
827
+
828
+
829
+ class RoutingSession(Session):
830
+ def get_bind(self, mapper=None, clause=None, **kw):
831
+ # within get_bind(), return sync engines
832
+ if mapper and issubclass(mapper.class_, MyOtherClass):
833
+ return engines["other"].sync_engine
834
+ elif self._flushing or isinstance(clause, (Update, Delete)):
835
+ return engines["leader"].sync_engine
836
+ else:
837
+ return engines[
838
+ random.choice(["follower1", "follower2"])
839
+ ].sync_engine
840
+
841
+
842
+ # apply to AsyncSession using sync_session_class
843
+ AsyncSessionMaker = async_sessionmaker(sync_session_class=RoutingSession)
844
+
845
+ The :meth:`_orm.Session.get_bind` method is called in a non-asyncio,
846
+ implicitly non-blocking context in the same manner as ORM event hooks
847
+ and functions that are invoked via :meth:`.AsyncSession.run_sync`, so
848
+ routines that wish to run SQL commands inside of
849
+ :meth:`_orm.Session.get_bind` can continue to do so using
850
+ blocking-style code, which will be translated to implicitly async calls
851
+ at the point of invoking IO on the database drivers.
852
+
853
+
854
+ """ # noqa: E501
855
+
856
+ return self._proxied.get_bind(
857
+ mapper=mapper, clause=clause, bind=bind, **kw
858
+ )
859
+
860
+ def is_modified(
861
+ self, instance: object, include_collections: bool = True
862
+ ) -> bool:
863
+ r"""Return ``True`` if the given instance has locally
864
+ modified attributes.
865
+
866
+ .. container:: class_bases
867
+
868
+ Proxied for the :class:`_asyncio.AsyncSession` class on
869
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
870
+
871
+ .. container:: class_bases
872
+
873
+ Proxied for the :class:`_orm.Session` class on
874
+ behalf of the :class:`_asyncio.AsyncSession` class.
875
+
876
+ This method retrieves the history for each instrumented
877
+ attribute on the instance and performs a comparison of the current
878
+ value to its previously flushed or committed value, if any.
879
+
880
+ It is in effect a more expensive and accurate
881
+ version of checking for the given instance in the
882
+ :attr:`.Session.dirty` collection; a full test for
883
+ each attribute's net "dirty" status is performed.
884
+
885
+ E.g.::
886
+
887
+ return session.is_modified(someobject)
888
+
889
+ A few caveats to this method apply:
890
+
891
+ * Instances present in the :attr:`.Session.dirty` collection may
892
+ report ``False`` when tested with this method. This is because
893
+ the object may have received change events via attribute mutation,
894
+ thus placing it in :attr:`.Session.dirty`, but ultimately the state
895
+ is the same as that loaded from the database, resulting in no net
896
+ change here.
897
+ * Scalar attributes may not have recorded the previously set
898
+ value when a new value was applied, if the attribute was not loaded,
899
+ or was expired, at the time the new value was received - in these
900
+ cases, the attribute is assumed to have a change, even if there is
901
+ ultimately no net change against its database value. SQLAlchemy in
902
+ most cases does not need the "old" value when a set event occurs, so
903
+ it skips the expense of a SQL call if the old value isn't present,
904
+ based on the assumption that an UPDATE of the scalar value is
905
+ usually needed, and in those few cases where it isn't, is less
906
+ expensive on average than issuing a defensive SELECT.
907
+
908
+ The "old" value is fetched unconditionally upon set only if the
909
+ attribute container has the ``active_history`` flag set to ``True``.
910
+ This flag is set typically for primary key attributes and scalar
911
+ object references that are not a simple many-to-one. To set this
912
+ flag for any arbitrary mapped column, use the ``active_history``
913
+ argument with :func:`.column_property`.
914
+
915
+ :param instance: mapped instance to be tested for pending changes.
916
+ :param include_collections: Indicates if multivalued collections
917
+ should be included in the operation. Setting this to ``False`` is a
918
+ way to detect only local-column based properties (i.e. scalar columns
919
+ or many-to-one foreign keys) that would result in an UPDATE for this
920
+ instance upon flush.
921
+
922
+
923
+
924
+ """ # noqa: E501
925
+
926
+ return self._proxied.is_modified(
927
+ instance, include_collections=include_collections
928
+ )
929
+
930
+ async def invalidate(self) -> None:
931
+ r"""Close this Session, using connection invalidation.
932
+
933
+ .. container:: class_bases
934
+
935
+ Proxied for the :class:`_asyncio.AsyncSession` class on
936
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
937
+
938
+ For a complete description, see :meth:`_orm.Session.invalidate`.
939
+
940
+ """ # noqa: E501
941
+
942
+ return await self._proxied.invalidate()
943
+
944
+ async def merge(
945
+ self,
946
+ instance: _O,
947
+ *,
948
+ load: bool = True,
949
+ options: Optional[Sequence[ORMOption]] = None,
950
+ ) -> _O:
951
+ r"""Copy the state of a given instance into a corresponding instance
952
+ within this :class:`_asyncio.AsyncSession`.
953
+
954
+ .. container:: class_bases
955
+
956
+ Proxied for the :class:`_asyncio.AsyncSession` class on
957
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
958
+
959
+ .. seealso::
960
+
961
+ :meth:`_orm.Session.merge` - main documentation for merge
962
+
963
+
964
+ """ # noqa: E501
965
+
966
+ return await self._proxied.merge(instance, load=load, options=options)
967
+
968
+ async def merge_all(
969
+ self,
970
+ instances: Iterable[_O],
971
+ *,
972
+ load: bool = True,
973
+ options: Optional[Sequence[ORMOption]] = None,
974
+ ) -> Sequence[_O]:
975
+ r"""Calls :meth:`.AsyncSession.merge` on multiple instances.
976
+
977
+ .. container:: class_bases
978
+
979
+ Proxied for the :class:`_asyncio.AsyncSession` class on
980
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
981
+
982
+ .. seealso::
983
+
984
+ :meth:`_orm.Session.merge_all` - main documentation for merge_all
985
+
986
+
987
+ """ # noqa: E501
988
+
989
+ return await self._proxied.merge_all(
990
+ instances, load=load, options=options
991
+ )
992
+
993
+ async def refresh(
994
+ self,
995
+ instance: object,
996
+ attribute_names: Optional[Iterable[str]] = None,
997
+ with_for_update: ForUpdateParameter = None,
998
+ ) -> None:
999
+ r"""Expire and refresh the attributes on the given instance.
1000
+
1001
+ .. container:: class_bases
1002
+
1003
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1004
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1005
+
1006
+ A query will be issued to the database and all attributes will be
1007
+ refreshed with their current database value.
1008
+
1009
+ This is the async version of the :meth:`_orm.Session.refresh` method.
1010
+ See that method for a complete description of all options.
1011
+
1012
+ .. seealso::
1013
+
1014
+ :meth:`_orm.Session.refresh` - main documentation for refresh
1015
+
1016
+
1017
+ """ # noqa: E501
1018
+
1019
+ return await self._proxied.refresh(
1020
+ instance,
1021
+ attribute_names=attribute_names,
1022
+ with_for_update=with_for_update,
1023
+ )
1024
+
1025
+ async def rollback(self) -> None:
1026
+ r"""Rollback the current transaction in progress.
1027
+
1028
+ .. container:: class_bases
1029
+
1030
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1031
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1032
+
1033
+ .. seealso::
1034
+
1035
+ :meth:`_orm.Session.rollback` - main documentation for
1036
+ "rollback"
1037
+
1038
+ """ # noqa: E501
1039
+
1040
+ return await self._proxied.rollback()
1041
+
1042
+ @overload
1043
+ async def scalar(
1044
+ self,
1045
+ statement: TypedReturnsRows[Never],
1046
+ params: Optional[_CoreAnyExecuteParams] = None,
1047
+ *,
1048
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1049
+ bind_arguments: Optional[_BindArguments] = None,
1050
+ **kw: Any,
1051
+ ) -> Optional[Any]: ...
1052
+
1053
+ @overload
1054
+ async def scalar(
1055
+ self,
1056
+ statement: TypedReturnsRows[_T],
1057
+ params: Optional[_CoreAnyExecuteParams] = None,
1058
+ *,
1059
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1060
+ bind_arguments: Optional[_BindArguments] = None,
1061
+ **kw: Any,
1062
+ ) -> Optional[_T]: ...
1063
+
1064
+ @overload
1065
+ async def scalar(
1066
+ self,
1067
+ statement: Executable,
1068
+ params: Optional[_CoreAnyExecuteParams] = None,
1069
+ *,
1070
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1071
+ bind_arguments: Optional[_BindArguments] = None,
1072
+ **kw: Any,
1073
+ ) -> Any: ...
1074
+
1075
+ async def scalar(
1076
+ self,
1077
+ statement: Executable,
1078
+ params: Optional[_CoreAnyExecuteParams] = None,
1079
+ *,
1080
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1081
+ bind_arguments: Optional[_BindArguments] = None,
1082
+ **kw: Any,
1083
+ ) -> Any:
1084
+ r"""Execute a statement and return a scalar result.
1085
+
1086
+ .. container:: class_bases
1087
+
1088
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1089
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1090
+
1091
+ .. seealso::
1092
+
1093
+ :meth:`_orm.Session.scalar` - main documentation for scalar
1094
+
1095
+
1096
+ """ # noqa: E501
1097
+
1098
+ return await self._proxied.scalar(
1099
+ statement,
1100
+ params=params,
1101
+ execution_options=execution_options,
1102
+ bind_arguments=bind_arguments,
1103
+ **kw,
1104
+ )
1105
+
1106
+ @overload
1107
+ async def scalars(
1108
+ self,
1109
+ statement: TypedReturnsRows[_T],
1110
+ params: Optional[_CoreAnyExecuteParams] = None,
1111
+ *,
1112
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1113
+ bind_arguments: Optional[_BindArguments] = None,
1114
+ **kw: Any,
1115
+ ) -> ScalarResult[_T]: ...
1116
+
1117
+ @overload
1118
+ async def scalars(
1119
+ self,
1120
+ statement: Executable,
1121
+ params: Optional[_CoreAnyExecuteParams] = None,
1122
+ *,
1123
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1124
+ bind_arguments: Optional[_BindArguments] = None,
1125
+ **kw: Any,
1126
+ ) -> ScalarResult[Any]: ...
1127
+
1128
+ async def scalars(
1129
+ self,
1130
+ statement: Executable,
1131
+ params: Optional[_CoreAnyExecuteParams] = None,
1132
+ *,
1133
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1134
+ bind_arguments: Optional[_BindArguments] = None,
1135
+ **kw: Any,
1136
+ ) -> ScalarResult[Any]:
1137
+ r"""Execute a statement and return scalar results.
1138
+
1139
+ .. container:: class_bases
1140
+
1141
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1142
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1143
+
1144
+ :return: a :class:`_result.ScalarResult` object
1145
+
1146
+ .. versionadded:: 1.4.24 Added :meth:`_asyncio.AsyncSession.scalars`
1147
+
1148
+ .. versionadded:: 1.4.26 Added
1149
+ :meth:`_asyncio.async_scoped_session.scalars`
1150
+
1151
+ .. seealso::
1152
+
1153
+ :meth:`_orm.Session.scalars` - main documentation for scalars
1154
+
1155
+ :meth:`_asyncio.AsyncSession.stream_scalars` - streaming version
1156
+
1157
+
1158
+ """ # noqa: E501
1159
+
1160
+ return await self._proxied.scalars(
1161
+ statement,
1162
+ params=params,
1163
+ execution_options=execution_options,
1164
+ bind_arguments=bind_arguments,
1165
+ **kw,
1166
+ )
1167
+
1168
+ async def get(
1169
+ self,
1170
+ entity: _EntityBindKey[_O],
1171
+ ident: _PKIdentityArgument,
1172
+ *,
1173
+ options: Optional[Sequence[ORMOption]] = None,
1174
+ populate_existing: bool = False,
1175
+ with_for_update: ForUpdateParameter = None,
1176
+ identity_token: Optional[Any] = None,
1177
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1178
+ ) -> Union[_O, None]:
1179
+ r"""Return an instance based on the given primary key identifier,
1180
+ or ``None`` if not found.
1181
+
1182
+ .. container:: class_bases
1183
+
1184
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1185
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1186
+
1187
+ .. seealso::
1188
+
1189
+ :meth:`_orm.Session.get` - main documentation for get
1190
+
1191
+
1192
+
1193
+ """ # noqa: E501
1194
+
1195
+ result = await self._proxied.get(
1196
+ entity,
1197
+ ident,
1198
+ options=options,
1199
+ populate_existing=populate_existing,
1200
+ with_for_update=with_for_update,
1201
+ identity_token=identity_token,
1202
+ execution_options=execution_options,
1203
+ )
1204
+ return result
1205
+
1206
+ async def get_one(
1207
+ self,
1208
+ entity: _EntityBindKey[_O],
1209
+ ident: _PKIdentityArgument,
1210
+ *,
1211
+ options: Optional[Sequence[ORMOption]] = None,
1212
+ populate_existing: bool = False,
1213
+ with_for_update: ForUpdateParameter = None,
1214
+ identity_token: Optional[Any] = None,
1215
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1216
+ ) -> _O:
1217
+ r"""Return an instance based on the given primary key identifier,
1218
+ or raise an exception if not found.
1219
+
1220
+ .. container:: class_bases
1221
+
1222
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1223
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1224
+
1225
+ Raises :class:`_exc.NoResultFound` if the query selects no rows.
1226
+
1227
+ ..versionadded: 2.0.22
1228
+
1229
+ .. seealso::
1230
+
1231
+ :meth:`_orm.Session.get_one` - main documentation for get_one
1232
+
1233
+
1234
+ """ # noqa: E501
1235
+
1236
+ return await self._proxied.get_one(
1237
+ entity,
1238
+ ident,
1239
+ options=options,
1240
+ populate_existing=populate_existing,
1241
+ with_for_update=with_for_update,
1242
+ identity_token=identity_token,
1243
+ execution_options=execution_options,
1244
+ )
1245
+
1246
+ @overload
1247
+ async def stream(
1248
+ self,
1249
+ statement: TypedReturnsRows[Unpack[_Ts]],
1250
+ params: Optional[_CoreAnyExecuteParams] = None,
1251
+ *,
1252
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1253
+ bind_arguments: Optional[_BindArguments] = None,
1254
+ **kw: Any,
1255
+ ) -> AsyncResult[Unpack[_Ts]]: ...
1256
+
1257
+ @overload
1258
+ async def stream(
1259
+ self,
1260
+ statement: Executable,
1261
+ params: Optional[_CoreAnyExecuteParams] = None,
1262
+ *,
1263
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1264
+ bind_arguments: Optional[_BindArguments] = None,
1265
+ **kw: Any,
1266
+ ) -> AsyncResult[Unpack[TupleAny]]: ...
1267
+
1268
+ async def stream(
1269
+ self,
1270
+ statement: Executable,
1271
+ params: Optional[_CoreAnyExecuteParams] = None,
1272
+ *,
1273
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1274
+ bind_arguments: Optional[_BindArguments] = None,
1275
+ **kw: Any,
1276
+ ) -> AsyncResult[Unpack[TupleAny]]:
1277
+ r"""Execute a statement and return a streaming
1278
+ :class:`_asyncio.AsyncResult` object.
1279
+
1280
+ .. container:: class_bases
1281
+
1282
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1283
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1284
+
1285
+
1286
+ """ # noqa: E501
1287
+
1288
+ return await self._proxied.stream(
1289
+ statement,
1290
+ params=params,
1291
+ execution_options=execution_options,
1292
+ bind_arguments=bind_arguments,
1293
+ **kw,
1294
+ )
1295
+
1296
+ @overload
1297
+ async def stream_scalars(
1298
+ self,
1299
+ statement: TypedReturnsRows[_T],
1300
+ params: Optional[_CoreAnyExecuteParams] = None,
1301
+ *,
1302
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1303
+ bind_arguments: Optional[_BindArguments] = None,
1304
+ **kw: Any,
1305
+ ) -> AsyncScalarResult[_T]: ...
1306
+
1307
+ @overload
1308
+ async def stream_scalars(
1309
+ self,
1310
+ statement: Executable,
1311
+ params: Optional[_CoreAnyExecuteParams] = None,
1312
+ *,
1313
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1314
+ bind_arguments: Optional[_BindArguments] = None,
1315
+ **kw: Any,
1316
+ ) -> AsyncScalarResult[Any]: ...
1317
+
1318
+ async def stream_scalars(
1319
+ self,
1320
+ statement: Executable,
1321
+ params: Optional[_CoreAnyExecuteParams] = None,
1322
+ *,
1323
+ execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
1324
+ bind_arguments: Optional[_BindArguments] = None,
1325
+ **kw: Any,
1326
+ ) -> AsyncScalarResult[Any]:
1327
+ r"""Execute a statement and return a stream of scalar results.
1328
+
1329
+ .. container:: class_bases
1330
+
1331
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1332
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1333
+
1334
+ :return: an :class:`_asyncio.AsyncScalarResult` object
1335
+
1336
+ .. versionadded:: 1.4.24
1337
+
1338
+ .. seealso::
1339
+
1340
+ :meth:`_orm.Session.scalars` - main documentation for scalars
1341
+
1342
+ :meth:`_asyncio.AsyncSession.scalars` - non streaming version
1343
+
1344
+
1345
+ """ # noqa: E501
1346
+
1347
+ return await self._proxied.stream_scalars(
1348
+ statement,
1349
+ params=params,
1350
+ execution_options=execution_options,
1351
+ bind_arguments=bind_arguments,
1352
+ **kw,
1353
+ )
1354
+
1355
+ @property
1356
+ def bind(self) -> Any:
1357
+ r"""Proxy for the :attr:`_asyncio.AsyncSession.bind` attribute
1358
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1359
+
1360
+ """ # noqa: E501
1361
+
1362
+ return self._proxied.bind
1363
+
1364
+ @bind.setter
1365
+ def bind(self, attr: Any) -> None:
1366
+ self._proxied.bind = attr
1367
+
1368
+ @property
1369
+ def dirty(self) -> Any:
1370
+ r"""The set of all persistent instances considered dirty.
1371
+
1372
+ .. container:: class_bases
1373
+
1374
+ Proxied for the :class:`_asyncio.AsyncSession` class
1375
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1376
+
1377
+ .. container:: class_bases
1378
+
1379
+ Proxied for the :class:`_orm.Session` class
1380
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1381
+
1382
+ E.g.::
1383
+
1384
+ some_mapped_object in session.dirty
1385
+
1386
+ Instances are considered dirty when they were modified but not
1387
+ deleted.
1388
+
1389
+ Note that this 'dirty' calculation is 'optimistic'; most
1390
+ attribute-setting or collection modification operations will
1391
+ mark an instance as 'dirty' and place it in this set, even if
1392
+ there is no net change to the attribute's value. At flush
1393
+ time, the value of each attribute is compared to its
1394
+ previously saved value, and if there's no net change, no SQL
1395
+ operation will occur (this is a more expensive operation so
1396
+ it's only done at flush time).
1397
+
1398
+ To check if an instance has actionable net changes to its
1399
+ attributes, use the :meth:`.Session.is_modified` method.
1400
+
1401
+
1402
+
1403
+ """ # noqa: E501
1404
+
1405
+ return self._proxied.dirty
1406
+
1407
+ @property
1408
+ def deleted(self) -> Any:
1409
+ r"""The set of all instances marked as 'deleted' within this ``Session``
1410
+
1411
+ .. container:: class_bases
1412
+
1413
+ Proxied for the :class:`_asyncio.AsyncSession` class
1414
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1415
+
1416
+ .. container:: class_bases
1417
+
1418
+ Proxied for the :class:`_orm.Session` class
1419
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1420
+
1421
+
1422
+ """ # noqa: E501
1423
+
1424
+ return self._proxied.deleted
1425
+
1426
+ @property
1427
+ def new(self) -> Any:
1428
+ r"""The set of all instances marked as 'new' within this ``Session``.
1429
+
1430
+ .. container:: class_bases
1431
+
1432
+ Proxied for the :class:`_asyncio.AsyncSession` class
1433
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1434
+
1435
+ .. container:: class_bases
1436
+
1437
+ Proxied for the :class:`_orm.Session` class
1438
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1439
+
1440
+
1441
+ """ # noqa: E501
1442
+
1443
+ return self._proxied.new
1444
+
1445
+ @property
1446
+ def identity_map(self) -> Any:
1447
+ r"""Proxy for the :attr:`_orm.Session.identity_map` attribute
1448
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1449
+
1450
+ .. container:: class_bases
1451
+
1452
+ Proxied for the :class:`_asyncio.AsyncSession` class
1453
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1454
+
1455
+
1456
+ """ # noqa: E501
1457
+
1458
+ return self._proxied.identity_map
1459
+
1460
+ @identity_map.setter
1461
+ def identity_map(self, attr: Any) -> None:
1462
+ self._proxied.identity_map = attr
1463
+
1464
+ @property
1465
+ def is_active(self) -> Any:
1466
+ r"""True if this :class:`.Session` not in "partial rollback" state.
1467
+
1468
+ .. container:: class_bases
1469
+
1470
+ Proxied for the :class:`_asyncio.AsyncSession` class
1471
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1472
+
1473
+ .. container:: class_bases
1474
+
1475
+ Proxied for the :class:`_orm.Session` class
1476
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1477
+
1478
+ .. versionchanged:: 1.4 The :class:`_orm.Session` no longer begins
1479
+ a new transaction immediately, so this attribute will be False
1480
+ when the :class:`_orm.Session` is first instantiated.
1481
+
1482
+ "partial rollback" state typically indicates that the flush process
1483
+ of the :class:`_orm.Session` has failed, and that the
1484
+ :meth:`_orm.Session.rollback` method must be emitted in order to
1485
+ fully roll back the transaction.
1486
+
1487
+ If this :class:`_orm.Session` is not in a transaction at all, the
1488
+ :class:`_orm.Session` will autobegin when it is first used, so in this
1489
+ case :attr:`_orm.Session.is_active` will return True.
1490
+
1491
+ Otherwise, if this :class:`_orm.Session` is within a transaction,
1492
+ and that transaction has not been rolled back internally, the
1493
+ :attr:`_orm.Session.is_active` will also return True.
1494
+
1495
+ .. seealso::
1496
+
1497
+ :ref:`faq_session_rollback`
1498
+
1499
+ :meth:`_orm.Session.in_transaction`
1500
+
1501
+
1502
+
1503
+ """ # noqa: E501
1504
+
1505
+ return self._proxied.is_active
1506
+
1507
+ @property
1508
+ def autoflush(self) -> Any:
1509
+ r"""Proxy for the :attr:`_orm.Session.autoflush` attribute
1510
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1511
+
1512
+ .. container:: class_bases
1513
+
1514
+ Proxied for the :class:`_asyncio.AsyncSession` class
1515
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1516
+
1517
+
1518
+ """ # noqa: E501
1519
+
1520
+ return self._proxied.autoflush
1521
+
1522
+ @autoflush.setter
1523
+ def autoflush(self, attr: Any) -> None:
1524
+ self._proxied.autoflush = attr
1525
+
1526
+ @property
1527
+ def no_autoflush(self) -> Any:
1528
+ r"""Return a context manager that disables autoflush.
1529
+
1530
+ .. container:: class_bases
1531
+
1532
+ Proxied for the :class:`_asyncio.AsyncSession` class
1533
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1534
+
1535
+ .. container:: class_bases
1536
+
1537
+ Proxied for the :class:`_orm.Session` class
1538
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1539
+
1540
+ e.g.::
1541
+
1542
+ with session.no_autoflush:
1543
+
1544
+ some_object = SomeClass()
1545
+ session.add(some_object)
1546
+ # won't autoflush
1547
+ some_object.related_thing = session.query(SomeRelated).first()
1548
+
1549
+ Operations that proceed within the ``with:`` block
1550
+ will not be subject to flushes occurring upon query
1551
+ access. This is useful when initializing a series
1552
+ of objects which involve existing database queries,
1553
+ where the uncompleted object should not yet be flushed.
1554
+
1555
+
1556
+
1557
+ """ # noqa: E501
1558
+
1559
+ return self._proxied.no_autoflush
1560
+
1561
+ @property
1562
+ def info(self) -> Any:
1563
+ r"""A user-modifiable dictionary.
1564
+
1565
+ .. container:: class_bases
1566
+
1567
+ Proxied for the :class:`_asyncio.AsyncSession` class
1568
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1569
+
1570
+ .. container:: class_bases
1571
+
1572
+ Proxied for the :class:`_orm.Session` class
1573
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1574
+
1575
+ The initial value of this dictionary can be populated using the
1576
+ ``info`` argument to the :class:`.Session` constructor or
1577
+ :class:`.sessionmaker` constructor or factory methods. The dictionary
1578
+ here is always local to this :class:`.Session` and can be modified
1579
+ independently of all other :class:`.Session` objects.
1580
+
1581
+
1582
+
1583
+ """ # noqa: E501
1584
+
1585
+ return self._proxied.info
1586
+
1587
+ @property
1588
+ def execution_options(self) -> Any:
1589
+ r"""Proxy for the :attr:`_orm.Session.execution_options` attribute
1590
+ on behalf of the :class:`_asyncio.AsyncSession` class.
1591
+
1592
+ .. container:: class_bases
1593
+
1594
+ Proxied for the :class:`_asyncio.AsyncSession` class
1595
+ on behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1596
+
1597
+
1598
+ """ # noqa: E501
1599
+
1600
+ return self._proxied.execution_options
1601
+
1602
+ @execution_options.setter
1603
+ def execution_options(self, attr: Any) -> None:
1604
+ self._proxied.execution_options = attr
1605
+
1606
+ @classmethod
1607
+ async def close_all(cls) -> None:
1608
+ r"""Close all :class:`_asyncio.AsyncSession` sessions.
1609
+
1610
+ .. container:: class_bases
1611
+
1612
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1613
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1614
+
1615
+ .. 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`.
1616
+
1617
+ """ # noqa: E501
1618
+
1619
+ return await AsyncSession.close_all()
1620
+
1621
+ @classmethod
1622
+ def object_session(cls, instance: object) -> Optional[Session]:
1623
+ r"""Return the :class:`.Session` to which an object belongs.
1624
+
1625
+ .. container:: class_bases
1626
+
1627
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1628
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1629
+
1630
+ .. container:: class_bases
1631
+
1632
+ Proxied for the :class:`_orm.Session` class on
1633
+ behalf of the :class:`_asyncio.AsyncSession` class.
1634
+
1635
+ This is an alias of :func:`.object_session`.
1636
+
1637
+
1638
+
1639
+ """ # noqa: E501
1640
+
1641
+ return AsyncSession.object_session(instance)
1642
+
1643
+ @classmethod
1644
+ def identity_key(
1645
+ cls,
1646
+ class_: Optional[Type[Any]] = None,
1647
+ ident: Union[Any, Tuple[Any, ...]] = None,
1648
+ *,
1649
+ instance: Optional[Any] = None,
1650
+ row: Optional[Union[Row[Unpack[TupleAny]], RowMapping]] = None,
1651
+ identity_token: Optional[Any] = None,
1652
+ ) -> _IdentityKeyType[Any]:
1653
+ r"""Return an identity key.
1654
+
1655
+ .. container:: class_bases
1656
+
1657
+ Proxied for the :class:`_asyncio.AsyncSession` class on
1658
+ behalf of the :class:`_asyncio.scoping.async_scoped_session` class.
1659
+
1660
+ .. container:: class_bases
1661
+
1662
+ Proxied for the :class:`_orm.Session` class on
1663
+ behalf of the :class:`_asyncio.AsyncSession` class.
1664
+
1665
+ This is an alias of :func:`.util.identity_key`.
1666
+
1667
+
1668
+
1669
+ """ # noqa: E501
1670
+
1671
+ return AsyncSession.identity_key(
1672
+ class_=class_,
1673
+ ident=ident,
1674
+ instance=instance,
1675
+ row=row,
1676
+ identity_token=identity_token,
1677
+ )
1678
+
1679
+ # END PROXY METHODS async_scoped_session