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,156 @@
1
+ # sql/__init__.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
+ from typing import Any
8
+ from typing import TYPE_CHECKING
9
+
10
+ from ._typing import ColumnExpressionArgument as ColumnExpressionArgument
11
+ from ._typing import NotNullable as NotNullable
12
+ from ._typing import Nullable as Nullable
13
+ from .base import Executable as Executable
14
+ from .base import ExecutableStatement as ExecutableStatement
15
+ from .base import SyntaxExtension as SyntaxExtension
16
+ from .compiler import COLLECT_CARTESIAN_PRODUCTS as COLLECT_CARTESIAN_PRODUCTS
17
+ from .compiler import FROM_LINTING as FROM_LINTING
18
+ from .compiler import NO_LINTING as NO_LINTING
19
+ from .compiler import WARN_LINTING as WARN_LINTING
20
+ from .ddl import BaseDDLElement as BaseDDLElement
21
+ from .ddl import CheckFirst as CheckFirst
22
+ from .ddl import DDL as DDL
23
+ from .ddl import DDLElement as DDLElement
24
+ from .ddl import ExecutableDDLElement as ExecutableDDLElement
25
+ from .expression import aggregate_order_by as aggregate_order_by
26
+ from .expression import Alias as Alias
27
+ from .expression import alias as alias
28
+ from .expression import all_ as all_
29
+ from .expression import and_ as and_
30
+ from .expression import any_ as any_
31
+ from .expression import asc as asc
32
+ from .expression import between as between
33
+ from .expression import bindparam as bindparam
34
+ from .expression import case as case
35
+ from .expression import cast as cast
36
+ from .expression import ClauseElement as ClauseElement
37
+ from .expression import collate as collate
38
+ from .expression import column as column
39
+ from .expression import ColumnCollection as ColumnCollection
40
+ from .expression import ColumnElement as ColumnElement
41
+ from .expression import CompoundSelect as CompoundSelect
42
+ from .expression import cte as cte
43
+ from .expression import Delete as Delete
44
+ from .expression import delete as delete
45
+ from .expression import desc as desc
46
+ from .expression import distinct as distinct
47
+ from .expression import except_ as except_
48
+ from .expression import except_all as except_all
49
+ from .expression import exists as exists
50
+ from .expression import extract as extract
51
+ from .expression import false as false
52
+ from .expression import False_ as False_
53
+ from .expression import from_dml_column as from_dml_column
54
+ from .expression import FromClause as FromClause
55
+ from .expression import func as func
56
+ from .expression import funcfilter as funcfilter
57
+ from .expression import Insert as Insert
58
+ from .expression import insert as insert
59
+ from .expression import intersect as intersect
60
+ from .expression import intersect_all as intersect_all
61
+ from .expression import Join as Join
62
+ from .expression import join as join
63
+ from .expression import label as label
64
+ from .expression import LABEL_STYLE_DEFAULT as LABEL_STYLE_DEFAULT
65
+ from .expression import (
66
+ LABEL_STYLE_DISAMBIGUATE_ONLY as LABEL_STYLE_DISAMBIGUATE_ONLY,
67
+ )
68
+ from .expression import LABEL_STYLE_NONE as LABEL_STYLE_NONE
69
+ from .expression import (
70
+ LABEL_STYLE_TABLENAME_PLUS_COL as LABEL_STYLE_TABLENAME_PLUS_COL,
71
+ )
72
+ from .expression import lambda_stmt as lambda_stmt
73
+ from .expression import LambdaElement as LambdaElement
74
+ from .expression import lateral as lateral
75
+ from .expression import literal as literal
76
+ from .expression import literal_column as literal_column
77
+ from .expression import modifier as modifier
78
+ from .expression import not_ as not_
79
+ from .expression import null as null
80
+ from .expression import nulls_first as nulls_first
81
+ from .expression import nulls_last as nulls_last
82
+ from .expression import nullsfirst as nullsfirst
83
+ from .expression import nullslast as nullslast
84
+ from .expression import or_ as or_
85
+ from .expression import outerjoin as outerjoin
86
+ from .expression import outparam as outparam
87
+ from .expression import over as over
88
+ from .expression import quoted_name as quoted_name
89
+ from .expression import Select as Select
90
+ from .expression import select as select
91
+ from .expression import Selectable as Selectable
92
+ from .expression import SelectLabelStyle as SelectLabelStyle
93
+ from .expression import SQLColumnExpression as SQLColumnExpression
94
+ from .expression import StatementLambdaElement as StatementLambdaElement
95
+ from .expression import Subquery as Subquery
96
+ from .expression import table as table
97
+ from .expression import TableClause as TableClause
98
+ from .expression import TableSample as TableSample
99
+ from .expression import tablesample as tablesample
100
+ from .expression import TableValuedAlias as TableValuedAlias
101
+ from .expression import TableValuedColumn as TableValuedColumn
102
+ from .expression import text as text
103
+ from .expression import TextClause as TextClause
104
+ from .expression import true as true
105
+ from .expression import True_ as True_
106
+ from .expression import try_cast as try_cast
107
+ from .expression import TString as TString
108
+ from .expression import tstring as tstring
109
+ from .expression import tuple_ as tuple_
110
+ from .expression import type_coerce as type_coerce
111
+ from .expression import union as union
112
+ from .expression import union_all as union_all
113
+ from .expression import Update as Update
114
+ from .expression import update as update
115
+ from .expression import Values as Values
116
+ from .expression import values as values
117
+ from .expression import within_group as within_group
118
+ from .expression import WriteableColumnCollection as WriteableColumnCollection
119
+ from .visitors import ClauseVisitor as ClauseVisitor
120
+
121
+
122
+ def __go(lcls: Any) -> None:
123
+ from .. import util as _sa_util
124
+
125
+ from . import base
126
+ from . import coercions
127
+ from . import elements
128
+ from . import lambdas
129
+ from . import selectable
130
+ from . import schema
131
+ from . import traversals
132
+ from . import type_api
133
+
134
+ if not TYPE_CHECKING:
135
+ base.coercions = elements.coercions = coercions
136
+ base.elements = elements
137
+ base.type_api = type_api
138
+ coercions.elements = elements
139
+ coercions.lambdas = lambdas
140
+ coercions.schema = schema
141
+ coercions.selectable = selectable
142
+
143
+ from .annotation import _prepare_annotations
144
+ from .annotation import Annotated
145
+ from .elements import AnnotatedColumnElement
146
+ from .elements import ClauseList
147
+ from .selectable import AnnotatedFromClause
148
+
149
+ _prepare_annotations(ColumnElement, AnnotatedColumnElement)
150
+ _prepare_annotations(FromClause, AnnotatedFromClause)
151
+ _prepare_annotations(ClauseList, Annotated)
152
+
153
+ _sa_util.preloaded.import_prefix("sqlalchemy.sql")
154
+
155
+
156
+ __go(locals())
@@ -0,0 +1,397 @@
1
+ # sql/_annotated_cols.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
+ from __future__ import annotations
8
+
9
+ from typing import Any
10
+ from typing import Generic
11
+ from typing import Literal
12
+ from typing import NoReturn
13
+ from typing import overload
14
+ from typing import Protocol
15
+ from typing import TYPE_CHECKING
16
+
17
+ from . import sqltypes
18
+ from ._typing import _T
19
+ from ._typing import _Ts
20
+ from .base import _NoArg
21
+ from .base import ReadOnlyColumnCollection
22
+ from .. import util
23
+ from ..exc import ArgumentError
24
+ from ..exc import InvalidRequestError
25
+ from ..util import typing as sa_typing
26
+ from ..util.langhelpers import dunders_re
27
+ from ..util.typing import Never
28
+ from ..util.typing import Self
29
+ from ..util.typing import TypeVar
30
+ from ..util.typing import Unpack
31
+
32
+ if TYPE_CHECKING:
33
+ from .elements import ColumnClause # noqa (for zimports)
34
+ from .elements import KeyedColumnElement # noqa (for zimports)
35
+ from .schema import Column
36
+ from .type_api import TypeEngine
37
+ from ..util.typing import _AnnotationScanType
38
+
39
+
40
+ class Named(Generic[_T]):
41
+ """A named descriptor that is interpreted by SQLAlchemy in various ways.
42
+
43
+ .. seealso::
44
+
45
+ :class:`_schema.TypedColumns` Define table columns using this
46
+ descriptor.
47
+
48
+ .. versionadded:: 2.1.0b2
49
+ """
50
+
51
+ __slots__ = ()
52
+
53
+ key: str
54
+ if TYPE_CHECKING:
55
+
56
+ # NOTE: this overload prevents users from using the a TypedColumns
57
+ # class like if it were an orm mapped class
58
+ @overload
59
+ def __get__(self, instance: None, owner: Any) -> Never: ...
60
+
61
+ @overload
62
+ def __get__(
63
+ self, instance: TypedColumns, owner: Any
64
+ ) -> Column[_T]: ...
65
+ @overload
66
+ def __get__(self, instance: Any, owner: Any) -> Self: ...
67
+
68
+ def __get__(self, instance: object | None, owner: Any) -> Any: ...
69
+
70
+
71
+ # NOTE: TypedColumns subclasses are ignored by the ORM mapping process
72
+ class TypedColumns(ReadOnlyColumnCollection[str, "Column[Any]"]):
73
+ """Class that generally represent the typed columns of a :class:`.Table`,
74
+ but can be used with most :class:`_sql.FromClause` subclasses with the
75
+ :meth:`_sql.FromClause.with_cols` method.
76
+
77
+ This is a "typing only" class that is never instantiated at runtime: the
78
+ type checker will think that this class is exposed as the ``table.c``
79
+ attribute, but in reality a normal :class:`_schema.ColumnCollection` is
80
+ used at runtime.
81
+
82
+ Subclasses should just list the columns as class attributes, without
83
+ specifying method or other non column members.
84
+
85
+ To resolve the columns, a simplified version of the ORM logic is used,
86
+ in particular, columns can be declared by:
87
+
88
+ * directly instantiating them, to declare constraint, custom SQL types and
89
+ additional column options;
90
+ * using only a :class:`.Named` or :class:`_schema.Column` type annotation,
91
+ where nullability and SQL type will be inferred by the python type
92
+ provided.
93
+ Type inference is available for a common subset of python types.
94
+ * a mix of both, where the instance can be used to declare
95
+ constraints and other column options while the annotation will be used
96
+ to set the SQL type and nullability if not provided by the instance.
97
+
98
+ In all cases the name is inferred from the attribute name, unless
99
+ explicitly provided.
100
+
101
+ .. note::
102
+
103
+ The generated table will create a copy of any column instance assigned
104
+ as attributes of this class, so columns should be accessed only via
105
+ the ``table.c`` collection, not using this class directly.
106
+
107
+ Example of the inference behavior::
108
+
109
+ from sqlalchemy import Column, Integer, Named, String, TypedColumns
110
+
111
+
112
+ class tbl_cols(TypedColumns):
113
+ # the name will be set to ``id``, type is inferred as Column[int]
114
+ id = Column(Integer, primary_key=True)
115
+
116
+ # not null String column is generated
117
+ name: Named[str]
118
+
119
+ # nullable Double column is generated
120
+ weight: Named[float | None]
121
+
122
+ # nullable Integer column, with sql name 'user_age'
123
+ age: Named[int | None] = Column("user_age")
124
+
125
+ # not null column with type String(42)
126
+ middle_name: Named[str] = Column(String(42))
127
+
128
+ Mixins and subclasses are also supported::
129
+
130
+ class with_id(TypedColumns):
131
+ id = Column(Integer, primary_key=True)
132
+
133
+
134
+ class named_cols(TypedColumns):
135
+ name: Named[str]
136
+ description: Named[str | None]
137
+
138
+
139
+ class product_cols(named_cols, with_id):
140
+ ean: Named[str] = Column(unique=True)
141
+
142
+
143
+ product = Table("product", metadata, product_cols)
144
+
145
+
146
+ class office_cols(named_cols, with_id):
147
+ address: Named[str]
148
+
149
+
150
+ office = Table("office", metadata, office_cols)
151
+
152
+ The positional types returned when selecting the table can
153
+ be optionally declared by specifying a :attr:`.HasRowPos.__row_pos__`
154
+ annotation::
155
+
156
+ from sqlalchemy import select
157
+
158
+
159
+ class some_cols(TypedColumns):
160
+ id = Column(Integer, primary_key=True)
161
+ name: Named[str]
162
+ weight: Named[float | None]
163
+
164
+ __row_pos__: tuple[int, str, float | None]
165
+
166
+
167
+ some_table = Table("st", metadata, some_cols)
168
+
169
+ # both will be typed as Select[int, str, float | None]
170
+ stmt1 = some_table.select()
171
+ stmt2 = select(some_table)
172
+
173
+ .. seealso::
174
+
175
+ :class:`.Table` for usage details on how to use this class to
176
+ create a table instance.
177
+
178
+ :meth:`_sql.FromClause.with_cols` to apply a :class:`.TypedColumns`
179
+ to a from clause.
180
+
181
+ .. versionadded:: 2.1.0b2
182
+ """ # noqa
183
+
184
+ __slots__ = ()
185
+
186
+ if not TYPE_CHECKING:
187
+
188
+ def __new__(cls, *args: Any, **kwargs: Any) -> NoReturn:
189
+ raise InvalidRequestError(
190
+ "Cannot instantiate a TypedColumns object."
191
+ )
192
+
193
+ def __init_subclass__(cls) -> None:
194
+ methods = {
195
+ name
196
+ for name, value in cls.__dict__.items()
197
+ if not dunders_re.match(name) and callable(value)
198
+ }
199
+ if methods:
200
+ raise InvalidRequestError(
201
+ "TypedColumns subclasses may not define methods. "
202
+ f"Found {sorted(methods)}"
203
+ )
204
+
205
+
206
+ _KeyColCC_co = TypeVar(
207
+ "_KeyColCC_co",
208
+ bound=ReadOnlyColumnCollection[str, "KeyedColumnElement[Any]"],
209
+ covariant=True,
210
+ default=ReadOnlyColumnCollection[str, "KeyedColumnElement[Any]"],
211
+ )
212
+ _ColClauseCC_co = TypeVar(
213
+ "_ColClauseCC_co",
214
+ bound=ReadOnlyColumnCollection[str, "ColumnClause[Any]"],
215
+ covariant=True,
216
+ default=ReadOnlyColumnCollection[str, "ColumnClause[Any]"],
217
+ )
218
+ _ColCC_co = TypeVar(
219
+ "_ColCC_co",
220
+ bound=ReadOnlyColumnCollection[str, "Column[Any]"],
221
+ covariant=True,
222
+ default=ReadOnlyColumnCollection[str, "Column[Any]"],
223
+ )
224
+
225
+ _TC = TypeVar("_TC", bound=TypedColumns)
226
+ _TC_co = TypeVar("_TC_co", bound=TypedColumns, covariant=True)
227
+
228
+
229
+ class HasRowPos(Protocol[Unpack[_Ts]]):
230
+ """Protocol for a :class:`_schema.TypedColumns` used to indicate the
231
+ positional types will be returned when selecting the table.
232
+
233
+ .. versionadded:: 2.1.0b2
234
+ """
235
+
236
+ __row_pos__: tuple[Unpack[_Ts]]
237
+ """A tuple that represents the types that will be returned when
238
+ selecting from the table.
239
+ """
240
+
241
+
242
+ @util.preload_module("sqlalchemy.sql.schema")
243
+ def _extract_columns_from_class(
244
+ table_columns_cls: type[TypedColumns],
245
+ ) -> list[Column[Any]]:
246
+ columns: dict[str, Column[Any]] = {}
247
+
248
+ Column = util.preloaded.sql_schema.Column
249
+ NULL_UNSPECIFIED = util.preloaded.sql_schema.NULL_UNSPECIFIED
250
+
251
+ for base in table_columns_cls.__mro__[::-1]:
252
+ if base in TypedColumns.__mro__:
253
+ continue
254
+
255
+ # _ClassScanAbstractConfig._cls_attr_resolver
256
+ cls_annotations = util.get_annotations(base)
257
+ cls_vars = vars(base)
258
+ items = [
259
+ (n, cls_vars.get(n), cls_annotations.get(n))
260
+ for n in util.merge_lists_w_ordering(
261
+ list(cls_vars), list(cls_annotations)
262
+ )
263
+ if not dunders_re.match(n)
264
+ ]
265
+ # --
266
+ for name, obj, annotation in items:
267
+ if obj is None:
268
+ assert annotation is not None
269
+ # no attribute, just annotation
270
+ extracted_type = _collect_annotation(
271
+ table_columns_cls, name, base.__module__, annotation
272
+ )
273
+ if extracted_type is _NoArg.NO_ARG:
274
+ raise ArgumentError(
275
+ "No type information could be extracted from "
276
+ f"annotation {annotation} for attribute "
277
+ f"'{base.__name__}.{name}'"
278
+ )
279
+ sqltype = _get_sqltype(extracted_type)
280
+ if sqltype is None:
281
+ raise ArgumentError(
282
+ f"Could not find a SQL type for type {extracted_type} "
283
+ f"obtained from annotation {annotation} in "
284
+ f"attribute '{base.__name__}.{name}'"
285
+ )
286
+ columns[name] = Column(
287
+ name,
288
+ sqltype,
289
+ nullable=sa_typing.includes_none(extracted_type),
290
+ )
291
+ elif isinstance(obj, Column):
292
+ # has attribute attribute
293
+ # _DeclarativeMapperConfig._produce_column_copies
294
+ # as with orm this case is not supported
295
+ for fk in obj.foreign_keys:
296
+ if (
297
+ fk._table_column is not None
298
+ and fk._table_column.table is None
299
+ ):
300
+ raise InvalidRequestError(
301
+ f"Column '{base.__name__}.{name}' with foreign "
302
+ "key to non-table-bound columns is not supported "
303
+ "when using a TypedColumns. If possible use the "
304
+ "qualified string name the column"
305
+ )
306
+
307
+ col = obj._copy()
308
+ # MapptedColumn.declarative_scan
309
+ if col.key == col.name and col.key != name:
310
+ col.key = name
311
+ if col.name is None:
312
+ col.name = name
313
+
314
+ sqltype = col.type
315
+ anno_sqltype = None
316
+ nullable: Literal[_NoArg.NO_ARG] | bool = _NoArg.NO_ARG
317
+ if annotation is not None:
318
+ # there is an annotation, extract the type
319
+ extracted_type = _collect_annotation(
320
+ table_columns_cls, name, base.__module__, annotation
321
+ )
322
+ if extracted_type is not _NoArg.NO_ARG:
323
+ anno_sqltype = _get_sqltype(extracted_type)
324
+ nullable = sa_typing.includes_none(extracted_type)
325
+
326
+ if sqltype._isnull:
327
+ if anno_sqltype is None and not col.foreign_keys:
328
+ raise ArgumentError(
329
+ "Python typing annotation is required for "
330
+ f"attribute '{base.__name__}.{name}' when "
331
+ "primary argument(s) for Column construct are "
332
+ "None or not present"
333
+ )
334
+ elif anno_sqltype is not None:
335
+ col._set_type(anno_sqltype)
336
+
337
+ if (
338
+ nullable is not _NoArg.NO_ARG
339
+ and col._user_defined_nullable is NULL_UNSPECIFIED
340
+ and not col.primary_key
341
+ ):
342
+ col.nullable = nullable
343
+ columns[name] = col
344
+ else:
345
+ raise ArgumentError(
346
+ f"Unexpected value for attribute '{base.__name__}.{name}'"
347
+ f". Expected a Column, not: {type(obj)}"
348
+ )
349
+
350
+ # Return columns as a list
351
+ return list(columns.values())
352
+
353
+
354
+ @util.preload_module("sqlalchemy.sql.schema")
355
+ def _collect_annotation(
356
+ cls: type[Any], name: str, module: str, raw_annotation: _AnnotationScanType
357
+ ) -> _AnnotationScanType | Literal[_NoArg.NO_ARG]:
358
+ Column = util.preloaded.sql_schema.Column
359
+
360
+ _locals = {"Column": Column, "Named": Named}
361
+ # _ClassScanAbstractConfig._collect_annotation & _extract_mapped_subtype
362
+ try:
363
+ annotation = sa_typing.de_stringify_annotation(
364
+ cls, raw_annotation, module, _locals
365
+ )
366
+ except Exception as e:
367
+ raise ArgumentError(
368
+ f"Could not interpret annotation {raw_annotation} for "
369
+ f"attribute '{cls.__name__}.{name}'"
370
+ ) from e
371
+
372
+ if (
373
+ not sa_typing.is_generic(annotation)
374
+ and isinstance(annotation, type)
375
+ and issubclass(annotation, (Column, Named))
376
+ ):
377
+ # no generic information, ignore
378
+ return _NoArg.NO_ARG
379
+ elif not sa_typing.is_origin_of_cls(annotation, (Column, Named)):
380
+ raise ArgumentError(
381
+ f"Annotation {raw_annotation} for attribute "
382
+ f"'{cls.__name__}.{name}' is not of type Named/Column[...]"
383
+ )
384
+ else:
385
+ assert len(annotation.__args__) == 1 # Column[int, int] raises
386
+ return annotation.__args__[0] # type: ignore[no-any-return]
387
+
388
+
389
+ def _get_sqltype(annotation: _AnnotationScanType) -> TypeEngine[Any] | None:
390
+ our_type = sa_typing.de_optionalize_union_types(annotation)
391
+ # simplified version of registry._resolve_type given no customizable
392
+ # type map
393
+ sql_type = sqltypes._type_map_get(our_type) # type: ignore[arg-type]
394
+ if sql_type is not None and not sql_type._isnull:
395
+ return sqltypes.to_instance(sql_type)
396
+ else:
397
+ return None
@@ -0,0 +1,132 @@
1
+ # sql/_dml_constructors.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 TYPE_CHECKING
11
+
12
+ from .dml import Delete
13
+ from .dml import Insert
14
+ from .dml import Update
15
+
16
+ if TYPE_CHECKING:
17
+ from ._typing import _DMLTableArgument
18
+
19
+
20
+ def insert(table: _DMLTableArgument) -> Insert:
21
+ """Construct an :class:`_expression.Insert` object.
22
+
23
+ E.g.::
24
+
25
+ from sqlalchemy import insert
26
+
27
+ stmt = insert(user_table).values(name="username", fullname="Full Username")
28
+
29
+ Similar functionality is available via the
30
+ :meth:`_expression.TableClause.insert` method on
31
+ :class:`_schema.Table`.
32
+
33
+ .. seealso::
34
+
35
+ :ref:`tutorial_core_insert` - in the :ref:`unified_tutorial`
36
+
37
+
38
+ :param table: :class:`_expression.TableClause`
39
+ which is the subject of the
40
+ insert.
41
+
42
+ :param values: collection of values to be inserted; see
43
+ :meth:`_expression.Insert.values`
44
+ for a description of allowed formats here.
45
+ Can be omitted entirely; a :class:`_expression.Insert` construct
46
+ will also dynamically render the VALUES clause at execution time
47
+ based on the parameters passed to :meth:`_engine.Connection.execute`.
48
+
49
+ :param inline: if True, no attempt will be made to retrieve the
50
+ SQL-generated default values to be provided within the statement;
51
+ in particular,
52
+ this allows SQL expressions to be rendered 'inline' within the
53
+ statement without the need to pre-execute them beforehand; for
54
+ backends that support "returning", this turns off the "implicit
55
+ returning" feature for the statement.
56
+
57
+ If both :paramref:`_expression.insert.values` and compile-time bind
58
+ parameters are present, the compile-time bind parameters override the
59
+ information specified within :paramref:`_expression.insert.values` on a
60
+ per-key basis.
61
+
62
+ The keys within :paramref:`_expression.Insert.values` can be either
63
+ :class:`~sqlalchemy.schema.Column` objects or their string
64
+ identifiers. Each key may reference one of:
65
+
66
+ * a literal data value (i.e. string, number, etc.);
67
+ * a Column object;
68
+ * a SELECT statement.
69
+
70
+ If a ``SELECT`` statement is specified which references this
71
+ ``INSERT`` statement's table, the statement will be correlated
72
+ against the ``INSERT`` statement.
73
+
74
+ .. seealso::
75
+
76
+ :ref:`tutorial_core_insert` - in the :ref:`unified_tutorial`
77
+
78
+ """ # noqa: E501
79
+ return Insert(table)
80
+
81
+
82
+ def update(table: _DMLTableArgument) -> Update:
83
+ r"""Construct an :class:`_expression.Update` object.
84
+
85
+ E.g.::
86
+
87
+ from sqlalchemy import update
88
+
89
+ stmt = (
90
+ update(user_table).where(user_table.c.id == 5).values(name="user #5")
91
+ )
92
+
93
+ Similar functionality is available via the
94
+ :meth:`_expression.TableClause.update` method on
95
+ :class:`_schema.Table`.
96
+
97
+ :param table: A :class:`_schema.Table`
98
+ object representing the database
99
+ table to be updated.
100
+
101
+
102
+ .. seealso::
103
+
104
+ :ref:`tutorial_core_update_delete` - in the :ref:`unified_tutorial`
105
+
106
+
107
+ """ # noqa: E501
108
+ return Update(table)
109
+
110
+
111
+ def delete(table: _DMLTableArgument) -> Delete:
112
+ r"""Construct :class:`_expression.Delete` object.
113
+
114
+ E.g.::
115
+
116
+ from sqlalchemy import delete
117
+
118
+ stmt = delete(user_table).where(user_table.c.id == 5)
119
+
120
+ Similar functionality is available via the
121
+ :meth:`_expression.TableClause.delete` method on
122
+ :class:`_schema.Table`.
123
+
124
+ :param table: The table to delete rows from.
125
+
126
+ .. seealso::
127
+
128
+ :ref:`tutorial_core_update_delete` - in the :ref:`unified_tutorial`
129
+
130
+
131
+ """
132
+ return Delete(table)