sqlspec 0.13.1__py3-none-any.whl → 0.16.2__py3-none-any.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.

Potentially problematic release.


This version of sqlspec might be problematic. Click here for more details.

Files changed (185) hide show
  1. sqlspec/__init__.py +71 -8
  2. sqlspec/__main__.py +12 -0
  3. sqlspec/__metadata__.py +1 -3
  4. sqlspec/_serialization.py +1 -2
  5. sqlspec/_sql.py +930 -136
  6. sqlspec/_typing.py +278 -142
  7. sqlspec/adapters/adbc/__init__.py +4 -3
  8. sqlspec/adapters/adbc/_types.py +12 -0
  9. sqlspec/adapters/adbc/config.py +116 -285
  10. sqlspec/adapters/adbc/driver.py +462 -340
  11. sqlspec/adapters/aiosqlite/__init__.py +18 -3
  12. sqlspec/adapters/aiosqlite/_types.py +13 -0
  13. sqlspec/adapters/aiosqlite/config.py +202 -150
  14. sqlspec/adapters/aiosqlite/driver.py +226 -247
  15. sqlspec/adapters/asyncmy/__init__.py +18 -3
  16. sqlspec/adapters/asyncmy/_types.py +12 -0
  17. sqlspec/adapters/asyncmy/config.py +80 -199
  18. sqlspec/adapters/asyncmy/driver.py +257 -215
  19. sqlspec/adapters/asyncpg/__init__.py +19 -4
  20. sqlspec/adapters/asyncpg/_types.py +17 -0
  21. sqlspec/adapters/asyncpg/config.py +81 -214
  22. sqlspec/adapters/asyncpg/driver.py +284 -359
  23. sqlspec/adapters/bigquery/__init__.py +17 -3
  24. sqlspec/adapters/bigquery/_types.py +12 -0
  25. sqlspec/adapters/bigquery/config.py +191 -299
  26. sqlspec/adapters/bigquery/driver.py +474 -634
  27. sqlspec/adapters/duckdb/__init__.py +14 -3
  28. sqlspec/adapters/duckdb/_types.py +12 -0
  29. sqlspec/adapters/duckdb/config.py +414 -397
  30. sqlspec/adapters/duckdb/driver.py +342 -393
  31. sqlspec/adapters/oracledb/__init__.py +19 -5
  32. sqlspec/adapters/oracledb/_types.py +14 -0
  33. sqlspec/adapters/oracledb/config.py +123 -458
  34. sqlspec/adapters/oracledb/driver.py +505 -531
  35. sqlspec/adapters/psqlpy/__init__.py +13 -3
  36. sqlspec/adapters/psqlpy/_types.py +11 -0
  37. sqlspec/adapters/psqlpy/config.py +93 -307
  38. sqlspec/adapters/psqlpy/driver.py +504 -213
  39. sqlspec/adapters/psycopg/__init__.py +19 -5
  40. sqlspec/adapters/psycopg/_types.py +17 -0
  41. sqlspec/adapters/psycopg/config.py +143 -472
  42. sqlspec/adapters/psycopg/driver.py +704 -825
  43. sqlspec/adapters/sqlite/__init__.py +14 -3
  44. sqlspec/adapters/sqlite/_types.py +11 -0
  45. sqlspec/adapters/sqlite/config.py +208 -142
  46. sqlspec/adapters/sqlite/driver.py +263 -278
  47. sqlspec/base.py +105 -9
  48. sqlspec/{statement/builder → builder}/__init__.py +12 -14
  49. sqlspec/{statement/builder/base.py → builder/_base.py} +184 -86
  50. sqlspec/{statement/builder/column.py → builder/_column.py} +97 -60
  51. sqlspec/{statement/builder/ddl.py → builder/_ddl.py} +61 -131
  52. sqlspec/{statement/builder → builder}/_ddl_utils.py +4 -10
  53. sqlspec/{statement/builder/delete.py → builder/_delete.py} +10 -30
  54. sqlspec/builder/_insert.py +421 -0
  55. sqlspec/builder/_merge.py +71 -0
  56. sqlspec/{statement/builder → builder}/_parsing_utils.py +49 -26
  57. sqlspec/builder/_select.py +170 -0
  58. sqlspec/{statement/builder/update.py → builder/_update.py} +16 -20
  59. sqlspec/builder/mixins/__init__.py +55 -0
  60. sqlspec/builder/mixins/_cte_and_set_ops.py +222 -0
  61. sqlspec/{statement/builder/mixins/_delete_from.py → builder/mixins/_delete_operations.py} +8 -1
  62. sqlspec/builder/mixins/_insert_operations.py +244 -0
  63. sqlspec/{statement/builder/mixins/_join.py → builder/mixins/_join_operations.py} +45 -13
  64. sqlspec/{statement/builder/mixins/_merge_clauses.py → builder/mixins/_merge_operations.py} +188 -30
  65. sqlspec/builder/mixins/_order_limit_operations.py +135 -0
  66. sqlspec/builder/mixins/_pivot_operations.py +153 -0
  67. sqlspec/builder/mixins/_select_operations.py +604 -0
  68. sqlspec/builder/mixins/_update_operations.py +202 -0
  69. sqlspec/builder/mixins/_where_clause.py +644 -0
  70. sqlspec/cli.py +247 -0
  71. sqlspec/config.py +183 -138
  72. sqlspec/core/__init__.py +63 -0
  73. sqlspec/core/cache.py +871 -0
  74. sqlspec/core/compiler.py +417 -0
  75. sqlspec/core/filters.py +830 -0
  76. sqlspec/core/hashing.py +310 -0
  77. sqlspec/core/parameters.py +1237 -0
  78. sqlspec/core/result.py +677 -0
  79. sqlspec/{statement → core}/splitter.py +321 -191
  80. sqlspec/core/statement.py +676 -0
  81. sqlspec/driver/__init__.py +7 -10
  82. sqlspec/driver/_async.py +422 -163
  83. sqlspec/driver/_common.py +545 -287
  84. sqlspec/driver/_sync.py +426 -160
  85. sqlspec/driver/mixins/__init__.py +2 -13
  86. sqlspec/driver/mixins/_result_tools.py +193 -0
  87. sqlspec/driver/mixins/_sql_translator.py +65 -14
  88. sqlspec/exceptions.py +5 -252
  89. sqlspec/extensions/aiosql/adapter.py +93 -96
  90. sqlspec/extensions/litestar/__init__.py +2 -1
  91. sqlspec/extensions/litestar/cli.py +48 -0
  92. sqlspec/extensions/litestar/config.py +0 -1
  93. sqlspec/extensions/litestar/handlers.py +15 -26
  94. sqlspec/extensions/litestar/plugin.py +21 -16
  95. sqlspec/extensions/litestar/providers.py +17 -52
  96. sqlspec/loader.py +423 -104
  97. sqlspec/migrations/__init__.py +35 -0
  98. sqlspec/migrations/base.py +414 -0
  99. sqlspec/migrations/commands.py +443 -0
  100. sqlspec/migrations/loaders.py +402 -0
  101. sqlspec/migrations/runner.py +213 -0
  102. sqlspec/migrations/tracker.py +140 -0
  103. sqlspec/migrations/utils.py +129 -0
  104. sqlspec/protocols.py +51 -186
  105. sqlspec/storage/__init__.py +1 -1
  106. sqlspec/storage/backends/base.py +37 -40
  107. sqlspec/storage/backends/fsspec.py +136 -112
  108. sqlspec/storage/backends/obstore.py +138 -160
  109. sqlspec/storage/capabilities.py +5 -4
  110. sqlspec/storage/registry.py +57 -106
  111. sqlspec/typing.py +136 -115
  112. sqlspec/utils/__init__.py +2 -2
  113. sqlspec/utils/correlation.py +0 -3
  114. sqlspec/utils/deprecation.py +6 -6
  115. sqlspec/utils/fixtures.py +6 -6
  116. sqlspec/utils/logging.py +0 -2
  117. sqlspec/utils/module_loader.py +7 -12
  118. sqlspec/utils/singleton.py +0 -1
  119. sqlspec/utils/sync_tools.py +17 -38
  120. sqlspec/utils/text.py +12 -51
  121. sqlspec/utils/type_guards.py +482 -235
  122. {sqlspec-0.13.1.dist-info → sqlspec-0.16.2.dist-info}/METADATA +7 -2
  123. sqlspec-0.16.2.dist-info/RECORD +134 -0
  124. sqlspec-0.16.2.dist-info/entry_points.txt +2 -0
  125. sqlspec/driver/connection.py +0 -207
  126. sqlspec/driver/mixins/_csv_writer.py +0 -91
  127. sqlspec/driver/mixins/_pipeline.py +0 -512
  128. sqlspec/driver/mixins/_result_utils.py +0 -140
  129. sqlspec/driver/mixins/_storage.py +0 -926
  130. sqlspec/driver/mixins/_type_coercion.py +0 -130
  131. sqlspec/driver/parameters.py +0 -138
  132. sqlspec/service/__init__.py +0 -4
  133. sqlspec/service/_util.py +0 -147
  134. sqlspec/service/base.py +0 -1131
  135. sqlspec/service/pagination.py +0 -26
  136. sqlspec/statement/__init__.py +0 -21
  137. sqlspec/statement/builder/insert.py +0 -288
  138. sqlspec/statement/builder/merge.py +0 -95
  139. sqlspec/statement/builder/mixins/__init__.py +0 -65
  140. sqlspec/statement/builder/mixins/_aggregate_functions.py +0 -250
  141. sqlspec/statement/builder/mixins/_case_builder.py +0 -91
  142. sqlspec/statement/builder/mixins/_common_table_expr.py +0 -90
  143. sqlspec/statement/builder/mixins/_from.py +0 -63
  144. sqlspec/statement/builder/mixins/_group_by.py +0 -118
  145. sqlspec/statement/builder/mixins/_having.py +0 -35
  146. sqlspec/statement/builder/mixins/_insert_from_select.py +0 -47
  147. sqlspec/statement/builder/mixins/_insert_into.py +0 -36
  148. sqlspec/statement/builder/mixins/_insert_values.py +0 -67
  149. sqlspec/statement/builder/mixins/_limit_offset.py +0 -53
  150. sqlspec/statement/builder/mixins/_order_by.py +0 -46
  151. sqlspec/statement/builder/mixins/_pivot.py +0 -79
  152. sqlspec/statement/builder/mixins/_returning.py +0 -37
  153. sqlspec/statement/builder/mixins/_select_columns.py +0 -61
  154. sqlspec/statement/builder/mixins/_set_ops.py +0 -122
  155. sqlspec/statement/builder/mixins/_unpivot.py +0 -77
  156. sqlspec/statement/builder/mixins/_update_from.py +0 -55
  157. sqlspec/statement/builder/mixins/_update_set.py +0 -94
  158. sqlspec/statement/builder/mixins/_update_table.py +0 -29
  159. sqlspec/statement/builder/mixins/_where.py +0 -401
  160. sqlspec/statement/builder/mixins/_window_functions.py +0 -86
  161. sqlspec/statement/builder/select.py +0 -221
  162. sqlspec/statement/filters.py +0 -596
  163. sqlspec/statement/parameter_manager.py +0 -220
  164. sqlspec/statement/parameters.py +0 -867
  165. sqlspec/statement/pipelines/__init__.py +0 -210
  166. sqlspec/statement/pipelines/analyzers/__init__.py +0 -9
  167. sqlspec/statement/pipelines/analyzers/_analyzer.py +0 -646
  168. sqlspec/statement/pipelines/context.py +0 -115
  169. sqlspec/statement/pipelines/transformers/__init__.py +0 -7
  170. sqlspec/statement/pipelines/transformers/_expression_simplifier.py +0 -88
  171. sqlspec/statement/pipelines/transformers/_literal_parameterizer.py +0 -1247
  172. sqlspec/statement/pipelines/transformers/_remove_comments_and_hints.py +0 -76
  173. sqlspec/statement/pipelines/validators/__init__.py +0 -23
  174. sqlspec/statement/pipelines/validators/_dml_safety.py +0 -290
  175. sqlspec/statement/pipelines/validators/_parameter_style.py +0 -370
  176. sqlspec/statement/pipelines/validators/_performance.py +0 -718
  177. sqlspec/statement/pipelines/validators/_security.py +0 -967
  178. sqlspec/statement/result.py +0 -435
  179. sqlspec/statement/sql.py +0 -1704
  180. sqlspec/statement/sql_compiler.py +0 -140
  181. sqlspec/utils/cached_property.py +0 -25
  182. sqlspec-0.13.1.dist-info/RECORD +0 -150
  183. {sqlspec-0.13.1.dist-info → sqlspec-0.16.2.dist-info}/WHEEL +0 -0
  184. {sqlspec-0.13.1.dist-info → sqlspec-0.16.2.dist-info}/licenses/LICENSE +0 -0
  185. {sqlspec-0.13.1.dist-info → sqlspec-0.16.2.dist-info}/licenses/NOTICE +0 -0
@@ -2,256 +2,122 @@
2
2
 
3
3
  import contextlib
4
4
  import logging
5
- from collections.abc import AsyncGenerator
6
5
  from contextlib import asynccontextmanager
7
- from typing import TYPE_CHECKING, Any, ClassVar, Optional, cast
6
+ from typing import TYPE_CHECKING, Any, ClassVar, Optional, TypedDict, Union, cast
8
7
 
9
8
  import oracledb
9
+ from typing_extensions import NotRequired
10
10
 
11
+ from sqlspec.adapters.oracledb._types import OracleAsyncConnection, OracleSyncConnection
11
12
  from sqlspec.adapters.oracledb.driver import (
12
- OracleAsyncConnection,
13
+ OracleAsyncCursor,
13
14
  OracleAsyncDriver,
14
- OracleSyncConnection,
15
+ OracleSyncCursor,
15
16
  OracleSyncDriver,
17
+ oracledb_statement_config,
16
18
  )
17
19
  from sqlspec.config import AsyncDatabaseConfig, SyncDatabaseConfig
18
- from sqlspec.statement.sql import SQLConfig
19
- from sqlspec.typing import DictRow, Empty
20
20
 
21
21
  if TYPE_CHECKING:
22
- from collections.abc import Callable, Generator
22
+ from collections.abc import AsyncGenerator, Callable, Generator
23
23
 
24
24
  from oracledb import AuthMode
25
25
  from oracledb.pool import AsyncConnectionPool, ConnectionPool
26
- from sqlglot.dialects.dialect import DialectType
27
26
 
27
+ from sqlspec.core.statement import StatementConfig
28
28
 
29
- __all__ = ("CONNECTION_FIELDS", "POOL_FIELDS", "OracleAsyncConfig", "OracleSyncConfig")
29
+
30
+ __all__ = ("OracleAsyncConfig", "OracleConnectionParams", "OraclePoolParams", "OracleSyncConfig")
30
31
 
31
32
  logger = logging.getLogger(__name__)
32
33
 
33
- CONNECTION_FIELDS = frozenset(
34
- {
35
- "dsn",
36
- "user",
37
- "password",
38
- "host",
39
- "port",
40
- "service_name",
41
- "sid",
42
- "wallet_location",
43
- "wallet_password",
44
- "config_dir",
45
- "tcp_connect_timeout",
46
- "retry_count",
47
- "retry_delay",
48
- "mode",
49
- "events",
50
- "edition",
51
- }
52
- )
53
34
 
54
- POOL_FIELDS = CONNECTION_FIELDS.union(
55
- {
56
- "min",
57
- "max",
58
- "increment",
59
- "threaded",
60
- "getmode",
61
- "homogeneous",
62
- "timeout",
63
- "wait_timeout",
64
- "max_lifetime_session",
65
- "session_callback",
66
- "max_sessions_per_shard",
67
- "soda_metadata_cache",
68
- "ping_interval",
69
- }
70
- )
35
+ class OracleConnectionParams(TypedDict, total=False):
36
+ """OracleDB connection parameters."""
37
+
38
+ dsn: NotRequired[str]
39
+ user: NotRequired[str]
40
+ password: NotRequired[str]
41
+ host: NotRequired[str]
42
+ port: NotRequired[int]
43
+ service_name: NotRequired[str]
44
+ sid: NotRequired[str]
45
+ wallet_location: NotRequired[str]
46
+ wallet_password: NotRequired[str]
47
+ config_dir: NotRequired[str]
48
+ tcp_connect_timeout: NotRequired[float]
49
+ retry_count: NotRequired[int]
50
+ retry_delay: NotRequired[int]
51
+ mode: NotRequired["AuthMode"]
52
+ events: NotRequired[bool]
53
+ edition: NotRequired[str]
54
+
55
+
56
+ class OraclePoolParams(OracleConnectionParams, total=False):
57
+ """OracleDB pool parameters."""
58
+
59
+ min: NotRequired[int]
60
+ max: NotRequired[int]
61
+ increment: NotRequired[int]
62
+ threaded: NotRequired[bool]
63
+ getmode: NotRequired[Any]
64
+ homogeneous: NotRequired[bool]
65
+ timeout: NotRequired[int]
66
+ wait_timeout: NotRequired[int]
67
+ max_lifetime_session: NotRequired[int]
68
+ session_callback: NotRequired["Callable[..., Any]"]
69
+ max_sessions_per_shard: NotRequired[int]
70
+ soda_metadata_cache: NotRequired[bool]
71
+ ping_interval: NotRequired[int]
72
+ extra: NotRequired[dict[str, Any]]
71
73
 
72
74
 
73
75
  class OracleSyncConfig(SyncDatabaseConfig[OracleSyncConnection, "ConnectionPool", OracleSyncDriver]):
74
76
  """Configuration for Oracle synchronous database connections with direct field-based configuration."""
75
77
 
76
- __slots__ = (
77
- "_dialect",
78
- "config_dir",
79
- "default_row_type",
80
- "dsn",
81
- "edition",
82
- "events",
83
- "extras",
84
- "getmode",
85
- "homogeneous",
86
- "host",
87
- "increment",
88
- "max",
89
- "max_lifetime_session",
90
- "max_sessions_per_shard",
91
- "min",
92
- "mode",
93
- "password",
94
- "ping_interval",
95
- "pool_instance",
96
- "port",
97
- "retry_count",
98
- "retry_delay",
99
- "service_name",
100
- "session_callback",
101
- "sid",
102
- "soda_metadata_cache",
103
- "statement_config",
104
- "tcp_connect_timeout",
105
- "threaded",
106
- "timeout",
107
- "user",
108
- "wait_timeout",
109
- "wallet_location",
110
- "wallet_password",
111
- )
112
-
113
- is_async: ClassVar[bool] = False
114
- supports_connection_pooling: ClassVar[bool] = True
115
-
116
- driver_type: type[OracleSyncDriver] = OracleSyncDriver
117
- connection_type: type[OracleSyncConnection] = OracleSyncConnection
118
-
119
- # Parameter style support information
120
- supported_parameter_styles: ClassVar[tuple[str, ...]] = ("named_colon", "positional_colon")
121
- """OracleDB supports :name (named_colon) and :1 (positional_colon) parameter styles."""
122
-
123
- preferred_parameter_style: ClassVar[str] = "named_colon"
124
- """OracleDB's preferred parameter style is :name (named_colon)."""
78
+ driver_type: ClassVar[type[OracleSyncDriver]] = OracleSyncDriver
79
+ connection_type: "ClassVar[type[OracleSyncConnection]]" = OracleSyncConnection
125
80
 
126
81
  def __init__(
127
82
  self,
128
- statement_config: "Optional[SQLConfig]" = None,
129
- default_row_type: "type[DictRow]" = DictRow,
130
- # Connection parameters
131
- dsn: Optional[str] = None,
132
- user: Optional[str] = None,
133
- password: Optional[str] = None,
134
- host: Optional[str] = None,
135
- port: Optional[int] = None,
136
- service_name: Optional[str] = None,
137
- sid: Optional[str] = None,
138
- wallet_location: Optional[str] = None,
139
- wallet_password: Optional[str] = None,
140
- config_dir: Optional[str] = None,
141
- tcp_connect_timeout: Optional[float] = None,
142
- retry_count: Optional[int] = None,
143
- retry_delay: Optional[int] = None,
144
- mode: Optional["AuthMode"] = None,
145
- events: Optional[bool] = None,
146
- edition: Optional[str] = None,
147
- # Pool parameters
148
- min: Optional[int] = None,
149
- max: Optional[int] = None,
150
- increment: Optional[int] = None,
151
- threaded: Optional[bool] = None,
152
- getmode: Optional[int] = None,
153
- homogeneous: Optional[bool] = None,
154
- timeout: Optional[int] = None,
155
- wait_timeout: Optional[int] = None,
156
- max_lifetime_session: Optional[int] = None,
157
- session_callback: Optional["Callable[[Any, Any], None]"] = None,
158
- max_sessions_per_shard: Optional[int] = None,
159
- soda_metadata_cache: Optional[bool] = None,
160
- ping_interval: Optional[int] = None,
161
- pool_instance: Optional["ConnectionPool"] = None,
162
- **kwargs: Any,
83
+ *,
84
+ pool_instance: "Optional[ConnectionPool]" = None,
85
+ pool_config: "Optional[Union[OraclePoolParams, dict[str, Any]]]" = None,
86
+ statement_config: "Optional[StatementConfig]" = None,
87
+ migration_config: Optional[dict[str, Any]] = None,
163
88
  ) -> None:
164
89
  """Initialize Oracle synchronous configuration.
165
90
 
166
91
  Args:
92
+ pool_config: Pool configuration parameters
93
+ pool_instance: Existing pool instance to use
167
94
  statement_config: Default SQL statement configuration
168
- default_row_type: Default row type for results
169
- dsn: Connection string for the database
170
- user: Username for database authentication
171
- password: Password for database authentication
172
- host: Database server hostname
173
- port: Database server port number
174
- service_name: Oracle service name
175
- sid: Oracle System ID (SID)
176
- wallet_location: Location of Oracle Wallet
177
- wallet_password: Password for accessing Oracle Wallet
178
- config_dir: Directory containing Oracle configuration files
179
- tcp_connect_timeout: Timeout for establishing TCP connections
180
- retry_count: Number of attempts to connect
181
- retry_delay: Time in seconds between connection attempts
182
- mode: Session mode (SYSDBA, SYSOPER, etc.)
183
- events: If True, enables Oracle events for FAN and RLB
184
- edition: Edition name for edition-based redefinition
185
- min: Minimum number of connections in the pool
186
- max: Maximum number of connections in the pool
187
- increment: Number of connections to create when pool needs to grow
188
- threaded: Whether the pool should be threaded
189
- getmode: How connections are returned from the pool
190
- homogeneous: Whether all connections use the same credentials
191
- timeout: Time in seconds after which idle connections are closed
192
- wait_timeout: Time in seconds to wait for an available connection
193
- max_lifetime_session: Maximum time in seconds that a connection can remain in the pool
194
- session_callback: Callback function called when a connection is returned to the pool
195
- max_sessions_per_shard: Maximum number of sessions per shard
196
- soda_metadata_cache: Whether to enable SODA metadata caching
197
- ping_interval: Interval for pinging pooled connections
198
- pool_instance: Optional existing connection pool instance
199
- **kwargs: Additional parameters (stored in extras)
95
+ migration_config: Migration configuration
200
96
  """
201
- # Store connection parameters as instance attributes
202
- self.dsn = dsn
203
- self.user = user
204
- self.password = password
205
- self.host = host
206
- self.port = port
207
- self.service_name = service_name
208
- self.sid = sid
209
- self.wallet_location = wallet_location
210
- self.wallet_password = wallet_password
211
- self.config_dir = config_dir
212
- self.tcp_connect_timeout = tcp_connect_timeout
213
- self.retry_count = retry_count
214
- self.retry_delay = retry_delay
215
- self.mode = mode
216
- self.events = events
217
- self.edition = edition
218
-
219
- # Store pool parameters as instance attributes
220
- self.min = min
221
- self.max = max
222
- self.increment = increment
223
- self.threaded = threaded
224
- self.getmode = getmode
225
- self.homogeneous = homogeneous
226
- self.timeout = timeout
227
- self.wait_timeout = wait_timeout
228
- self.max_lifetime_session = max_lifetime_session
229
- self.session_callback = session_callback
230
- self.max_sessions_per_shard = max_sessions_per_shard
231
- self.soda_metadata_cache = soda_metadata_cache
232
- self.ping_interval = ping_interval
233
-
234
- self.extras = kwargs or {}
235
-
236
- # Store other config
237
- self.statement_config = statement_config or SQLConfig()
238
- self.default_row_type = default_row_type
239
- self.pool_instance = pool_instance
240
- self._dialect: DialectType = None
241
-
242
- super().__init__()
97
+ # Store the pool config as a dict and extract/merge extras
98
+ processed_pool_config: dict[str, Any] = dict(pool_config) if pool_config else {}
99
+ if "extra" in processed_pool_config:
100
+ extras = processed_pool_config.pop("extra")
101
+ processed_pool_config.update(extras)
102
+ statement_config = statement_config or oracledb_statement_config
103
+ super().__init__(
104
+ pool_config=processed_pool_config,
105
+ pool_instance=pool_instance,
106
+ migration_config=migration_config,
107
+ statement_config=statement_config,
108
+ )
243
109
 
244
110
  def _create_pool(self) -> "ConnectionPool":
245
111
  """Create the actual connection pool."""
246
112
 
247
- return oracledb.create_pool(**self.connection_config_dict)
113
+ return oracledb.create_pool(**dict(self.pool_config))
248
114
 
249
115
  def _close_pool(self) -> None:
250
116
  """Close the actual connection pool."""
251
117
  if self.pool_instance:
252
118
  self.pool_instance.close()
253
119
 
254
- def create_connection(self) -> OracleSyncConnection:
120
+ def create_connection(self) -> "OracleSyncConnection":
255
121
  """Create a single connection (not from pool).
256
122
 
257
123
  Returns:
@@ -281,29 +147,21 @@ class OracleSyncConfig(SyncDatabaseConfig[OracleSyncConnection, "ConnectionPool"
281
147
  self.pool_instance.release(conn)
282
148
 
283
149
  @contextlib.contextmanager
284
- def provide_session(self, *args: Any, **kwargs: Any) -> "Generator[OracleSyncDriver, None, None]":
150
+ def provide_session(
151
+ self, *args: Any, statement_config: "Optional[StatementConfig]" = None, **kwargs: Any
152
+ ) -> "Generator[OracleSyncDriver, None, None]":
285
153
  """Provide a driver session context manager.
286
154
 
287
155
  Args:
288
156
  *args: Additional arguments.
157
+ statement_config: Optional statement configuration override.
289
158
  **kwargs: Additional keyword arguments.
290
159
 
291
160
  Yields:
292
161
  An OracleSyncDriver instance.
293
162
  """
294
163
  with self.provide_connection(*args, **kwargs) as conn:
295
- statement_config = self.statement_config
296
- # Inject parameter style info if not already set
297
- if statement_config.allowed_parameter_styles is None:
298
- from dataclasses import replace
299
-
300
- statement_config = replace(
301
- statement_config,
302
- allowed_parameter_styles=self.supported_parameter_styles,
303
- target_parameter_style=self.preferred_parameter_style,
304
- )
305
- driver = self.driver_type(connection=conn, config=statement_config)
306
- yield driver
164
+ yield self.driver_type(connection=conn, statement_config=statement_config or self.statement_config)
307
165
 
308
166
  def provide_pool(self, *args: Any, **kwargs: Any) -> "ConnectionPool":
309
167
  """Provide pool instance.
@@ -324,250 +182,57 @@ class OracleSyncConfig(SyncDatabaseConfig[OracleSyncConnection, "ConnectionPool"
324
182
  Returns:
325
183
  Dictionary mapping type names to types.
326
184
  """
185
+
327
186
  namespace = super().get_signature_namespace()
328
- namespace.update({"OracleSyncConnection": OracleSyncConnection, "OracleAsyncConnection": OracleAsyncConnection})
187
+ namespace.update(
188
+ {
189
+ "OracleSyncConnection": OracleSyncConnection,
190
+ "OracleAsyncConnection": OracleAsyncConnection,
191
+ "OracleSyncCursor": OracleSyncCursor,
192
+ }
193
+ )
329
194
  return namespace
330
195
 
331
- @property
332
- def connection_config_dict(self) -> dict[str, Any]:
333
- """Return the connection configuration as a dict for Oracle operations.
334
-
335
- Returns all configuration parameters merged together.
336
- """
337
- # Gather non-None parameters from all fields (connection + pool)
338
- config = {
339
- field: getattr(self, field)
340
- for field in CONNECTION_FIELDS
341
- if getattr(self, field, None) is not None and getattr(self, field) is not Empty
342
- }
343
-
344
- # Merge extras parameters
345
- config.update(self.extras)
346
-
347
- return config
348
-
349
- @property
350
- def pool_config_dict(self) -> dict[str, Any]:
351
- """Return the pool configuration as a dict for Oracle operations.
352
-
353
- Returns all configuration parameters merged together.
354
- """
355
- # Gather non-None parameters from all fields (connection + pool)
356
- config = {
357
- field: getattr(self, field)
358
- for field in POOL_FIELDS
359
- if getattr(self, field, None) is not None and getattr(self, field) is not Empty
360
- }
361
-
362
- # Merge extras parameters
363
- config.update(self.extras)
364
-
365
- return config
366
-
367
196
 
368
197
  class OracleAsyncConfig(AsyncDatabaseConfig[OracleAsyncConnection, "AsyncConnectionPool", OracleAsyncDriver]):
369
198
  """Configuration for Oracle asynchronous database connections with direct field-based configuration."""
370
199
 
371
- __slots__ = (
372
- "_dialect",
373
- "config_dir",
374
- "default_row_type",
375
- "dsn",
376
- "edition",
377
- "events",
378
- "extras",
379
- "getmode",
380
- "homogeneous",
381
- "host",
382
- "increment",
383
- "max",
384
- "max_lifetime_session",
385
- "max_sessions_per_shard",
386
- "min",
387
- "mode",
388
- "password",
389
- "ping_interval",
390
- "pool_instance",
391
- "port",
392
- "retry_count",
393
- "retry_delay",
394
- "service_name",
395
- "session_callback",
396
- "sid",
397
- "soda_metadata_cache",
398
- "statement_config",
399
- "tcp_connect_timeout",
400
- "threaded",
401
- "timeout",
402
- "user",
403
- "wait_timeout",
404
- "wallet_location",
405
- "wallet_password",
406
- )
407
-
408
- is_async: ClassVar[bool] = True
409
- supports_connection_pooling: ClassVar[bool] = True
410
-
411
- connection_type: type[OracleAsyncConnection] = OracleAsyncConnection
412
- driver_type: type[OracleAsyncDriver] = OracleAsyncDriver
413
-
414
- # Parameter style support information
415
- supported_parameter_styles: ClassVar[tuple[str, ...]] = ("named_colon", "positional_colon")
416
- """OracleDB supports :name (named_colon) and :1 (positional_colon) parameter styles."""
417
-
418
- preferred_parameter_style: ClassVar[str] = "named_colon"
419
- """OracleDB's preferred parameter style is :name (named_colon)."""
200
+ connection_type: "ClassVar[type[OracleAsyncConnection]]" = OracleAsyncConnection
201
+ driver_type: ClassVar[type[OracleAsyncDriver]] = OracleAsyncDriver
420
202
 
421
203
  def __init__(
422
204
  self,
423
- statement_config: "Optional[SQLConfig]" = None,
424
- default_row_type: "type[DictRow]" = DictRow,
425
- # Connection parameters
426
- dsn: Optional[str] = None,
427
- user: Optional[str] = None,
428
- password: Optional[str] = None,
429
- host: Optional[str] = None,
430
- port: Optional[int] = None,
431
- service_name: Optional[str] = None,
432
- sid: Optional[str] = None,
433
- wallet_location: Optional[str] = None,
434
- wallet_password: Optional[str] = None,
435
- config_dir: Optional[str] = None,
436
- tcp_connect_timeout: Optional[float] = None,
437
- retry_count: Optional[int] = None,
438
- retry_delay: Optional[int] = None,
439
- mode: Optional["AuthMode"] = None,
440
- events: Optional[bool] = None,
441
- edition: Optional[str] = None,
442
- # Pool parameters
443
- min: Optional[int] = None,
444
- max: Optional[int] = None,
445
- increment: Optional[int] = None,
446
- threaded: Optional[bool] = None,
447
- getmode: Optional[int] = None,
448
- homogeneous: Optional[bool] = None,
449
- timeout: Optional[int] = None,
450
- wait_timeout: Optional[int] = None,
451
- max_lifetime_session: Optional[int] = None,
452
- session_callback: Optional["Callable[[Any, Any], None]"] = None,
453
- max_sessions_per_shard: Optional[int] = None,
454
- soda_metadata_cache: Optional[bool] = None,
455
- ping_interval: Optional[int] = None,
456
- pool_instance: Optional["AsyncConnectionPool"] = None,
457
- **kwargs: Any,
205
+ *,
206
+ pool_config: "Optional[Union[OraclePoolParams, dict[str, Any]]]" = None,
207
+ pool_instance: "Optional[AsyncConnectionPool]" = None,
208
+ statement_config: "Optional[StatementConfig]" = None,
209
+ migration_config: Optional[dict[str, Any]] = None,
458
210
  ) -> None:
459
211
  """Initialize Oracle asynchronous configuration.
460
212
 
461
213
  Args:
214
+ pool_config: Pool configuration parameters
215
+ pool_instance: Existing pool instance to use
462
216
  statement_config: Default SQL statement configuration
463
- default_row_type: Default row type for results
464
- dsn: Connection string for the database
465
- user: Username for database authentication
466
- password: Password for database authentication
467
- host: Database server hostname
468
- port: Database server port number
469
- service_name: Oracle service name
470
- sid: Oracle System ID (SID)
471
- wallet_location: Location of Oracle Wallet
472
- wallet_password: Password for accessing Oracle Wallet
473
- config_dir: Directory containing Oracle configuration files
474
- tcp_connect_timeout: Timeout for establishing TCP connections
475
- retry_count: Number of attempts to connect
476
- retry_delay: Time in seconds between connection attempts
477
- mode: Session mode (SYSDBA, SYSOPER, etc.)
478
- events: If True, enables Oracle events for FAN and RLB
479
- edition: Edition name for edition-based redefinition
480
- min: Minimum number of connections in the pool
481
- max: Maximum number of connections in the pool
482
- increment: Number of connections to create when pool needs to grow
483
- threaded: Whether the pool should be threaded
484
- getmode: How connections are returned from the pool
485
- homogeneous: Whether all connections use the same credentials
486
- timeout: Time in seconds after which idle connections are closed
487
- wait_timeout: Time in seconds to wait for an available connection
488
- max_lifetime_session: Maximum time in seconds that a connection can remain in the pool
489
- session_callback: Callback function called when a connection is returned to the pool
490
- max_sessions_per_shard: Maximum number of sessions per shard
491
- soda_metadata_cache: Whether to enable SODA metadata caching
492
- ping_interval: Interval for pinging pooled connections
493
- pool_instance: Optional existing async connection pool instance
494
- **kwargs: Additional parameters (stored in extras)
495
- """
496
- # Store connection parameters as instance attributes
497
- self.dsn = dsn
498
- self.user = user
499
- self.password = password
500
- self.host = host
501
- self.port = port
502
- self.service_name = service_name
503
- self.sid = sid
504
- self.wallet_location = wallet_location
505
- self.wallet_password = wallet_password
506
- self.config_dir = config_dir
507
- self.tcp_connect_timeout = tcp_connect_timeout
508
- self.retry_count = retry_count
509
- self.retry_delay = retry_delay
510
- self.mode = mode
511
- self.events = events
512
- self.edition = edition
513
-
514
- # Store pool parameters as instance attributes
515
- self.min = min
516
- self.max = max
517
- self.increment = increment
518
- self.threaded = threaded
519
- self.getmode = getmode
520
- self.homogeneous = homogeneous
521
- self.timeout = timeout
522
- self.wait_timeout = wait_timeout
523
- self.max_lifetime_session = max_lifetime_session
524
- self.session_callback = session_callback
525
- self.max_sessions_per_shard = max_sessions_per_shard
526
- self.soda_metadata_cache = soda_metadata_cache
527
- self.ping_interval = ping_interval
528
-
529
- self.extras = kwargs or {}
530
-
531
- # Store other config
532
- self.statement_config = statement_config or SQLConfig()
533
- self.default_row_type = default_row_type
534
- self.pool_instance: Optional[AsyncConnectionPool] = pool_instance
535
- self._dialect: DialectType = None
536
-
537
- super().__init__()
538
-
539
- @property
540
- def connection_config_dict(self) -> dict[str, Any]:
541
- """Return the connection configuration as a dict for Oracle async operations.
542
-
543
- Returns all configuration parameters merged together.
217
+ migration_config: Migration configuration
544
218
  """
545
- # Gather non-None parameters
546
- config = {field: getattr(self, field) for field in CONNECTION_FIELDS if getattr(self, field, None) is not None}
547
-
548
- # Merge extras parameters
549
- config.update(self.extras)
550
-
551
- return config
552
-
553
- @property
554
- def pool_config_dict(self) -> dict[str, Any]:
555
- """Return the connection configuration as a dict for Oracle async operations.
556
-
557
- Returns all configuration parameters merged together.
558
- """
559
- # Gather non-None parameters
560
- config = {field: getattr(self, field) for field in POOL_FIELDS if getattr(self, field, None) is not None}
561
-
562
- # Merge extras parameters
563
- config.update(self.extras)
564
-
565
- return config
219
+ # Store the pool config as a dict and extract/merge extras
220
+ processed_pool_config: dict[str, Any] = dict(pool_config) if pool_config else {}
221
+ if "extra" in processed_pool_config:
222
+ extras = processed_pool_config.pop("extra")
223
+ processed_pool_config.update(extras)
224
+
225
+ super().__init__(
226
+ pool_config=processed_pool_config,
227
+ pool_instance=pool_instance,
228
+ migration_config=migration_config,
229
+ statement_config=statement_config or oracledb_statement_config,
230
+ )
566
231
 
567
232
  async def _create_pool(self) -> "AsyncConnectionPool":
568
233
  """Create the actual async connection pool."""
569
234
 
570
- return oracledb.create_pool_async(**self.pool_config_dict)
235
+ return oracledb.create_pool_async(**dict(self.pool_config))
571
236
 
572
237
  async def _close_pool(self) -> None:
573
238
  """Close the actual async connection pool."""
@@ -585,7 +250,7 @@ class OracleAsyncConfig(AsyncDatabaseConfig[OracleAsyncConnection, "AsyncConnect
585
250
  return cast("OracleAsyncConnection", await self.pool_instance.acquire())
586
251
 
587
252
  @asynccontextmanager
588
- async def provide_connection(self, *args: Any, **kwargs: Any) -> AsyncGenerator[OracleAsyncConnection, None]:
253
+ async def provide_connection(self, *args: Any, **kwargs: Any) -> "AsyncGenerator[OracleAsyncConnection, None]":
589
254
  """Provide an async connection context manager.
590
255
 
591
256
  Args:
@@ -604,29 +269,21 @@ class OracleAsyncConfig(AsyncDatabaseConfig[OracleAsyncConnection, "AsyncConnect
604
269
  await self.pool_instance.release(conn)
605
270
 
606
271
  @asynccontextmanager
607
- async def provide_session(self, *args: Any, **kwargs: Any) -> AsyncGenerator[OracleAsyncDriver, None]:
272
+ async def provide_session(
273
+ self, *args: Any, statement_config: "Optional[StatementConfig]" = None, **kwargs: Any
274
+ ) -> "AsyncGenerator[OracleAsyncDriver, None]":
608
275
  """Provide an async driver session context manager.
609
276
 
610
277
  Args:
611
278
  *args: Additional arguments.
279
+ statement_config: Optional statement configuration override.
612
280
  **kwargs: Additional keyword arguments.
613
281
 
614
282
  Yields:
615
283
  An OracleAsyncDriver instance.
616
284
  """
617
285
  async with self.provide_connection(*args, **kwargs) as conn:
618
- statement_config = self.statement_config
619
- # Inject parameter style info if not already set
620
- if statement_config.allowed_parameter_styles is None:
621
- from dataclasses import replace
622
-
623
- statement_config = replace(
624
- statement_config,
625
- allowed_parameter_styles=self.supported_parameter_styles,
626
- target_parameter_style=self.preferred_parameter_style,
627
- )
628
- driver = self.driver_type(connection=conn, config=statement_config)
629
- yield driver
286
+ yield self.driver_type(connection=conn, statement_config=statement_config or self.statement_config)
630
287
 
631
288
  async def provide_pool(self, *args: Any, **kwargs: Any) -> "AsyncConnectionPool":
632
289
  """Provide async pool instance.
@@ -647,6 +304,14 @@ class OracleAsyncConfig(AsyncDatabaseConfig[OracleAsyncConnection, "AsyncConnect
647
304
  Returns:
648
305
  Dictionary mapping type names to types.
649
306
  """
307
+
650
308
  namespace = super().get_signature_namespace()
651
- namespace.update({"OracleSyncConnection": OracleSyncConnection, "OracleAsyncConnection": OracleAsyncConnection})
309
+ namespace.update(
310
+ {
311
+ "OracleSyncConnection": OracleSyncConnection,
312
+ "OracleAsyncConnection": OracleAsyncConnection,
313
+ "OracleSyncCursor": OracleSyncCursor,
314
+ "OracleAsyncCursor": OracleAsyncCursor,
315
+ }
316
+ )
652
317
  return namespace