sqlspec 0.14.1__py3-none-any.whl → 0.16.0__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 +50 -25
- sqlspec/__main__.py +1 -1
- sqlspec/__metadata__.py +1 -3
- sqlspec/_serialization.py +1 -2
- sqlspec/_sql.py +480 -121
- sqlspec/_typing.py +278 -142
- sqlspec/adapters/adbc/__init__.py +4 -3
- sqlspec/adapters/adbc/_types.py +12 -0
- sqlspec/adapters/adbc/config.py +115 -260
- sqlspec/adapters/adbc/driver.py +462 -367
- sqlspec/adapters/aiosqlite/__init__.py +18 -3
- sqlspec/adapters/aiosqlite/_types.py +13 -0
- sqlspec/adapters/aiosqlite/config.py +199 -129
- sqlspec/adapters/aiosqlite/driver.py +230 -269
- sqlspec/adapters/asyncmy/__init__.py +18 -3
- sqlspec/adapters/asyncmy/_types.py +12 -0
- sqlspec/adapters/asyncmy/config.py +80 -168
- sqlspec/adapters/asyncmy/driver.py +260 -225
- sqlspec/adapters/asyncpg/__init__.py +19 -4
- sqlspec/adapters/asyncpg/_types.py +17 -0
- sqlspec/adapters/asyncpg/config.py +82 -181
- sqlspec/adapters/asyncpg/driver.py +285 -383
- sqlspec/adapters/bigquery/__init__.py +17 -3
- sqlspec/adapters/bigquery/_types.py +12 -0
- sqlspec/adapters/bigquery/config.py +191 -258
- sqlspec/adapters/bigquery/driver.py +474 -646
- sqlspec/adapters/duckdb/__init__.py +14 -3
- sqlspec/adapters/duckdb/_types.py +12 -0
- sqlspec/adapters/duckdb/config.py +415 -351
- sqlspec/adapters/duckdb/driver.py +343 -413
- sqlspec/adapters/oracledb/__init__.py +19 -5
- sqlspec/adapters/oracledb/_types.py +14 -0
- sqlspec/adapters/oracledb/config.py +123 -379
- sqlspec/adapters/oracledb/driver.py +507 -560
- sqlspec/adapters/psqlpy/__init__.py +13 -3
- sqlspec/adapters/psqlpy/_types.py +11 -0
- sqlspec/adapters/psqlpy/config.py +93 -254
- sqlspec/adapters/psqlpy/driver.py +505 -234
- sqlspec/adapters/psycopg/__init__.py +19 -5
- sqlspec/adapters/psycopg/_types.py +17 -0
- sqlspec/adapters/psycopg/config.py +143 -403
- sqlspec/adapters/psycopg/driver.py +706 -872
- sqlspec/adapters/sqlite/__init__.py +14 -3
- sqlspec/adapters/sqlite/_types.py +11 -0
- sqlspec/adapters/sqlite/config.py +202 -118
- sqlspec/adapters/sqlite/driver.py +264 -303
- sqlspec/base.py +105 -9
- sqlspec/{statement/builder → builder}/__init__.py +12 -14
- sqlspec/{statement/builder → builder}/_base.py +120 -55
- sqlspec/{statement/builder → builder}/_column.py +17 -6
- sqlspec/{statement/builder → builder}/_ddl.py +46 -79
- sqlspec/{statement/builder → builder}/_ddl_utils.py +5 -10
- sqlspec/{statement/builder → builder}/_delete.py +6 -25
- sqlspec/{statement/builder → builder}/_insert.py +18 -65
- sqlspec/builder/_merge.py +56 -0
- sqlspec/{statement/builder → builder}/_parsing_utils.py +8 -11
- sqlspec/{statement/builder → builder}/_select.py +11 -56
- sqlspec/{statement/builder → builder}/_update.py +12 -18
- sqlspec/{statement/builder → builder}/mixins/__init__.py +10 -14
- sqlspec/{statement/builder → builder}/mixins/_cte_and_set_ops.py +48 -59
- sqlspec/{statement/builder → builder}/mixins/_insert_operations.py +34 -18
- sqlspec/{statement/builder → builder}/mixins/_join_operations.py +1 -3
- sqlspec/{statement/builder → builder}/mixins/_merge_operations.py +19 -9
- sqlspec/{statement/builder → builder}/mixins/_order_limit_operations.py +3 -3
- sqlspec/{statement/builder → builder}/mixins/_pivot_operations.py +4 -8
- sqlspec/{statement/builder → builder}/mixins/_select_operations.py +25 -38
- sqlspec/{statement/builder → builder}/mixins/_update_operations.py +15 -16
- sqlspec/{statement/builder → builder}/mixins/_where_clause.py +210 -137
- sqlspec/cli.py +4 -5
- sqlspec/config.py +180 -133
- sqlspec/core/__init__.py +63 -0
- sqlspec/core/cache.py +873 -0
- sqlspec/core/compiler.py +396 -0
- sqlspec/core/filters.py +830 -0
- sqlspec/core/hashing.py +310 -0
- sqlspec/core/parameters.py +1209 -0
- sqlspec/core/result.py +664 -0
- sqlspec/{statement → core}/splitter.py +321 -191
- sqlspec/core/statement.py +666 -0
- sqlspec/driver/__init__.py +7 -10
- sqlspec/driver/_async.py +387 -176
- sqlspec/driver/_common.py +527 -289
- sqlspec/driver/_sync.py +390 -172
- sqlspec/driver/mixins/__init__.py +2 -19
- sqlspec/driver/mixins/_result_tools.py +164 -0
- sqlspec/driver/mixins/_sql_translator.py +6 -3
- sqlspec/exceptions.py +5 -252
- sqlspec/extensions/aiosql/adapter.py +93 -96
- sqlspec/extensions/litestar/cli.py +1 -1
- sqlspec/extensions/litestar/config.py +0 -1
- sqlspec/extensions/litestar/handlers.py +15 -26
- sqlspec/extensions/litestar/plugin.py +18 -16
- sqlspec/extensions/litestar/providers.py +17 -52
- sqlspec/loader.py +424 -105
- sqlspec/migrations/__init__.py +12 -0
- sqlspec/migrations/base.py +92 -68
- sqlspec/migrations/commands.py +24 -106
- sqlspec/migrations/loaders.py +402 -0
- sqlspec/migrations/runner.py +49 -51
- sqlspec/migrations/tracker.py +31 -44
- sqlspec/migrations/utils.py +64 -24
- sqlspec/protocols.py +7 -183
- 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 -3
- 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 +443 -232
- {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/METADATA +7 -2
- sqlspec-0.16.0.dist-info/RECORD +134 -0
- sqlspec/adapters/adbc/transformers.py +0 -108
- sqlspec/driver/connection.py +0 -207
- sqlspec/driver/mixins/_cache.py +0 -114
- sqlspec/driver/mixins/_csv_writer.py +0 -91
- sqlspec/driver/mixins/_pipeline.py +0 -508
- sqlspec/driver/mixins/_query_tools.py +0 -796
- sqlspec/driver/mixins/_result_utils.py +0 -138
- sqlspec/driver/mixins/_storage.py +0 -912
- sqlspec/driver/mixins/_type_coercion.py +0 -128
- sqlspec/driver/parameters.py +0 -138
- sqlspec/statement/__init__.py +0 -21
- sqlspec/statement/builder/_merge.py +0 -95
- sqlspec/statement/cache.py +0 -50
- sqlspec/statement/filters.py +0 -625
- sqlspec/statement/parameters.py +0 -956
- 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 -109
- 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 -714
- sqlspec/statement/pipelines/validators/_security.py +0 -967
- sqlspec/statement/result.py +0 -435
- sqlspec/statement/sql.py +0 -1774
- sqlspec/utils/cached_property.py +0 -25
- sqlspec/utils/statement_hashing.py +0 -203
- sqlspec-0.14.1.dist-info/RECORD +0 -145
- /sqlspec/{statement/builder → builder}/mixins/_delete_operations.py +0 -0
- {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/WHEEL +0 -0
- {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/entry_points.txt +0 -0
- {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/licenses/LICENSE +0 -0
- {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/licenses/NOTICE +0 -0
|
@@ -1,18 +1,32 @@
|
|
|
1
|
-
from sqlspec.adapters.oracledb.
|
|
1
|
+
from sqlspec.adapters.oracledb._types import OracleAsyncConnection, OracleSyncConnection
|
|
2
|
+
from sqlspec.adapters.oracledb.config import (
|
|
3
|
+
OracleAsyncConfig,
|
|
4
|
+
OracleConnectionParams,
|
|
5
|
+
OraclePoolParams,
|
|
6
|
+
OracleSyncConfig,
|
|
7
|
+
)
|
|
2
8
|
from sqlspec.adapters.oracledb.driver import (
|
|
3
|
-
|
|
9
|
+
OracleAsyncCursor,
|
|
4
10
|
OracleAsyncDriver,
|
|
5
|
-
|
|
11
|
+
OracleAsyncExceptionHandler,
|
|
12
|
+
OracleSyncCursor,
|
|
6
13
|
OracleSyncDriver,
|
|
14
|
+
OracleSyncExceptionHandler,
|
|
15
|
+
oracledb_statement_config,
|
|
7
16
|
)
|
|
8
17
|
|
|
9
18
|
__all__ = (
|
|
10
|
-
"CONNECTION_FIELDS",
|
|
11
|
-
"POOL_FIELDS",
|
|
12
19
|
"OracleAsyncConfig",
|
|
13
20
|
"OracleAsyncConnection",
|
|
21
|
+
"OracleAsyncCursor",
|
|
14
22
|
"OracleAsyncDriver",
|
|
23
|
+
"OracleAsyncExceptionHandler",
|
|
24
|
+
"OracleConnectionParams",
|
|
25
|
+
"OraclePoolParams",
|
|
15
26
|
"OracleSyncConfig",
|
|
16
27
|
"OracleSyncConnection",
|
|
28
|
+
"OracleSyncCursor",
|
|
17
29
|
"OracleSyncDriver",
|
|
30
|
+
"OracleSyncExceptionHandler",
|
|
31
|
+
"oracledb_statement_config",
|
|
18
32
|
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING
|
|
2
|
+
|
|
3
|
+
from oracledb import AsyncConnection, Connection
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from typing_extensions import TypeAlias
|
|
7
|
+
|
|
8
|
+
OracleSyncConnection: TypeAlias = Connection
|
|
9
|
+
OracleAsyncConnection: TypeAlias = AsyncConnection
|
|
10
|
+
else:
|
|
11
|
+
OracleSyncConnection = Connection
|
|
12
|
+
OracleAsyncConnection = AsyncConnection
|
|
13
|
+
|
|
14
|
+
__all__ = ("OracleAsyncConnection", "OracleSyncConnection")
|
|
@@ -2,216 +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
26
|
|
|
27
|
+
from sqlspec.core.statement import StatementConfig
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
|
|
30
|
+
__all__ = ("OracleAsyncConfig", "OracleConnectionParams", "OraclePoolParams", "OracleSyncConfig")
|
|
29
31
|
|
|
30
32
|
logger = logging.getLogger(__name__)
|
|
31
33
|
|
|
32
|
-
CONNECTION_FIELDS = frozenset(
|
|
33
|
-
{
|
|
34
|
-
"dsn",
|
|
35
|
-
"user",
|
|
36
|
-
"password",
|
|
37
|
-
"host",
|
|
38
|
-
"port",
|
|
39
|
-
"service_name",
|
|
40
|
-
"sid",
|
|
41
|
-
"wallet_location",
|
|
42
|
-
"wallet_password",
|
|
43
|
-
"config_dir",
|
|
44
|
-
"tcp_connect_timeout",
|
|
45
|
-
"retry_count",
|
|
46
|
-
"retry_delay",
|
|
47
|
-
"mode",
|
|
48
|
-
"events",
|
|
49
|
-
"edition",
|
|
50
|
-
}
|
|
51
|
-
)
|
|
52
34
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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]]
|
|
70
73
|
|
|
71
74
|
|
|
72
75
|
class OracleSyncConfig(SyncDatabaseConfig[OracleSyncConnection, "ConnectionPool", OracleSyncDriver]):
|
|
73
76
|
"""Configuration for Oracle synchronous database connections with direct field-based configuration."""
|
|
74
77
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
driver_type: type[OracleSyncDriver] = OracleSyncDriver
|
|
79
|
-
connection_type: type[OracleSyncConnection] = OracleSyncConnection
|
|
80
|
-
|
|
81
|
-
# Parameter style support information
|
|
82
|
-
supported_parameter_styles: ClassVar[tuple[str, ...]] = ("named_colon", "positional_colon")
|
|
83
|
-
"""OracleDB supports :name (named_colon) and :1 (positional_colon) parameter styles."""
|
|
84
|
-
|
|
85
|
-
default_parameter_style: ClassVar[str] = "named_colon"
|
|
86
|
-
"""OracleDB's preferred parameter style is :name (named_colon)."""
|
|
78
|
+
driver_type: ClassVar[type[OracleSyncDriver]] = OracleSyncDriver
|
|
79
|
+
connection_type: "ClassVar[type[OracleSyncConnection]]" = OracleSyncConnection
|
|
87
80
|
|
|
88
81
|
def __init__(
|
|
89
82
|
self,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
password: Optional[str] = None,
|
|
96
|
-
host: Optional[str] = None,
|
|
97
|
-
port: Optional[int] = None,
|
|
98
|
-
service_name: Optional[str] = None,
|
|
99
|
-
sid: Optional[str] = None,
|
|
100
|
-
wallet_location: Optional[str] = None,
|
|
101
|
-
wallet_password: Optional[str] = None,
|
|
102
|
-
config_dir: Optional[str] = None,
|
|
103
|
-
tcp_connect_timeout: Optional[float] = None,
|
|
104
|
-
retry_count: Optional[int] = None,
|
|
105
|
-
retry_delay: Optional[int] = None,
|
|
106
|
-
mode: Optional["AuthMode"] = None,
|
|
107
|
-
events: Optional[bool] = None,
|
|
108
|
-
edition: Optional[str] = None,
|
|
109
|
-
# Pool parameters
|
|
110
|
-
min: Optional[int] = None,
|
|
111
|
-
max: Optional[int] = None,
|
|
112
|
-
increment: Optional[int] = None,
|
|
113
|
-
threaded: Optional[bool] = None,
|
|
114
|
-
getmode: Optional[int] = None,
|
|
115
|
-
homogeneous: Optional[bool] = None,
|
|
116
|
-
timeout: Optional[int] = None,
|
|
117
|
-
wait_timeout: Optional[int] = None,
|
|
118
|
-
max_lifetime_session: Optional[int] = None,
|
|
119
|
-
session_callback: Optional["Callable[[Any, Any], None]"] = None,
|
|
120
|
-
max_sessions_per_shard: Optional[int] = None,
|
|
121
|
-
soda_metadata_cache: Optional[bool] = None,
|
|
122
|
-
ping_interval: Optional[int] = None,
|
|
123
|
-
pool_instance: Optional["ConnectionPool"] = None,
|
|
124
|
-
**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,
|
|
125
88
|
) -> None:
|
|
126
89
|
"""Initialize Oracle synchronous configuration.
|
|
127
90
|
|
|
128
91
|
Args:
|
|
92
|
+
pool_config: Pool configuration parameters
|
|
93
|
+
pool_instance: Existing pool instance to use
|
|
129
94
|
statement_config: Default SQL statement configuration
|
|
130
|
-
|
|
131
|
-
dsn: Connection string for the database
|
|
132
|
-
user: Username for database authentication
|
|
133
|
-
password: Password for database authentication
|
|
134
|
-
host: Database server hostname
|
|
135
|
-
port: Database server port number
|
|
136
|
-
service_name: Oracle service name
|
|
137
|
-
sid: Oracle System ID (SID)
|
|
138
|
-
wallet_location: Location of Oracle Wallet
|
|
139
|
-
wallet_password: Password for accessing Oracle Wallet
|
|
140
|
-
config_dir: Directory containing Oracle configuration files
|
|
141
|
-
tcp_connect_timeout: Timeout for establishing TCP connections
|
|
142
|
-
retry_count: Number of attempts to connect
|
|
143
|
-
retry_delay: Time in seconds between connection attempts
|
|
144
|
-
mode: Session mode (SYSDBA, SYSOPER, etc.)
|
|
145
|
-
events: If True, enables Oracle events for FAN and RLB
|
|
146
|
-
edition: Edition name for edition-based redefinition
|
|
147
|
-
min: Minimum number of connections in the pool
|
|
148
|
-
max: Maximum number of connections in the pool
|
|
149
|
-
increment: Number of connections to create when pool needs to grow
|
|
150
|
-
threaded: Whether the pool should be threaded
|
|
151
|
-
getmode: How connections are returned from the pool
|
|
152
|
-
homogeneous: Whether all connections use the same credentials
|
|
153
|
-
timeout: Time in seconds after which idle connections are closed
|
|
154
|
-
wait_timeout: Time in seconds to wait for an available connection
|
|
155
|
-
max_lifetime_session: Maximum time in seconds that a connection can remain in the pool
|
|
156
|
-
session_callback: Callback function called when a connection is returned to the pool
|
|
157
|
-
max_sessions_per_shard: Maximum number of sessions per shard
|
|
158
|
-
soda_metadata_cache: Whether to enable SODA metadata caching
|
|
159
|
-
ping_interval: Interval for pinging pooled connections
|
|
160
|
-
pool_instance: Optional existing connection pool instance
|
|
161
|
-
**kwargs: Additional parameters (stored in extras)
|
|
95
|
+
migration_config: Migration configuration
|
|
162
96
|
"""
|
|
163
|
-
# Store
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
self.retry_count = retry_count
|
|
176
|
-
self.retry_delay = retry_delay
|
|
177
|
-
self.mode = mode
|
|
178
|
-
self.events = events
|
|
179
|
-
self.edition = edition
|
|
180
|
-
|
|
181
|
-
# Store pool parameters as instance attributes
|
|
182
|
-
self.min = min
|
|
183
|
-
self.max = max
|
|
184
|
-
self.increment = increment
|
|
185
|
-
self.threaded = threaded
|
|
186
|
-
self.getmode = getmode
|
|
187
|
-
self.homogeneous = homogeneous
|
|
188
|
-
self.timeout = timeout
|
|
189
|
-
self.wait_timeout = wait_timeout
|
|
190
|
-
self.max_lifetime_session = max_lifetime_session
|
|
191
|
-
self.session_callback = session_callback
|
|
192
|
-
self.max_sessions_per_shard = max_sessions_per_shard
|
|
193
|
-
self.soda_metadata_cache = soda_metadata_cache
|
|
194
|
-
self.ping_interval = ping_interval
|
|
195
|
-
|
|
196
|
-
self.extras = kwargs or {}
|
|
197
|
-
|
|
198
|
-
# Store other config
|
|
199
|
-
self.statement_config = statement_config or SQLConfig()
|
|
200
|
-
self.default_row_type = default_row_type
|
|
201
|
-
|
|
202
|
-
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
|
+
)
|
|
203
109
|
|
|
204
110
|
def _create_pool(self) -> "ConnectionPool":
|
|
205
111
|
"""Create the actual connection pool."""
|
|
206
112
|
|
|
207
|
-
return oracledb.create_pool(**self.
|
|
113
|
+
return oracledb.create_pool(**dict(self.pool_config))
|
|
208
114
|
|
|
209
115
|
def _close_pool(self) -> None:
|
|
210
116
|
"""Close the actual connection pool."""
|
|
211
117
|
if self.pool_instance:
|
|
212
118
|
self.pool_instance.close()
|
|
213
119
|
|
|
214
|
-
def create_connection(self) -> OracleSyncConnection:
|
|
120
|
+
def create_connection(self) -> "OracleSyncConnection":
|
|
215
121
|
"""Create a single connection (not from pool).
|
|
216
122
|
|
|
217
123
|
Returns:
|
|
@@ -241,29 +147,21 @@ class OracleSyncConfig(SyncDatabaseConfig[OracleSyncConnection, "ConnectionPool"
|
|
|
241
147
|
self.pool_instance.release(conn)
|
|
242
148
|
|
|
243
149
|
@contextlib.contextmanager
|
|
244
|
-
def provide_session(
|
|
150
|
+
def provide_session(
|
|
151
|
+
self, *args: Any, statement_config: "Optional[StatementConfig]" = None, **kwargs: Any
|
|
152
|
+
) -> "Generator[OracleSyncDriver, None, None]":
|
|
245
153
|
"""Provide a driver session context manager.
|
|
246
154
|
|
|
247
155
|
Args:
|
|
248
156
|
*args: Additional arguments.
|
|
157
|
+
statement_config: Optional statement configuration override.
|
|
249
158
|
**kwargs: Additional keyword arguments.
|
|
250
159
|
|
|
251
160
|
Yields:
|
|
252
161
|
An OracleSyncDriver instance.
|
|
253
162
|
"""
|
|
254
163
|
with self.provide_connection(*args, **kwargs) as conn:
|
|
255
|
-
|
|
256
|
-
# Inject parameter style info if not already set
|
|
257
|
-
if statement_config.allowed_parameter_styles is None:
|
|
258
|
-
from dataclasses import replace
|
|
259
|
-
|
|
260
|
-
statement_config = replace(
|
|
261
|
-
statement_config,
|
|
262
|
-
allowed_parameter_styles=self.supported_parameter_styles,
|
|
263
|
-
default_parameter_style=self.default_parameter_style,
|
|
264
|
-
)
|
|
265
|
-
driver = self.driver_type(connection=conn, config=statement_config)
|
|
266
|
-
yield driver
|
|
164
|
+
yield self.driver_type(connection=conn, statement_config=statement_config or self.statement_config)
|
|
267
165
|
|
|
268
166
|
def provide_pool(self, *args: Any, **kwargs: Any) -> "ConnectionPool":
|
|
269
167
|
"""Provide pool instance.
|
|
@@ -284,211 +182,57 @@ class OracleSyncConfig(SyncDatabaseConfig[OracleSyncConnection, "ConnectionPool"
|
|
|
284
182
|
Returns:
|
|
285
183
|
Dictionary mapping type names to types.
|
|
286
184
|
"""
|
|
185
|
+
|
|
287
186
|
namespace = super().get_signature_namespace()
|
|
288
|
-
namespace.update(
|
|
187
|
+
namespace.update(
|
|
188
|
+
{
|
|
189
|
+
"OracleSyncConnection": OracleSyncConnection,
|
|
190
|
+
"OracleAsyncConnection": OracleAsyncConnection,
|
|
191
|
+
"OracleSyncCursor": OracleSyncCursor,
|
|
192
|
+
}
|
|
193
|
+
)
|
|
289
194
|
return namespace
|
|
290
195
|
|
|
291
|
-
@property
|
|
292
|
-
def connection_config_dict(self) -> dict[str, Any]:
|
|
293
|
-
"""Return the connection configuration as a dict for Oracle operations.
|
|
294
|
-
|
|
295
|
-
Returns all configuration parameters merged together.
|
|
296
|
-
"""
|
|
297
|
-
# Gather non-None parameters from all fields (connection + pool)
|
|
298
|
-
config = {
|
|
299
|
-
field: getattr(self, field)
|
|
300
|
-
for field in CONNECTION_FIELDS
|
|
301
|
-
if getattr(self, field, None) is not None and getattr(self, field) is not Empty
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
# Merge extras parameters
|
|
305
|
-
config.update(self.extras)
|
|
306
|
-
|
|
307
|
-
return config
|
|
308
|
-
|
|
309
|
-
@property
|
|
310
|
-
def pool_config_dict(self) -> dict[str, Any]:
|
|
311
|
-
"""Return the pool configuration as a dict for Oracle operations.
|
|
312
|
-
|
|
313
|
-
Returns all configuration parameters merged together.
|
|
314
|
-
"""
|
|
315
|
-
# Gather non-None parameters from all fields (connection + pool)
|
|
316
|
-
config = {
|
|
317
|
-
field: getattr(self, field)
|
|
318
|
-
for field in POOL_FIELDS
|
|
319
|
-
if getattr(self, field, None) is not None and getattr(self, field) is not Empty
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
# Merge extras parameters
|
|
323
|
-
config.update(self.extras)
|
|
324
|
-
|
|
325
|
-
return config
|
|
326
|
-
|
|
327
196
|
|
|
328
197
|
class OracleAsyncConfig(AsyncDatabaseConfig[OracleAsyncConnection, "AsyncConnectionPool", OracleAsyncDriver]):
|
|
329
198
|
"""Configuration for Oracle asynchronous database connections with direct field-based configuration."""
|
|
330
199
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
connection_type: type[OracleAsyncConnection] = OracleAsyncConnection
|
|
335
|
-
driver_type: type[OracleAsyncDriver] = OracleAsyncDriver
|
|
336
|
-
|
|
337
|
-
# Parameter style support information
|
|
338
|
-
supported_parameter_styles: ClassVar[tuple[str, ...]] = ("named_colon", "positional_colon")
|
|
339
|
-
"""OracleDB supports :name (named_colon) and :1 (positional_colon) parameter styles."""
|
|
340
|
-
|
|
341
|
-
default_parameter_style: ClassVar[str] = "named_colon"
|
|
342
|
-
"""OracleDB's preferred parameter style is :name (named_colon)."""
|
|
200
|
+
connection_type: "ClassVar[type[OracleAsyncConnection]]" = OracleAsyncConnection
|
|
201
|
+
driver_type: ClassVar[type[OracleAsyncDriver]] = OracleAsyncDriver
|
|
343
202
|
|
|
344
203
|
def __init__(
|
|
345
204
|
self,
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
password: Optional[str] = None,
|
|
352
|
-
host: Optional[str] = None,
|
|
353
|
-
port: Optional[int] = None,
|
|
354
|
-
service_name: Optional[str] = None,
|
|
355
|
-
sid: Optional[str] = None,
|
|
356
|
-
wallet_location: Optional[str] = None,
|
|
357
|
-
wallet_password: Optional[str] = None,
|
|
358
|
-
config_dir: Optional[str] = None,
|
|
359
|
-
tcp_connect_timeout: Optional[float] = None,
|
|
360
|
-
retry_count: Optional[int] = None,
|
|
361
|
-
retry_delay: Optional[int] = None,
|
|
362
|
-
mode: Optional["AuthMode"] = None,
|
|
363
|
-
events: Optional[bool] = None,
|
|
364
|
-
edition: Optional[str] = None,
|
|
365
|
-
# Pool parameters
|
|
366
|
-
min: Optional[int] = None,
|
|
367
|
-
max: Optional[int] = None,
|
|
368
|
-
increment: Optional[int] = None,
|
|
369
|
-
threaded: Optional[bool] = None,
|
|
370
|
-
getmode: Optional[int] = None,
|
|
371
|
-
homogeneous: Optional[bool] = None,
|
|
372
|
-
timeout: Optional[int] = None,
|
|
373
|
-
wait_timeout: Optional[int] = None,
|
|
374
|
-
max_lifetime_session: Optional[int] = None,
|
|
375
|
-
session_callback: Optional["Callable[[Any, Any], None]"] = None,
|
|
376
|
-
max_sessions_per_shard: Optional[int] = None,
|
|
377
|
-
soda_metadata_cache: Optional[bool] = None,
|
|
378
|
-
ping_interval: Optional[int] = None,
|
|
379
|
-
pool_instance: Optional["AsyncConnectionPool"] = None,
|
|
380
|
-
**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,
|
|
381
210
|
) -> None:
|
|
382
211
|
"""Initialize Oracle asynchronous configuration.
|
|
383
212
|
|
|
384
213
|
Args:
|
|
214
|
+
pool_config: Pool configuration parameters
|
|
215
|
+
pool_instance: Existing pool instance to use
|
|
385
216
|
statement_config: Default SQL statement configuration
|
|
386
|
-
|
|
387
|
-
dsn: Connection string for the database
|
|
388
|
-
user: Username for database authentication
|
|
389
|
-
password: Password for database authentication
|
|
390
|
-
host: Database server hostname
|
|
391
|
-
port: Database server port number
|
|
392
|
-
service_name: Oracle service name
|
|
393
|
-
sid: Oracle System ID (SID)
|
|
394
|
-
wallet_location: Location of Oracle Wallet
|
|
395
|
-
wallet_password: Password for accessing Oracle Wallet
|
|
396
|
-
config_dir: Directory containing Oracle configuration files
|
|
397
|
-
tcp_connect_timeout: Timeout for establishing TCP connections
|
|
398
|
-
retry_count: Number of attempts to connect
|
|
399
|
-
retry_delay: Time in seconds between connection attempts
|
|
400
|
-
mode: Session mode (SYSDBA, SYSOPER, etc.)
|
|
401
|
-
events: If True, enables Oracle events for FAN and RLB
|
|
402
|
-
edition: Edition name for edition-based redefinition
|
|
403
|
-
min: Minimum number of connections in the pool
|
|
404
|
-
max: Maximum number of connections in the pool
|
|
405
|
-
increment: Number of connections to create when pool needs to grow
|
|
406
|
-
threaded: Whether the pool should be threaded
|
|
407
|
-
getmode: How connections are returned from the pool
|
|
408
|
-
homogeneous: Whether all connections use the same credentials
|
|
409
|
-
timeout: Time in seconds after which idle connections are closed
|
|
410
|
-
wait_timeout: Time in seconds to wait for an available connection
|
|
411
|
-
max_lifetime_session: Maximum time in seconds that a connection can remain in the pool
|
|
412
|
-
session_callback: Callback function called when a connection is returned to the pool
|
|
413
|
-
max_sessions_per_shard: Maximum number of sessions per shard
|
|
414
|
-
soda_metadata_cache: Whether to enable SODA metadata caching
|
|
415
|
-
ping_interval: Interval for pinging pooled connections
|
|
416
|
-
pool_instance: Optional existing async connection pool instance
|
|
417
|
-
**kwargs: Additional parameters (stored in extras)
|
|
418
|
-
"""
|
|
419
|
-
# Store connection parameters as instance attributes
|
|
420
|
-
self.dsn = dsn
|
|
421
|
-
self.user = user
|
|
422
|
-
self.password = password
|
|
423
|
-
self.host = host
|
|
424
|
-
self.port = port
|
|
425
|
-
self.service_name = service_name
|
|
426
|
-
self.sid = sid
|
|
427
|
-
self.wallet_location = wallet_location
|
|
428
|
-
self.wallet_password = wallet_password
|
|
429
|
-
self.config_dir = config_dir
|
|
430
|
-
self.tcp_connect_timeout = tcp_connect_timeout
|
|
431
|
-
self.retry_count = retry_count
|
|
432
|
-
self.retry_delay = retry_delay
|
|
433
|
-
self.mode = mode
|
|
434
|
-
self.events = events
|
|
435
|
-
self.edition = edition
|
|
436
|
-
|
|
437
|
-
# Store pool parameters as instance attributes
|
|
438
|
-
self.min = min
|
|
439
|
-
self.max = max
|
|
440
|
-
self.increment = increment
|
|
441
|
-
self.threaded = threaded
|
|
442
|
-
self.getmode = getmode
|
|
443
|
-
self.homogeneous = homogeneous
|
|
444
|
-
self.timeout = timeout
|
|
445
|
-
self.wait_timeout = wait_timeout
|
|
446
|
-
self.max_lifetime_session = max_lifetime_session
|
|
447
|
-
self.session_callback = session_callback
|
|
448
|
-
self.max_sessions_per_shard = max_sessions_per_shard
|
|
449
|
-
self.soda_metadata_cache = soda_metadata_cache
|
|
450
|
-
self.ping_interval = ping_interval
|
|
451
|
-
|
|
452
|
-
self.extras = kwargs or {}
|
|
453
|
-
|
|
454
|
-
# Store other config
|
|
455
|
-
self.statement_config = statement_config or SQLConfig()
|
|
456
|
-
self.default_row_type = default_row_type
|
|
457
|
-
|
|
458
|
-
super().__init__()
|
|
459
|
-
|
|
460
|
-
@property
|
|
461
|
-
def connection_config_dict(self) -> dict[str, Any]:
|
|
462
|
-
"""Return the connection configuration as a dict for Oracle async operations.
|
|
463
|
-
|
|
464
|
-
Returns all configuration parameters merged together.
|
|
465
|
-
"""
|
|
466
|
-
# Gather non-None parameters
|
|
467
|
-
config = {field: getattr(self, field) for field in CONNECTION_FIELDS if getattr(self, field, None) is not None}
|
|
468
|
-
|
|
469
|
-
# Merge extras parameters
|
|
470
|
-
config.update(self.extras)
|
|
471
|
-
|
|
472
|
-
return config
|
|
473
|
-
|
|
474
|
-
@property
|
|
475
|
-
def pool_config_dict(self) -> dict[str, Any]:
|
|
476
|
-
"""Return the connection configuration as a dict for Oracle async operations.
|
|
477
|
-
|
|
478
|
-
Returns all configuration parameters merged together.
|
|
217
|
+
migration_config: Migration configuration
|
|
479
218
|
"""
|
|
480
|
-
#
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
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
|
+
)
|
|
487
231
|
|
|
488
232
|
async def _create_pool(self) -> "AsyncConnectionPool":
|
|
489
233
|
"""Create the actual async connection pool."""
|
|
490
234
|
|
|
491
|
-
return oracledb.create_pool_async(**self.
|
|
235
|
+
return oracledb.create_pool_async(**dict(self.pool_config))
|
|
492
236
|
|
|
493
237
|
async def _close_pool(self) -> None:
|
|
494
238
|
"""Close the actual async connection pool."""
|
|
@@ -506,7 +250,7 @@ class OracleAsyncConfig(AsyncDatabaseConfig[OracleAsyncConnection, "AsyncConnect
|
|
|
506
250
|
return cast("OracleAsyncConnection", await self.pool_instance.acquire())
|
|
507
251
|
|
|
508
252
|
@asynccontextmanager
|
|
509
|
-
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]":
|
|
510
254
|
"""Provide an async connection context manager.
|
|
511
255
|
|
|
512
256
|
Args:
|
|
@@ -525,29 +269,21 @@ class OracleAsyncConfig(AsyncDatabaseConfig[OracleAsyncConnection, "AsyncConnect
|
|
|
525
269
|
await self.pool_instance.release(conn)
|
|
526
270
|
|
|
527
271
|
@asynccontextmanager
|
|
528
|
-
async def provide_session(
|
|
272
|
+
async def provide_session(
|
|
273
|
+
self, *args: Any, statement_config: "Optional[StatementConfig]" = None, **kwargs: Any
|
|
274
|
+
) -> "AsyncGenerator[OracleAsyncDriver, None]":
|
|
529
275
|
"""Provide an async driver session context manager.
|
|
530
276
|
|
|
531
277
|
Args:
|
|
532
278
|
*args: Additional arguments.
|
|
279
|
+
statement_config: Optional statement configuration override.
|
|
533
280
|
**kwargs: Additional keyword arguments.
|
|
534
281
|
|
|
535
282
|
Yields:
|
|
536
283
|
An OracleAsyncDriver instance.
|
|
537
284
|
"""
|
|
538
285
|
async with self.provide_connection(*args, **kwargs) as conn:
|
|
539
|
-
|
|
540
|
-
# Inject parameter style info if not already set
|
|
541
|
-
if statement_config.allowed_parameter_styles is None:
|
|
542
|
-
from dataclasses import replace
|
|
543
|
-
|
|
544
|
-
statement_config = replace(
|
|
545
|
-
statement_config,
|
|
546
|
-
allowed_parameter_styles=self.supported_parameter_styles,
|
|
547
|
-
default_parameter_style=self.default_parameter_style,
|
|
548
|
-
)
|
|
549
|
-
driver = self.driver_type(connection=conn, config=statement_config)
|
|
550
|
-
yield driver
|
|
286
|
+
yield self.driver_type(connection=conn, statement_config=statement_config or self.statement_config)
|
|
551
287
|
|
|
552
288
|
async def provide_pool(self, *args: Any, **kwargs: Any) -> "AsyncConnectionPool":
|
|
553
289
|
"""Provide async pool instance.
|
|
@@ -568,6 +304,14 @@ class OracleAsyncConfig(AsyncDatabaseConfig[OracleAsyncConnection, "AsyncConnect
|
|
|
568
304
|
Returns:
|
|
569
305
|
Dictionary mapping type names to types.
|
|
570
306
|
"""
|
|
307
|
+
|
|
571
308
|
namespace = super().get_signature_namespace()
|
|
572
|
-
namespace.update(
|
|
309
|
+
namespace.update(
|
|
310
|
+
{
|
|
311
|
+
"OracleSyncConnection": OracleSyncConnection,
|
|
312
|
+
"OracleAsyncConnection": OracleAsyncConnection,
|
|
313
|
+
"OracleSyncCursor": OracleSyncCursor,
|
|
314
|
+
"OracleAsyncCursor": OracleAsyncCursor,
|
|
315
|
+
}
|
|
316
|
+
)
|
|
573
317
|
return namespace
|