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.
- sqlspec/__init__.py +71 -8
- sqlspec/__main__.py +12 -0
- sqlspec/__metadata__.py +1 -3
- sqlspec/_serialization.py +1 -2
- sqlspec/_sql.py +930 -136
- sqlspec/_typing.py +278 -142
- sqlspec/adapters/adbc/__init__.py +4 -3
- sqlspec/adapters/adbc/_types.py +12 -0
- sqlspec/adapters/adbc/config.py +116 -285
- sqlspec/adapters/adbc/driver.py +462 -340
- sqlspec/adapters/aiosqlite/__init__.py +18 -3
- sqlspec/adapters/aiosqlite/_types.py +13 -0
- sqlspec/adapters/aiosqlite/config.py +202 -150
- sqlspec/adapters/aiosqlite/driver.py +226 -247
- sqlspec/adapters/asyncmy/__init__.py +18 -3
- sqlspec/adapters/asyncmy/_types.py +12 -0
- sqlspec/adapters/asyncmy/config.py +80 -199
- sqlspec/adapters/asyncmy/driver.py +257 -215
- sqlspec/adapters/asyncpg/__init__.py +19 -4
- sqlspec/adapters/asyncpg/_types.py +17 -0
- sqlspec/adapters/asyncpg/config.py +81 -214
- sqlspec/adapters/asyncpg/driver.py +284 -359
- sqlspec/adapters/bigquery/__init__.py +17 -3
- sqlspec/adapters/bigquery/_types.py +12 -0
- sqlspec/adapters/bigquery/config.py +191 -299
- sqlspec/adapters/bigquery/driver.py +474 -634
- sqlspec/adapters/duckdb/__init__.py +14 -3
- sqlspec/adapters/duckdb/_types.py +12 -0
- sqlspec/adapters/duckdb/config.py +414 -397
- sqlspec/adapters/duckdb/driver.py +342 -393
- sqlspec/adapters/oracledb/__init__.py +19 -5
- sqlspec/adapters/oracledb/_types.py +14 -0
- sqlspec/adapters/oracledb/config.py +123 -458
- sqlspec/adapters/oracledb/driver.py +505 -531
- sqlspec/adapters/psqlpy/__init__.py +13 -3
- sqlspec/adapters/psqlpy/_types.py +11 -0
- sqlspec/adapters/psqlpy/config.py +93 -307
- sqlspec/adapters/psqlpy/driver.py +504 -213
- sqlspec/adapters/psycopg/__init__.py +19 -5
- sqlspec/adapters/psycopg/_types.py +17 -0
- sqlspec/adapters/psycopg/config.py +143 -472
- sqlspec/adapters/psycopg/driver.py +704 -825
- sqlspec/adapters/sqlite/__init__.py +14 -3
- sqlspec/adapters/sqlite/_types.py +11 -0
- sqlspec/adapters/sqlite/config.py +208 -142
- sqlspec/adapters/sqlite/driver.py +263 -278
- sqlspec/base.py +105 -9
- sqlspec/{statement/builder → builder}/__init__.py +12 -14
- sqlspec/{statement/builder/base.py → builder/_base.py} +184 -86
- sqlspec/{statement/builder/column.py → builder/_column.py} +97 -60
- sqlspec/{statement/builder/ddl.py → builder/_ddl.py} +61 -131
- sqlspec/{statement/builder → builder}/_ddl_utils.py +4 -10
- sqlspec/{statement/builder/delete.py → builder/_delete.py} +10 -30
- sqlspec/builder/_insert.py +421 -0
- sqlspec/builder/_merge.py +71 -0
- sqlspec/{statement/builder → builder}/_parsing_utils.py +49 -26
- sqlspec/builder/_select.py +170 -0
- sqlspec/{statement/builder/update.py → builder/_update.py} +16 -20
- sqlspec/builder/mixins/__init__.py +55 -0
- sqlspec/builder/mixins/_cte_and_set_ops.py +222 -0
- sqlspec/{statement/builder/mixins/_delete_from.py → builder/mixins/_delete_operations.py} +8 -1
- sqlspec/builder/mixins/_insert_operations.py +244 -0
- sqlspec/{statement/builder/mixins/_join.py → builder/mixins/_join_operations.py} +45 -13
- sqlspec/{statement/builder/mixins/_merge_clauses.py → builder/mixins/_merge_operations.py} +188 -30
- sqlspec/builder/mixins/_order_limit_operations.py +135 -0
- sqlspec/builder/mixins/_pivot_operations.py +153 -0
- sqlspec/builder/mixins/_select_operations.py +604 -0
- sqlspec/builder/mixins/_update_operations.py +202 -0
- sqlspec/builder/mixins/_where_clause.py +644 -0
- sqlspec/cli.py +247 -0
- sqlspec/config.py +183 -138
- sqlspec/core/__init__.py +63 -0
- sqlspec/core/cache.py +871 -0
- sqlspec/core/compiler.py +417 -0
- sqlspec/core/filters.py +830 -0
- sqlspec/core/hashing.py +310 -0
- sqlspec/core/parameters.py +1237 -0
- sqlspec/core/result.py +677 -0
- sqlspec/{statement → core}/splitter.py +321 -191
- sqlspec/core/statement.py +676 -0
- sqlspec/driver/__init__.py +7 -10
- sqlspec/driver/_async.py +422 -163
- sqlspec/driver/_common.py +545 -287
- sqlspec/driver/_sync.py +426 -160
- sqlspec/driver/mixins/__init__.py +2 -13
- sqlspec/driver/mixins/_result_tools.py +193 -0
- sqlspec/driver/mixins/_sql_translator.py +65 -14
- sqlspec/exceptions.py +5 -252
- sqlspec/extensions/aiosql/adapter.py +93 -96
- sqlspec/extensions/litestar/__init__.py +2 -1
- sqlspec/extensions/litestar/cli.py +48 -0
- sqlspec/extensions/litestar/config.py +0 -1
- sqlspec/extensions/litestar/handlers.py +15 -26
- sqlspec/extensions/litestar/plugin.py +21 -16
- sqlspec/extensions/litestar/providers.py +17 -52
- sqlspec/loader.py +423 -104
- sqlspec/migrations/__init__.py +35 -0
- sqlspec/migrations/base.py +414 -0
- sqlspec/migrations/commands.py +443 -0
- sqlspec/migrations/loaders.py +402 -0
- sqlspec/migrations/runner.py +213 -0
- sqlspec/migrations/tracker.py +140 -0
- sqlspec/migrations/utils.py +129 -0
- sqlspec/protocols.py +51 -186
- sqlspec/storage/__init__.py +1 -1
- sqlspec/storage/backends/base.py +37 -40
- sqlspec/storage/backends/fsspec.py +136 -112
- sqlspec/storage/backends/obstore.py +138 -160
- sqlspec/storage/capabilities.py +5 -4
- sqlspec/storage/registry.py +57 -106
- sqlspec/typing.py +136 -115
- sqlspec/utils/__init__.py +2 -2
- sqlspec/utils/correlation.py +0 -3
- sqlspec/utils/deprecation.py +6 -6
- sqlspec/utils/fixtures.py +6 -6
- sqlspec/utils/logging.py +0 -2
- sqlspec/utils/module_loader.py +7 -12
- sqlspec/utils/singleton.py +0 -1
- sqlspec/utils/sync_tools.py +17 -38
- sqlspec/utils/text.py +12 -51
- sqlspec/utils/type_guards.py +482 -235
- {sqlspec-0.13.1.dist-info → sqlspec-0.16.2.dist-info}/METADATA +7 -2
- sqlspec-0.16.2.dist-info/RECORD +134 -0
- sqlspec-0.16.2.dist-info/entry_points.txt +2 -0
- sqlspec/driver/connection.py +0 -207
- sqlspec/driver/mixins/_csv_writer.py +0 -91
- sqlspec/driver/mixins/_pipeline.py +0 -512
- sqlspec/driver/mixins/_result_utils.py +0 -140
- sqlspec/driver/mixins/_storage.py +0 -926
- sqlspec/driver/mixins/_type_coercion.py +0 -130
- sqlspec/driver/parameters.py +0 -138
- sqlspec/service/__init__.py +0 -4
- sqlspec/service/_util.py +0 -147
- sqlspec/service/base.py +0 -1131
- sqlspec/service/pagination.py +0 -26
- sqlspec/statement/__init__.py +0 -21
- sqlspec/statement/builder/insert.py +0 -288
- sqlspec/statement/builder/merge.py +0 -95
- sqlspec/statement/builder/mixins/__init__.py +0 -65
- sqlspec/statement/builder/mixins/_aggregate_functions.py +0 -250
- sqlspec/statement/builder/mixins/_case_builder.py +0 -91
- sqlspec/statement/builder/mixins/_common_table_expr.py +0 -90
- sqlspec/statement/builder/mixins/_from.py +0 -63
- sqlspec/statement/builder/mixins/_group_by.py +0 -118
- sqlspec/statement/builder/mixins/_having.py +0 -35
- sqlspec/statement/builder/mixins/_insert_from_select.py +0 -47
- sqlspec/statement/builder/mixins/_insert_into.py +0 -36
- sqlspec/statement/builder/mixins/_insert_values.py +0 -67
- sqlspec/statement/builder/mixins/_limit_offset.py +0 -53
- sqlspec/statement/builder/mixins/_order_by.py +0 -46
- sqlspec/statement/builder/mixins/_pivot.py +0 -79
- sqlspec/statement/builder/mixins/_returning.py +0 -37
- sqlspec/statement/builder/mixins/_select_columns.py +0 -61
- sqlspec/statement/builder/mixins/_set_ops.py +0 -122
- sqlspec/statement/builder/mixins/_unpivot.py +0 -77
- sqlspec/statement/builder/mixins/_update_from.py +0 -55
- sqlspec/statement/builder/mixins/_update_set.py +0 -94
- sqlspec/statement/builder/mixins/_update_table.py +0 -29
- sqlspec/statement/builder/mixins/_where.py +0 -401
- sqlspec/statement/builder/mixins/_window_functions.py +0 -86
- sqlspec/statement/builder/select.py +0 -221
- sqlspec/statement/filters.py +0 -596
- sqlspec/statement/parameter_manager.py +0 -220
- sqlspec/statement/parameters.py +0 -867
- sqlspec/statement/pipelines/__init__.py +0 -210
- sqlspec/statement/pipelines/analyzers/__init__.py +0 -9
- sqlspec/statement/pipelines/analyzers/_analyzer.py +0 -646
- sqlspec/statement/pipelines/context.py +0 -115
- sqlspec/statement/pipelines/transformers/__init__.py +0 -7
- sqlspec/statement/pipelines/transformers/_expression_simplifier.py +0 -88
- sqlspec/statement/pipelines/transformers/_literal_parameterizer.py +0 -1247
- sqlspec/statement/pipelines/transformers/_remove_comments_and_hints.py +0 -76
- sqlspec/statement/pipelines/validators/__init__.py +0 -23
- sqlspec/statement/pipelines/validators/_dml_safety.py +0 -290
- sqlspec/statement/pipelines/validators/_parameter_style.py +0 -370
- sqlspec/statement/pipelines/validators/_performance.py +0 -718
- sqlspec/statement/pipelines/validators/_security.py +0 -967
- sqlspec/statement/result.py +0 -435
- sqlspec/statement/sql.py +0 -1704
- sqlspec/statement/sql_compiler.py +0 -140
- sqlspec/utils/cached_property.py +0 -25
- sqlspec-0.13.1.dist-info/RECORD +0 -150
- {sqlspec-0.13.1.dist-info → sqlspec-0.16.2.dist-info}/WHEEL +0 -0
- {sqlspec-0.13.1.dist-info → sqlspec-0.16.2.dist-info}/licenses/LICENSE +0 -0
- {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
|
-
|
|
13
|
+
OracleAsyncCursor,
|
|
13
14
|
OracleAsyncDriver,
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
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
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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.
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
372
|
-
|
|
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
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
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
|
-
|
|
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
|
-
#
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
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.
|
|
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(
|
|
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
|
-
|
|
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(
|
|
309
|
+
namespace.update(
|
|
310
|
+
{
|
|
311
|
+
"OracleSyncConnection": OracleSyncConnection,
|
|
312
|
+
"OracleAsyncConnection": OracleAsyncConnection,
|
|
313
|
+
"OracleSyncCursor": OracleSyncCursor,
|
|
314
|
+
"OracleAsyncCursor": OracleAsyncCursor,
|
|
315
|
+
}
|
|
316
|
+
)
|
|
652
317
|
return namespace
|