SQLAlchemy 2.0.47__cp313-cp313t-win_amd64.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 (274) hide show
  1. sqlalchemy/__init__.py +283 -0
  2. sqlalchemy/connectors/__init__.py +18 -0
  3. sqlalchemy/connectors/aioodbc.py +184 -0
  4. sqlalchemy/connectors/asyncio.py +429 -0
  5. sqlalchemy/connectors/pyodbc.py +250 -0
  6. sqlalchemy/cyextension/__init__.py +6 -0
  7. sqlalchemy/cyextension/collections.cp313t-win_amd64.pyd +0 -0
  8. sqlalchemy/cyextension/collections.pyx +409 -0
  9. sqlalchemy/cyextension/immutabledict.cp313t-win_amd64.pyd +0 -0
  10. sqlalchemy/cyextension/immutabledict.pxd +8 -0
  11. sqlalchemy/cyextension/immutabledict.pyx +133 -0
  12. sqlalchemy/cyextension/processors.cp313t-win_amd64.pyd +0 -0
  13. sqlalchemy/cyextension/processors.pyx +68 -0
  14. sqlalchemy/cyextension/resultproxy.cp313t-win_amd64.pyd +0 -0
  15. sqlalchemy/cyextension/resultproxy.pyx +102 -0
  16. sqlalchemy/cyextension/util.cp313t-win_amd64.pyd +0 -0
  17. sqlalchemy/cyextension/util.pyx +90 -0
  18. sqlalchemy/dialects/__init__.py +62 -0
  19. sqlalchemy/dialects/_typing.py +30 -0
  20. sqlalchemy/dialects/mssql/__init__.py +88 -0
  21. sqlalchemy/dialects/mssql/aioodbc.py +63 -0
  22. sqlalchemy/dialects/mssql/base.py +4093 -0
  23. sqlalchemy/dialects/mssql/information_schema.py +285 -0
  24. sqlalchemy/dialects/mssql/json.py +129 -0
  25. sqlalchemy/dialects/mssql/provision.py +185 -0
  26. sqlalchemy/dialects/mssql/pymssql.py +126 -0
  27. sqlalchemy/dialects/mssql/pyodbc.py +760 -0
  28. sqlalchemy/dialects/mysql/__init__.py +104 -0
  29. sqlalchemy/dialects/mysql/aiomysql.py +250 -0
  30. sqlalchemy/dialects/mysql/asyncmy.py +231 -0
  31. sqlalchemy/dialects/mysql/base.py +3949 -0
  32. sqlalchemy/dialects/mysql/cymysql.py +106 -0
  33. sqlalchemy/dialects/mysql/dml.py +225 -0
  34. sqlalchemy/dialects/mysql/enumerated.py +282 -0
  35. sqlalchemy/dialects/mysql/expression.py +146 -0
  36. sqlalchemy/dialects/mysql/json.py +91 -0
  37. sqlalchemy/dialects/mysql/mariadb.py +72 -0
  38. sqlalchemy/dialects/mysql/mariadbconnector.py +322 -0
  39. sqlalchemy/dialects/mysql/mysqlconnector.py +302 -0
  40. sqlalchemy/dialects/mysql/mysqldb.py +314 -0
  41. sqlalchemy/dialects/mysql/provision.py +153 -0
  42. sqlalchemy/dialects/mysql/pymysql.py +158 -0
  43. sqlalchemy/dialects/mysql/pyodbc.py +157 -0
  44. sqlalchemy/dialects/mysql/reflection.py +727 -0
  45. sqlalchemy/dialects/mysql/reserved_words.py +570 -0
  46. sqlalchemy/dialects/mysql/types.py +835 -0
  47. sqlalchemy/dialects/oracle/__init__.py +81 -0
  48. sqlalchemy/dialects/oracle/base.py +3802 -0
  49. sqlalchemy/dialects/oracle/cx_oracle.py +1555 -0
  50. sqlalchemy/dialects/oracle/dictionary.py +507 -0
  51. sqlalchemy/dialects/oracle/oracledb.py +941 -0
  52. sqlalchemy/dialects/oracle/provision.py +297 -0
  53. sqlalchemy/dialects/oracle/types.py +316 -0
  54. sqlalchemy/dialects/oracle/vector.py +365 -0
  55. sqlalchemy/dialects/postgresql/__init__.py +167 -0
  56. sqlalchemy/dialects/postgresql/_psycopg_common.py +189 -0
  57. sqlalchemy/dialects/postgresql/array.py +519 -0
  58. sqlalchemy/dialects/postgresql/asyncpg.py +1284 -0
  59. sqlalchemy/dialects/postgresql/base.py +5378 -0
  60. sqlalchemy/dialects/postgresql/dml.py +339 -0
  61. sqlalchemy/dialects/postgresql/ext.py +540 -0
  62. sqlalchemy/dialects/postgresql/hstore.py +406 -0
  63. sqlalchemy/dialects/postgresql/json.py +404 -0
  64. sqlalchemy/dialects/postgresql/named_types.py +524 -0
  65. sqlalchemy/dialects/postgresql/operators.py +129 -0
  66. sqlalchemy/dialects/postgresql/pg8000.py +669 -0
  67. sqlalchemy/dialects/postgresql/pg_catalog.py +326 -0
  68. sqlalchemy/dialects/postgresql/provision.py +183 -0
  69. sqlalchemy/dialects/postgresql/psycopg.py +862 -0
  70. sqlalchemy/dialects/postgresql/psycopg2.py +892 -0
  71. sqlalchemy/dialects/postgresql/psycopg2cffi.py +61 -0
  72. sqlalchemy/dialects/postgresql/ranges.py +1031 -0
  73. sqlalchemy/dialects/postgresql/types.py +313 -0
  74. sqlalchemy/dialects/sqlite/__init__.py +57 -0
  75. sqlalchemy/dialects/sqlite/aiosqlite.py +482 -0
  76. sqlalchemy/dialects/sqlite/base.py +3056 -0
  77. sqlalchemy/dialects/sqlite/dml.py +263 -0
  78. sqlalchemy/dialects/sqlite/json.py +92 -0
  79. sqlalchemy/dialects/sqlite/provision.py +229 -0
  80. sqlalchemy/dialects/sqlite/pysqlcipher.py +157 -0
  81. sqlalchemy/dialects/sqlite/pysqlite.py +756 -0
  82. sqlalchemy/dialects/type_migration_guidelines.txt +145 -0
  83. sqlalchemy/engine/__init__.py +62 -0
  84. sqlalchemy/engine/_py_processors.py +136 -0
  85. sqlalchemy/engine/_py_row.py +128 -0
  86. sqlalchemy/engine/_py_util.py +74 -0
  87. sqlalchemy/engine/base.py +3390 -0
  88. sqlalchemy/engine/characteristics.py +155 -0
  89. sqlalchemy/engine/create.py +893 -0
  90. sqlalchemy/engine/cursor.py +2298 -0
  91. sqlalchemy/engine/default.py +2394 -0
  92. sqlalchemy/engine/events.py +965 -0
  93. sqlalchemy/engine/interfaces.py +3471 -0
  94. sqlalchemy/engine/mock.py +134 -0
  95. sqlalchemy/engine/processors.py +61 -0
  96. sqlalchemy/engine/reflection.py +2102 -0
  97. sqlalchemy/engine/result.py +2399 -0
  98. sqlalchemy/engine/row.py +400 -0
  99. sqlalchemy/engine/strategies.py +16 -0
  100. sqlalchemy/engine/url.py +924 -0
  101. sqlalchemy/engine/util.py +167 -0
  102. sqlalchemy/event/__init__.py +26 -0
  103. sqlalchemy/event/api.py +220 -0
  104. sqlalchemy/event/attr.py +676 -0
  105. sqlalchemy/event/base.py +472 -0
  106. sqlalchemy/event/legacy.py +258 -0
  107. sqlalchemy/event/registry.py +390 -0
  108. sqlalchemy/events.py +17 -0
  109. sqlalchemy/exc.py +832 -0
  110. sqlalchemy/ext/__init__.py +11 -0
  111. sqlalchemy/ext/associationproxy.py +2027 -0
  112. sqlalchemy/ext/asyncio/__init__.py +25 -0
  113. sqlalchemy/ext/asyncio/base.py +281 -0
  114. sqlalchemy/ext/asyncio/engine.py +1471 -0
  115. sqlalchemy/ext/asyncio/exc.py +21 -0
  116. sqlalchemy/ext/asyncio/result.py +965 -0
  117. sqlalchemy/ext/asyncio/scoping.py +1599 -0
  118. sqlalchemy/ext/asyncio/session.py +1947 -0
  119. sqlalchemy/ext/automap.py +1701 -0
  120. sqlalchemy/ext/baked.py +570 -0
  121. sqlalchemy/ext/compiler.py +600 -0
  122. sqlalchemy/ext/declarative/__init__.py +65 -0
  123. sqlalchemy/ext/declarative/extensions.py +564 -0
  124. sqlalchemy/ext/horizontal_shard.py +478 -0
  125. sqlalchemy/ext/hybrid.py +1535 -0
  126. sqlalchemy/ext/indexable.py +364 -0
  127. sqlalchemy/ext/instrumentation.py +450 -0
  128. sqlalchemy/ext/mutable.py +1085 -0
  129. sqlalchemy/ext/mypy/__init__.py +6 -0
  130. sqlalchemy/ext/mypy/apply.py +324 -0
  131. sqlalchemy/ext/mypy/decl_class.py +515 -0
  132. sqlalchemy/ext/mypy/infer.py +590 -0
  133. sqlalchemy/ext/mypy/names.py +335 -0
  134. sqlalchemy/ext/mypy/plugin.py +303 -0
  135. sqlalchemy/ext/mypy/util.py +357 -0
  136. sqlalchemy/ext/orderinglist.py +439 -0
  137. sqlalchemy/ext/serializer.py +185 -0
  138. sqlalchemy/future/__init__.py +16 -0
  139. sqlalchemy/future/engine.py +15 -0
  140. sqlalchemy/inspection.py +174 -0
  141. sqlalchemy/log.py +288 -0
  142. sqlalchemy/orm/__init__.py +171 -0
  143. sqlalchemy/orm/_orm_constructors.py +2661 -0
  144. sqlalchemy/orm/_typing.py +179 -0
  145. sqlalchemy/orm/attributes.py +2845 -0
  146. sqlalchemy/orm/base.py +971 -0
  147. sqlalchemy/orm/bulk_persistence.py +2135 -0
  148. sqlalchemy/orm/clsregistry.py +571 -0
  149. sqlalchemy/orm/collections.py +1627 -0
  150. sqlalchemy/orm/context.py +3334 -0
  151. sqlalchemy/orm/decl_api.py +2004 -0
  152. sqlalchemy/orm/decl_base.py +2192 -0
  153. sqlalchemy/orm/dependency.py +1302 -0
  154. sqlalchemy/orm/descriptor_props.py +1092 -0
  155. sqlalchemy/orm/dynamic.py +300 -0
  156. sqlalchemy/orm/evaluator.py +379 -0
  157. sqlalchemy/orm/events.py +3252 -0
  158. sqlalchemy/orm/exc.py +237 -0
  159. sqlalchemy/orm/identity.py +302 -0
  160. sqlalchemy/orm/instrumentation.py +754 -0
  161. sqlalchemy/orm/interfaces.py +1496 -0
  162. sqlalchemy/orm/loading.py +1686 -0
  163. sqlalchemy/orm/mapped_collection.py +557 -0
  164. sqlalchemy/orm/mapper.py +4444 -0
  165. sqlalchemy/orm/path_registry.py +809 -0
  166. sqlalchemy/orm/persistence.py +1788 -0
  167. sqlalchemy/orm/properties.py +935 -0
  168. sqlalchemy/orm/query.py +3459 -0
  169. sqlalchemy/orm/relationships.py +3508 -0
  170. sqlalchemy/orm/scoping.py +2148 -0
  171. sqlalchemy/orm/session.py +5280 -0
  172. sqlalchemy/orm/state.py +1168 -0
  173. sqlalchemy/orm/state_changes.py +196 -0
  174. sqlalchemy/orm/strategies.py +3470 -0
  175. sqlalchemy/orm/strategy_options.py +2568 -0
  176. sqlalchemy/orm/sync.py +164 -0
  177. sqlalchemy/orm/unitofwork.py +796 -0
  178. sqlalchemy/orm/util.py +2403 -0
  179. sqlalchemy/orm/writeonly.py +674 -0
  180. sqlalchemy/pool/__init__.py +44 -0
  181. sqlalchemy/pool/base.py +1524 -0
  182. sqlalchemy/pool/events.py +375 -0
  183. sqlalchemy/pool/impl.py +588 -0
  184. sqlalchemy/py.typed +0 -0
  185. sqlalchemy/schema.py +69 -0
  186. sqlalchemy/sql/__init__.py +145 -0
  187. sqlalchemy/sql/_dml_constructors.py +132 -0
  188. sqlalchemy/sql/_elements_constructors.py +1872 -0
  189. sqlalchemy/sql/_orm_types.py +20 -0
  190. sqlalchemy/sql/_py_util.py +75 -0
  191. sqlalchemy/sql/_selectable_constructors.py +763 -0
  192. sqlalchemy/sql/_typing.py +482 -0
  193. sqlalchemy/sql/annotation.py +587 -0
  194. sqlalchemy/sql/base.py +2293 -0
  195. sqlalchemy/sql/cache_key.py +1057 -0
  196. sqlalchemy/sql/coercions.py +1404 -0
  197. sqlalchemy/sql/compiler.py +8081 -0
  198. sqlalchemy/sql/crud.py +1752 -0
  199. sqlalchemy/sql/ddl.py +1444 -0
  200. sqlalchemy/sql/default_comparator.py +551 -0
  201. sqlalchemy/sql/dml.py +1850 -0
  202. sqlalchemy/sql/elements.py +5589 -0
  203. sqlalchemy/sql/events.py +458 -0
  204. sqlalchemy/sql/expression.py +159 -0
  205. sqlalchemy/sql/functions.py +2158 -0
  206. sqlalchemy/sql/lambdas.py +1442 -0
  207. sqlalchemy/sql/naming.py +209 -0
  208. sqlalchemy/sql/operators.py +2623 -0
  209. sqlalchemy/sql/roles.py +323 -0
  210. sqlalchemy/sql/schema.py +6222 -0
  211. sqlalchemy/sql/selectable.py +7265 -0
  212. sqlalchemy/sql/sqltypes.py +3930 -0
  213. sqlalchemy/sql/traversals.py +1024 -0
  214. sqlalchemy/sql/type_api.py +2368 -0
  215. sqlalchemy/sql/util.py +1485 -0
  216. sqlalchemy/sql/visitors.py +1164 -0
  217. sqlalchemy/testing/__init__.py +96 -0
  218. sqlalchemy/testing/assertions.py +994 -0
  219. sqlalchemy/testing/assertsql.py +520 -0
  220. sqlalchemy/testing/asyncio.py +135 -0
  221. sqlalchemy/testing/config.py +434 -0
  222. sqlalchemy/testing/engines.py +483 -0
  223. sqlalchemy/testing/entities.py +117 -0
  224. sqlalchemy/testing/exclusions.py +476 -0
  225. sqlalchemy/testing/fixtures/__init__.py +28 -0
  226. sqlalchemy/testing/fixtures/base.py +384 -0
  227. sqlalchemy/testing/fixtures/mypy.py +332 -0
  228. sqlalchemy/testing/fixtures/orm.py +227 -0
  229. sqlalchemy/testing/fixtures/sql.py +482 -0
  230. sqlalchemy/testing/pickleable.py +155 -0
  231. sqlalchemy/testing/plugin/__init__.py +6 -0
  232. sqlalchemy/testing/plugin/bootstrap.py +51 -0
  233. sqlalchemy/testing/plugin/plugin_base.py +828 -0
  234. sqlalchemy/testing/plugin/pytestplugin.py +892 -0
  235. sqlalchemy/testing/profiling.py +329 -0
  236. sqlalchemy/testing/provision.py +603 -0
  237. sqlalchemy/testing/requirements.py +1945 -0
  238. sqlalchemy/testing/schema.py +198 -0
  239. sqlalchemy/testing/suite/__init__.py +19 -0
  240. sqlalchemy/testing/suite/test_cte.py +237 -0
  241. sqlalchemy/testing/suite/test_ddl.py +389 -0
  242. sqlalchemy/testing/suite/test_deprecations.py +153 -0
  243. sqlalchemy/testing/suite/test_dialect.py +776 -0
  244. sqlalchemy/testing/suite/test_insert.py +630 -0
  245. sqlalchemy/testing/suite/test_reflection.py +3557 -0
  246. sqlalchemy/testing/suite/test_results.py +504 -0
  247. sqlalchemy/testing/suite/test_rowcount.py +258 -0
  248. sqlalchemy/testing/suite/test_select.py +2010 -0
  249. sqlalchemy/testing/suite/test_sequence.py +317 -0
  250. sqlalchemy/testing/suite/test_types.py +2147 -0
  251. sqlalchemy/testing/suite/test_unicode_ddl.py +189 -0
  252. sqlalchemy/testing/suite/test_update_delete.py +139 -0
  253. sqlalchemy/testing/util.py +535 -0
  254. sqlalchemy/testing/warnings.py +52 -0
  255. sqlalchemy/types.py +74 -0
  256. sqlalchemy/util/__init__.py +162 -0
  257. sqlalchemy/util/_collections.py +712 -0
  258. sqlalchemy/util/_concurrency_py3k.py +288 -0
  259. sqlalchemy/util/_has_cy.py +40 -0
  260. sqlalchemy/util/_py_collections.py +541 -0
  261. sqlalchemy/util/compat.py +421 -0
  262. sqlalchemy/util/concurrency.py +110 -0
  263. sqlalchemy/util/deprecations.py +401 -0
  264. sqlalchemy/util/langhelpers.py +2203 -0
  265. sqlalchemy/util/preloaded.py +150 -0
  266. sqlalchemy/util/queue.py +322 -0
  267. sqlalchemy/util/tool_support.py +201 -0
  268. sqlalchemy/util/topological.py +120 -0
  269. sqlalchemy/util/typing.py +734 -0
  270. sqlalchemy-2.0.47.dist-info/METADATA +243 -0
  271. sqlalchemy-2.0.47.dist-info/RECORD +274 -0
  272. sqlalchemy-2.0.47.dist-info/WHEEL +5 -0
  273. sqlalchemy-2.0.47.dist-info/licenses/LICENSE +19 -0
  274. sqlalchemy-2.0.47.dist-info/top_level.txt +1 -0
@@ -0,0 +1,588 @@
1
+ # pool/impl.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
+
9
+ """Pool implementation classes."""
10
+ from __future__ import annotations
11
+
12
+ import threading
13
+ import traceback
14
+ import typing
15
+ from typing import Any
16
+ from typing import cast
17
+ from typing import List
18
+ from typing import Optional
19
+ from typing import Set
20
+ from typing import Type
21
+ from typing import TYPE_CHECKING
22
+ from typing import Union
23
+ import weakref
24
+
25
+ from .base import _AsyncConnDialect
26
+ from .base import _ConnectionFairy
27
+ from .base import _ConnectionRecord
28
+ from .base import _CreatorFnType
29
+ from .base import _CreatorWRecFnType
30
+ from .base import ConnectionPoolEntry
31
+ from .base import Pool
32
+ from .base import PoolProxiedConnection
33
+ from .. import exc
34
+ from .. import util
35
+ from ..util import chop_traceback
36
+ from ..util import queue as sqla_queue
37
+ from ..util.typing import Literal
38
+
39
+ if typing.TYPE_CHECKING:
40
+ from ..engine.interfaces import DBAPIConnection
41
+
42
+
43
+ class QueuePool(Pool):
44
+ """A :class:`_pool.Pool`
45
+ that imposes a limit on the number of open connections.
46
+
47
+ :class:`.QueuePool` is the default pooling implementation used for
48
+ all :class:`_engine.Engine` objects other than SQLite with a ``:memory:``
49
+ database.
50
+
51
+ The :class:`.QueuePool` class **is not compatible** with asyncio and
52
+ :func:`_asyncio.create_async_engine`. The
53
+ :class:`.AsyncAdaptedQueuePool` class is used automatically when
54
+ using :func:`_asyncio.create_async_engine`, if no other kind of pool
55
+ is specified.
56
+
57
+ .. seealso::
58
+
59
+ :class:`.AsyncAdaptedQueuePool`
60
+
61
+ """
62
+
63
+ _is_asyncio = False
64
+
65
+ _queue_class: Type[sqla_queue.QueueCommon[ConnectionPoolEntry]] = (
66
+ sqla_queue.Queue
67
+ )
68
+
69
+ _pool: sqla_queue.QueueCommon[ConnectionPoolEntry]
70
+
71
+ def __init__(
72
+ self,
73
+ creator: Union[_CreatorFnType, _CreatorWRecFnType],
74
+ pool_size: int = 5,
75
+ max_overflow: int = 10,
76
+ timeout: float = 30.0,
77
+ use_lifo: bool = False,
78
+ **kw: Any,
79
+ ):
80
+ r"""
81
+ Construct a QueuePool.
82
+
83
+ :param creator: a callable function that returns a DB-API
84
+ connection object, same as that of :paramref:`_pool.Pool.creator`.
85
+
86
+ :param pool_size: The size of the pool to be maintained,
87
+ defaults to 5. This is the largest number of connections that
88
+ will be kept persistently in the pool. Note that the pool
89
+ begins with no connections; once this number of connections
90
+ is requested, that number of connections will remain.
91
+ ``pool_size`` can be set to 0 to indicate no size limit; to
92
+ disable pooling, use a :class:`~sqlalchemy.pool.NullPool`
93
+ instead.
94
+
95
+ :param max_overflow: The maximum overflow size of the
96
+ pool. When the number of checked-out connections reaches the
97
+ size set in pool_size, additional connections will be
98
+ returned up to this limit. When those additional connections
99
+ are returned to the pool, they are disconnected and
100
+ discarded. It follows then that the total number of
101
+ simultaneous connections the pool will allow is pool_size +
102
+ `max_overflow`, and the total number of "sleeping"
103
+ connections the pool will allow is pool_size. `max_overflow`
104
+ can be set to -1 to indicate no overflow limit; no limit
105
+ will be placed on the total number of concurrent
106
+ connections. Defaults to 10.
107
+
108
+ :param timeout: The number of seconds to wait before giving up
109
+ on returning a connection. Defaults to 30.0. This can be a float
110
+ but is subject to the limitations of Python time functions which
111
+ may not be reliable in the tens of milliseconds.
112
+
113
+ :param use_lifo: use LIFO (last-in-first-out) when retrieving
114
+ connections instead of FIFO (first-in-first-out). Using LIFO, a
115
+ server-side timeout scheme can reduce the number of connections used
116
+ during non-peak periods of use. When planning for server-side
117
+ timeouts, ensure that a recycle or pre-ping strategy is in use to
118
+ gracefully handle stale connections.
119
+
120
+ .. versionadded:: 1.3
121
+
122
+ .. seealso::
123
+
124
+ :ref:`pool_use_lifo`
125
+
126
+ :ref:`pool_disconnects`
127
+
128
+ :param \**kw: Other keyword arguments including
129
+ :paramref:`_pool.Pool.recycle`, :paramref:`_pool.Pool.echo`,
130
+ :paramref:`_pool.Pool.reset_on_return` and others are passed to the
131
+ :class:`_pool.Pool` constructor.
132
+
133
+ """
134
+
135
+ Pool.__init__(self, creator, **kw)
136
+ self._pool = self._queue_class(pool_size, use_lifo=use_lifo)
137
+ self._overflow = 0 - pool_size
138
+ self._max_overflow = -1 if pool_size == 0 else max_overflow
139
+ self._timeout = timeout
140
+ self._overflow_lock = threading.Lock()
141
+
142
+ def _do_return_conn(self, record: ConnectionPoolEntry) -> None:
143
+ try:
144
+ self._pool.put(record, False)
145
+ except sqla_queue.Full:
146
+ try:
147
+ record.close()
148
+ finally:
149
+ self._dec_overflow()
150
+
151
+ def _do_get(self) -> ConnectionPoolEntry:
152
+ use_overflow = self._max_overflow > -1
153
+
154
+ wait = use_overflow and self._overflow >= self._max_overflow
155
+ try:
156
+ return self._pool.get(wait, self._timeout)
157
+ except sqla_queue.Empty:
158
+ # don't do things inside of "except Empty", because when we say
159
+ # we timed out or can't connect and raise, Python 3 tells
160
+ # people the real error is queue.Empty which it isn't.
161
+ pass
162
+ if use_overflow and self._overflow >= self._max_overflow:
163
+ if not wait:
164
+ return self._do_get()
165
+ else:
166
+ raise exc.TimeoutError(
167
+ "QueuePool limit of size %d overflow %d reached, "
168
+ "connection timed out, timeout %0.2f"
169
+ % (self.size(), self.overflow(), self._timeout),
170
+ code="3o7r",
171
+ )
172
+
173
+ if self._inc_overflow():
174
+ try:
175
+ return self._create_connection()
176
+ except:
177
+ with util.safe_reraise():
178
+ self._dec_overflow()
179
+ raise
180
+ else:
181
+ return self._do_get()
182
+
183
+ def _inc_overflow(self) -> bool:
184
+ if self._max_overflow == -1:
185
+ self._overflow += 1
186
+ return True
187
+ with self._overflow_lock:
188
+ if self._overflow < self._max_overflow:
189
+ self._overflow += 1
190
+ return True
191
+ else:
192
+ return False
193
+
194
+ def _dec_overflow(self) -> Literal[True]:
195
+ if self._max_overflow == -1:
196
+ self._overflow -= 1
197
+ return True
198
+ with self._overflow_lock:
199
+ self._overflow -= 1
200
+ return True
201
+
202
+ def recreate(self) -> QueuePool:
203
+ self.logger.info("Pool recreating")
204
+ return self.__class__(
205
+ self._creator,
206
+ pool_size=self._pool.maxsize,
207
+ max_overflow=self._max_overflow,
208
+ pre_ping=self._pre_ping,
209
+ use_lifo=self._pool.use_lifo,
210
+ timeout=self._timeout,
211
+ recycle=self._recycle,
212
+ echo=self.echo,
213
+ logging_name=self._orig_logging_name,
214
+ reset_on_return=self._reset_on_return,
215
+ _dispatch=self.dispatch,
216
+ dialect=self._dialect,
217
+ )
218
+
219
+ def dispose(self) -> None:
220
+ while True:
221
+ try:
222
+ conn = self._pool.get(False)
223
+ conn.close()
224
+ except sqla_queue.Empty:
225
+ break
226
+
227
+ self._overflow = 0 - self.size()
228
+ self.logger.info("Pool disposed. %s", self.status())
229
+
230
+ def status(self) -> str:
231
+ return (
232
+ "Pool size: %d Connections in pool: %d "
233
+ "Current Overflow: %d Current Checked out "
234
+ "connections: %d"
235
+ % (
236
+ self.size(),
237
+ self.checkedin(),
238
+ self.overflow(),
239
+ self.checkedout(),
240
+ )
241
+ )
242
+
243
+ def size(self) -> int:
244
+ return self._pool.maxsize
245
+
246
+ def timeout(self) -> float:
247
+ return self._timeout
248
+
249
+ def checkedin(self) -> int:
250
+ return self._pool.qsize()
251
+
252
+ def overflow(self) -> int:
253
+ return self._overflow if self._pool.maxsize else 0
254
+
255
+ def checkedout(self) -> int:
256
+ return self._pool.maxsize - self._pool.qsize() + self._overflow
257
+
258
+
259
+ class AsyncAdaptedQueuePool(QueuePool):
260
+ """An asyncio-compatible version of :class:`.QueuePool`.
261
+
262
+ This pool is used by default when using :class:`.AsyncEngine` engines that
263
+ were generated from :func:`_asyncio.create_async_engine`. It uses an
264
+ asyncio-compatible queue implementation that does not use
265
+ ``threading.Lock``.
266
+
267
+ The arguments and operation of :class:`.AsyncAdaptedQueuePool` are
268
+ otherwise identical to that of :class:`.QueuePool`.
269
+
270
+ """
271
+
272
+ _is_asyncio = True
273
+ _queue_class: Type[sqla_queue.QueueCommon[ConnectionPoolEntry]] = (
274
+ sqla_queue.AsyncAdaptedQueue
275
+ )
276
+
277
+ _dialect = _AsyncConnDialect()
278
+
279
+
280
+ class FallbackAsyncAdaptedQueuePool(AsyncAdaptedQueuePool):
281
+ _queue_class = sqla_queue.FallbackAsyncAdaptedQueue # type: ignore[assignment] # noqa: E501
282
+
283
+
284
+ class NullPool(Pool):
285
+ """A Pool which does not pool connections.
286
+
287
+ Instead it literally opens and closes the underlying DB-API connection
288
+ per each connection open/close.
289
+
290
+ Reconnect-related functions such as ``recycle`` and connection
291
+ invalidation are not supported by this Pool implementation, since
292
+ no connections are held persistently.
293
+
294
+ The :class:`.NullPool` class **is compatible** with asyncio and
295
+ :func:`_asyncio.create_async_engine`.
296
+
297
+ """
298
+
299
+ def status(self) -> str:
300
+ return "NullPool"
301
+
302
+ def _do_return_conn(self, record: ConnectionPoolEntry) -> None:
303
+ record.close()
304
+
305
+ def _do_get(self) -> ConnectionPoolEntry:
306
+ return self._create_connection()
307
+
308
+ def recreate(self) -> NullPool:
309
+ self.logger.info("Pool recreating")
310
+
311
+ return self.__class__(
312
+ self._creator,
313
+ recycle=self._recycle,
314
+ echo=self.echo,
315
+ logging_name=self._orig_logging_name,
316
+ reset_on_return=self._reset_on_return,
317
+ pre_ping=self._pre_ping,
318
+ _dispatch=self.dispatch,
319
+ dialect=self._dialect,
320
+ )
321
+
322
+ def dispose(self) -> None:
323
+ pass
324
+
325
+
326
+ class SingletonThreadPool(Pool):
327
+ """A Pool that maintains one connection per thread.
328
+
329
+ Maintains one connection per each thread, never moving a connection to a
330
+ thread other than the one which it was created in.
331
+
332
+ .. warning:: the :class:`.SingletonThreadPool` will call ``.close()``
333
+ on arbitrary connections that exist beyond the size setting of
334
+ ``pool_size``, e.g. if more unique **thread identities**
335
+ than what ``pool_size`` states are used. This cleanup is
336
+ non-deterministic and not sensitive to whether or not the connections
337
+ linked to those thread identities are currently in use.
338
+
339
+ :class:`.SingletonThreadPool` may be improved in a future release,
340
+ however in its current status it is generally used only for test
341
+ scenarios using a SQLite ``:memory:`` database and is not recommended
342
+ for production use.
343
+
344
+ The :class:`.SingletonThreadPool` class **is not compatible** with asyncio
345
+ and :func:`_asyncio.create_async_engine`.
346
+
347
+
348
+ Options are the same as those of :class:`_pool.Pool`, as well as:
349
+
350
+ :param pool_size: The number of threads in which to maintain connections
351
+ at once. Defaults to five.
352
+
353
+ :class:`.SingletonThreadPool` is used by the SQLite dialect
354
+ automatically when a memory-based database is used.
355
+ See :ref:`sqlite_toplevel`.
356
+
357
+ """
358
+
359
+ _is_asyncio = False
360
+
361
+ def __init__(
362
+ self,
363
+ creator: Union[_CreatorFnType, _CreatorWRecFnType],
364
+ pool_size: int = 5,
365
+ **kw: Any,
366
+ ):
367
+ Pool.__init__(self, creator, **kw)
368
+ self._conn = threading.local()
369
+ self._fairy = threading.local()
370
+ self._all_conns: Set[ConnectionPoolEntry] = set()
371
+ self.size = pool_size
372
+
373
+ def recreate(self) -> SingletonThreadPool:
374
+ self.logger.info("Pool recreating")
375
+ return self.__class__(
376
+ self._creator,
377
+ pool_size=self.size,
378
+ recycle=self._recycle,
379
+ echo=self.echo,
380
+ pre_ping=self._pre_ping,
381
+ logging_name=self._orig_logging_name,
382
+ reset_on_return=self._reset_on_return,
383
+ _dispatch=self.dispatch,
384
+ dialect=self._dialect,
385
+ )
386
+
387
+ def _transfer_from(
388
+ self, other_singleton_pool: SingletonThreadPool
389
+ ) -> None:
390
+ # used by the test suite to make a new engine / pool without
391
+ # losing the state of an existing SQLite :memory: connection
392
+ assert not hasattr(other_singleton_pool._fairy, "current")
393
+ self._conn = other_singleton_pool._conn
394
+ self._all_conns = other_singleton_pool._all_conns
395
+
396
+ def dispose(self) -> None:
397
+ """Dispose of this pool."""
398
+
399
+ for conn in self._all_conns:
400
+ try:
401
+ conn.close()
402
+ except Exception:
403
+ # pysqlite won't even let you close a conn from a thread
404
+ # that didn't create it
405
+ pass
406
+
407
+ self._all_conns.clear()
408
+
409
+ def _cleanup(self) -> None:
410
+ while len(self._all_conns) >= self.size:
411
+ c = self._all_conns.pop()
412
+ c.close()
413
+
414
+ def status(self) -> str:
415
+ return "SingletonThreadPool id:%d size: %d" % (
416
+ id(self),
417
+ len(self._all_conns),
418
+ )
419
+
420
+ def _do_return_conn(self, record: ConnectionPoolEntry) -> None:
421
+ try:
422
+ del self._fairy.current
423
+ except AttributeError:
424
+ pass
425
+
426
+ def _do_get(self) -> ConnectionPoolEntry:
427
+ try:
428
+ if TYPE_CHECKING:
429
+ c = cast(ConnectionPoolEntry, self._conn.current())
430
+ else:
431
+ c = self._conn.current()
432
+ if c:
433
+ return c
434
+ except AttributeError:
435
+ pass
436
+ c = self._create_connection()
437
+ self._conn.current = weakref.ref(c)
438
+ if len(self._all_conns) >= self.size:
439
+ self._cleanup()
440
+ self._all_conns.add(c)
441
+ return c
442
+
443
+ def connect(self) -> PoolProxiedConnection:
444
+ # vendored from Pool to include the now removed use_threadlocal
445
+ # behavior
446
+ try:
447
+ rec = cast(_ConnectionFairy, self._fairy.current())
448
+ except AttributeError:
449
+ pass
450
+ else:
451
+ if rec is not None:
452
+ return rec._checkout_existing()
453
+
454
+ return _ConnectionFairy._checkout(self, self._fairy)
455
+
456
+
457
+ class StaticPool(Pool):
458
+ """A Pool of exactly one connection, used for all requests.
459
+
460
+ Reconnect-related functions such as ``recycle`` and connection
461
+ invalidation (which is also used to support auto-reconnect) are only
462
+ partially supported right now and may not yield good results.
463
+
464
+ The :class:`.StaticPool` class **is compatible** with asyncio and
465
+ :func:`_asyncio.create_async_engine`.
466
+
467
+ """
468
+
469
+ @util.memoized_property
470
+ def connection(self) -> _ConnectionRecord:
471
+ return _ConnectionRecord(self)
472
+
473
+ def status(self) -> str:
474
+ return "StaticPool"
475
+
476
+ def dispose(self) -> None:
477
+ if (
478
+ "connection" in self.__dict__
479
+ and self.connection.dbapi_connection is not None
480
+ ):
481
+ self.connection.close()
482
+ del self.__dict__["connection"]
483
+
484
+ def recreate(self) -> StaticPool:
485
+ self.logger.info("Pool recreating")
486
+ return self.__class__(
487
+ creator=self._creator,
488
+ recycle=self._recycle,
489
+ reset_on_return=self._reset_on_return,
490
+ pre_ping=self._pre_ping,
491
+ echo=self.echo,
492
+ logging_name=self._orig_logging_name,
493
+ _dispatch=self.dispatch,
494
+ dialect=self._dialect,
495
+ )
496
+
497
+ def _transfer_from(self, other_static_pool: StaticPool) -> None:
498
+ # used by the test suite to make a new engine / pool without
499
+ # losing the state of an existing SQLite :memory: connection
500
+ def creator(rec: ConnectionPoolEntry) -> DBAPIConnection:
501
+ conn = other_static_pool.connection.dbapi_connection
502
+ assert conn is not None
503
+ return conn
504
+
505
+ self._invoke_creator = creator
506
+
507
+ def _create_connection(self) -> ConnectionPoolEntry:
508
+ raise NotImplementedError()
509
+
510
+ def _do_return_conn(self, record: ConnectionPoolEntry) -> None:
511
+ pass
512
+
513
+ def _do_get(self) -> ConnectionPoolEntry:
514
+ rec = self.connection
515
+ if rec._is_hard_or_soft_invalidated():
516
+ del self.__dict__["connection"]
517
+ rec = self.connection
518
+
519
+ return rec
520
+
521
+
522
+ class AssertionPool(Pool):
523
+ """A :class:`_pool.Pool` that allows at most one checked out connection at
524
+ any given time.
525
+
526
+ This will raise an exception if more than one connection is checked out
527
+ at a time. Useful for debugging code that is using more connections
528
+ than desired.
529
+
530
+ The :class:`.AssertionPool` class **is compatible** with asyncio and
531
+ :func:`_asyncio.create_async_engine`.
532
+
533
+ """
534
+
535
+ _conn: Optional[ConnectionPoolEntry]
536
+ _checkout_traceback: Optional[List[str]]
537
+
538
+ def __init__(self, *args: Any, **kw: Any):
539
+ self._conn = None
540
+ self._checked_out = False
541
+ self._store_traceback = kw.pop("store_traceback", True)
542
+ self._checkout_traceback = None
543
+ Pool.__init__(self, *args, **kw)
544
+
545
+ def status(self) -> str:
546
+ return "AssertionPool"
547
+
548
+ def _do_return_conn(self, record: ConnectionPoolEntry) -> None:
549
+ if not self._checked_out:
550
+ raise AssertionError("connection is not checked out")
551
+ self._checked_out = False
552
+ assert record is self._conn
553
+
554
+ def dispose(self) -> None:
555
+ self._checked_out = False
556
+ if self._conn:
557
+ self._conn.close()
558
+
559
+ def recreate(self) -> AssertionPool:
560
+ self.logger.info("Pool recreating")
561
+ return self.__class__(
562
+ self._creator,
563
+ echo=self.echo,
564
+ pre_ping=self._pre_ping,
565
+ recycle=self._recycle,
566
+ reset_on_return=self._reset_on_return,
567
+ logging_name=self._orig_logging_name,
568
+ _dispatch=self.dispatch,
569
+ dialect=self._dialect,
570
+ )
571
+
572
+ def _do_get(self) -> ConnectionPoolEntry:
573
+ if self._checked_out:
574
+ if self._checkout_traceback:
575
+ suffix = " at:\n%s" % "".join(
576
+ chop_traceback(self._checkout_traceback)
577
+ )
578
+ else:
579
+ suffix = ""
580
+ raise AssertionError("connection is already checked out" + suffix)
581
+
582
+ if not self._conn:
583
+ self._conn = self._create_connection()
584
+
585
+ self._checked_out = True
586
+ if self._store_traceback:
587
+ self._checkout_traceback = traceback.format_stack()
588
+ return self._conn
sqlalchemy/py.typed ADDED
File without changes
sqlalchemy/schema.py ADDED
@@ -0,0 +1,69 @@
1
+ # schema.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
+ """Compatibility namespace for sqlalchemy.sql.schema and related."""
9
+
10
+ from __future__ import annotations
11
+
12
+ from .sql.base import SchemaVisitor as SchemaVisitor
13
+ from .sql.ddl import _CreateDropBase as _CreateDropBase
14
+ from .sql.ddl import _DropView as _DropView
15
+ from .sql.ddl import AddConstraint as AddConstraint
16
+ from .sql.ddl import BaseDDLElement as BaseDDLElement
17
+ from .sql.ddl import CreateColumn as CreateColumn
18
+ from .sql.ddl import CreateIndex as CreateIndex
19
+ from .sql.ddl import CreateSchema as CreateSchema
20
+ from .sql.ddl import CreateSequence as CreateSequence
21
+ from .sql.ddl import CreateTable as CreateTable
22
+ from .sql.ddl import DDL as DDL
23
+ from .sql.ddl import DDLElement as DDLElement
24
+ from .sql.ddl import DropColumnComment as DropColumnComment
25
+ from .sql.ddl import DropConstraint as DropConstraint
26
+ from .sql.ddl import DropConstraintComment as DropConstraintComment
27
+ from .sql.ddl import DropIndex as DropIndex
28
+ from .sql.ddl import DropSchema as DropSchema
29
+ from .sql.ddl import DropSequence as DropSequence
30
+ from .sql.ddl import DropTable as DropTable
31
+ from .sql.ddl import DropTableComment as DropTableComment
32
+ from .sql.ddl import ExecutableDDLElement as ExecutableDDLElement
33
+ from .sql.ddl import InvokeDDLBase as InvokeDDLBase
34
+ from .sql.ddl import SetColumnComment as SetColumnComment
35
+ from .sql.ddl import SetConstraintComment as SetConstraintComment
36
+ from .sql.ddl import SetTableComment as SetTableComment
37
+ from .sql.ddl import sort_tables as sort_tables
38
+ from .sql.ddl import (
39
+ sort_tables_and_constraints as sort_tables_and_constraints,
40
+ )
41
+ from .sql.naming import conv as conv
42
+ from .sql.schema import _get_table_key as _get_table_key
43
+ from .sql.schema import BLANK_SCHEMA as BLANK_SCHEMA
44
+ from .sql.schema import CheckConstraint as CheckConstraint
45
+ from .sql.schema import Column as Column
46
+ from .sql.schema import (
47
+ ColumnCollectionConstraint as ColumnCollectionConstraint,
48
+ )
49
+ from .sql.schema import ColumnCollectionMixin as ColumnCollectionMixin
50
+ from .sql.schema import ColumnDefault as ColumnDefault
51
+ from .sql.schema import Computed as Computed
52
+ from .sql.schema import Constraint as Constraint
53
+ from .sql.schema import DefaultClause as DefaultClause
54
+ from .sql.schema import DefaultGenerator as DefaultGenerator
55
+ from .sql.schema import FetchedValue as FetchedValue
56
+ from .sql.schema import ForeignKey as ForeignKey
57
+ from .sql.schema import ForeignKeyConstraint as ForeignKeyConstraint
58
+ from .sql.schema import HasConditionalDDL as HasConditionalDDL
59
+ from .sql.schema import Identity as Identity
60
+ from .sql.schema import Index as Index
61
+ from .sql.schema import insert_sentinel as insert_sentinel
62
+ from .sql.schema import MetaData as MetaData
63
+ from .sql.schema import PrimaryKeyConstraint as PrimaryKeyConstraint
64
+ from .sql.schema import SchemaConst as SchemaConst
65
+ from .sql.schema import SchemaItem as SchemaItem
66
+ from .sql.schema import SchemaVisitable as SchemaVisitable
67
+ from .sql.schema import Sequence as Sequence
68
+ from .sql.schema import Table as Table
69
+ from .sql.schema import UniqueConstraint as UniqueConstraint