sqlspec 0.11.0__py3-none-any.whl → 0.12.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.

Files changed (155) hide show
  1. sqlspec/__init__.py +16 -3
  2. sqlspec/_serialization.py +3 -10
  3. sqlspec/_sql.py +1147 -0
  4. sqlspec/_typing.py +343 -41
  5. sqlspec/adapters/adbc/__init__.py +2 -6
  6. sqlspec/adapters/adbc/config.py +474 -149
  7. sqlspec/adapters/adbc/driver.py +330 -644
  8. sqlspec/adapters/aiosqlite/__init__.py +2 -6
  9. sqlspec/adapters/aiosqlite/config.py +143 -57
  10. sqlspec/adapters/aiosqlite/driver.py +269 -462
  11. sqlspec/adapters/asyncmy/__init__.py +3 -8
  12. sqlspec/adapters/asyncmy/config.py +247 -202
  13. sqlspec/adapters/asyncmy/driver.py +217 -451
  14. sqlspec/adapters/asyncpg/__init__.py +4 -7
  15. sqlspec/adapters/asyncpg/config.py +329 -176
  16. sqlspec/adapters/asyncpg/driver.py +418 -498
  17. sqlspec/adapters/bigquery/__init__.py +2 -2
  18. sqlspec/adapters/bigquery/config.py +407 -0
  19. sqlspec/adapters/bigquery/driver.py +592 -634
  20. sqlspec/adapters/duckdb/__init__.py +4 -1
  21. sqlspec/adapters/duckdb/config.py +432 -321
  22. sqlspec/adapters/duckdb/driver.py +393 -436
  23. sqlspec/adapters/oracledb/__init__.py +3 -8
  24. sqlspec/adapters/oracledb/config.py +625 -0
  25. sqlspec/adapters/oracledb/driver.py +549 -942
  26. sqlspec/adapters/psqlpy/__init__.py +4 -7
  27. sqlspec/adapters/psqlpy/config.py +372 -203
  28. sqlspec/adapters/psqlpy/driver.py +197 -550
  29. sqlspec/adapters/psycopg/__init__.py +3 -8
  30. sqlspec/adapters/psycopg/config.py +741 -0
  31. sqlspec/adapters/psycopg/driver.py +732 -733
  32. sqlspec/adapters/sqlite/__init__.py +2 -6
  33. sqlspec/adapters/sqlite/config.py +146 -81
  34. sqlspec/adapters/sqlite/driver.py +243 -426
  35. sqlspec/base.py +220 -825
  36. sqlspec/config.py +354 -0
  37. sqlspec/driver/__init__.py +22 -0
  38. sqlspec/driver/_async.py +252 -0
  39. sqlspec/driver/_common.py +338 -0
  40. sqlspec/driver/_sync.py +261 -0
  41. sqlspec/driver/mixins/__init__.py +17 -0
  42. sqlspec/driver/mixins/_pipeline.py +523 -0
  43. sqlspec/driver/mixins/_result_utils.py +122 -0
  44. sqlspec/driver/mixins/_sql_translator.py +35 -0
  45. sqlspec/driver/mixins/_storage.py +993 -0
  46. sqlspec/driver/mixins/_type_coercion.py +131 -0
  47. sqlspec/exceptions.py +299 -7
  48. sqlspec/extensions/aiosql/__init__.py +10 -0
  49. sqlspec/extensions/aiosql/adapter.py +474 -0
  50. sqlspec/extensions/litestar/__init__.py +1 -6
  51. sqlspec/extensions/litestar/_utils.py +1 -5
  52. sqlspec/extensions/litestar/config.py +5 -6
  53. sqlspec/extensions/litestar/handlers.py +13 -12
  54. sqlspec/extensions/litestar/plugin.py +22 -24
  55. sqlspec/extensions/litestar/providers.py +37 -55
  56. sqlspec/loader.py +528 -0
  57. sqlspec/service/__init__.py +3 -0
  58. sqlspec/service/base.py +24 -0
  59. sqlspec/service/pagination.py +26 -0
  60. sqlspec/statement/__init__.py +21 -0
  61. sqlspec/statement/builder/__init__.py +54 -0
  62. sqlspec/statement/builder/_ddl_utils.py +119 -0
  63. sqlspec/statement/builder/_parsing_utils.py +135 -0
  64. sqlspec/statement/builder/base.py +328 -0
  65. sqlspec/statement/builder/ddl.py +1379 -0
  66. sqlspec/statement/builder/delete.py +80 -0
  67. sqlspec/statement/builder/insert.py +274 -0
  68. sqlspec/statement/builder/merge.py +95 -0
  69. sqlspec/statement/builder/mixins/__init__.py +65 -0
  70. sqlspec/statement/builder/mixins/_aggregate_functions.py +151 -0
  71. sqlspec/statement/builder/mixins/_case_builder.py +91 -0
  72. sqlspec/statement/builder/mixins/_common_table_expr.py +91 -0
  73. sqlspec/statement/builder/mixins/_delete_from.py +34 -0
  74. sqlspec/statement/builder/mixins/_from.py +61 -0
  75. sqlspec/statement/builder/mixins/_group_by.py +119 -0
  76. sqlspec/statement/builder/mixins/_having.py +35 -0
  77. sqlspec/statement/builder/mixins/_insert_from_select.py +48 -0
  78. sqlspec/statement/builder/mixins/_insert_into.py +36 -0
  79. sqlspec/statement/builder/mixins/_insert_values.py +69 -0
  80. sqlspec/statement/builder/mixins/_join.py +110 -0
  81. sqlspec/statement/builder/mixins/_limit_offset.py +53 -0
  82. sqlspec/statement/builder/mixins/_merge_clauses.py +405 -0
  83. sqlspec/statement/builder/mixins/_order_by.py +46 -0
  84. sqlspec/statement/builder/mixins/_pivot.py +82 -0
  85. sqlspec/statement/builder/mixins/_returning.py +37 -0
  86. sqlspec/statement/builder/mixins/_select_columns.py +60 -0
  87. sqlspec/statement/builder/mixins/_set_ops.py +122 -0
  88. sqlspec/statement/builder/mixins/_unpivot.py +80 -0
  89. sqlspec/statement/builder/mixins/_update_from.py +54 -0
  90. sqlspec/statement/builder/mixins/_update_set.py +91 -0
  91. sqlspec/statement/builder/mixins/_update_table.py +29 -0
  92. sqlspec/statement/builder/mixins/_where.py +374 -0
  93. sqlspec/statement/builder/mixins/_window_functions.py +86 -0
  94. sqlspec/statement/builder/protocols.py +20 -0
  95. sqlspec/statement/builder/select.py +206 -0
  96. sqlspec/statement/builder/update.py +178 -0
  97. sqlspec/statement/filters.py +571 -0
  98. sqlspec/statement/parameters.py +736 -0
  99. sqlspec/statement/pipelines/__init__.py +67 -0
  100. sqlspec/statement/pipelines/analyzers/__init__.py +9 -0
  101. sqlspec/statement/pipelines/analyzers/_analyzer.py +649 -0
  102. sqlspec/statement/pipelines/base.py +315 -0
  103. sqlspec/statement/pipelines/context.py +119 -0
  104. sqlspec/statement/pipelines/result_types.py +41 -0
  105. sqlspec/statement/pipelines/transformers/__init__.py +8 -0
  106. sqlspec/statement/pipelines/transformers/_expression_simplifier.py +256 -0
  107. sqlspec/statement/pipelines/transformers/_literal_parameterizer.py +623 -0
  108. sqlspec/statement/pipelines/transformers/_remove_comments.py +66 -0
  109. sqlspec/statement/pipelines/transformers/_remove_hints.py +81 -0
  110. sqlspec/statement/pipelines/validators/__init__.py +23 -0
  111. sqlspec/statement/pipelines/validators/_dml_safety.py +275 -0
  112. sqlspec/statement/pipelines/validators/_parameter_style.py +297 -0
  113. sqlspec/statement/pipelines/validators/_performance.py +703 -0
  114. sqlspec/statement/pipelines/validators/_security.py +990 -0
  115. sqlspec/statement/pipelines/validators/base.py +67 -0
  116. sqlspec/statement/result.py +527 -0
  117. sqlspec/statement/splitter.py +701 -0
  118. sqlspec/statement/sql.py +1198 -0
  119. sqlspec/storage/__init__.py +15 -0
  120. sqlspec/storage/backends/__init__.py +0 -0
  121. sqlspec/storage/backends/base.py +166 -0
  122. sqlspec/storage/backends/fsspec.py +315 -0
  123. sqlspec/storage/backends/obstore.py +464 -0
  124. sqlspec/storage/protocol.py +170 -0
  125. sqlspec/storage/registry.py +315 -0
  126. sqlspec/typing.py +157 -36
  127. sqlspec/utils/correlation.py +155 -0
  128. sqlspec/utils/deprecation.py +3 -6
  129. sqlspec/utils/fixtures.py +6 -11
  130. sqlspec/utils/logging.py +135 -0
  131. sqlspec/utils/module_loader.py +45 -43
  132. sqlspec/utils/serializers.py +4 -0
  133. sqlspec/utils/singleton.py +6 -8
  134. sqlspec/utils/sync_tools.py +15 -27
  135. sqlspec/utils/text.py +58 -26
  136. {sqlspec-0.11.0.dist-info → sqlspec-0.12.0.dist-info}/METADATA +100 -26
  137. sqlspec-0.12.0.dist-info/RECORD +145 -0
  138. sqlspec/adapters/bigquery/config/__init__.py +0 -3
  139. sqlspec/adapters/bigquery/config/_common.py +0 -40
  140. sqlspec/adapters/bigquery/config/_sync.py +0 -87
  141. sqlspec/adapters/oracledb/config/__init__.py +0 -9
  142. sqlspec/adapters/oracledb/config/_asyncio.py +0 -186
  143. sqlspec/adapters/oracledb/config/_common.py +0 -131
  144. sqlspec/adapters/oracledb/config/_sync.py +0 -186
  145. sqlspec/adapters/psycopg/config/__init__.py +0 -19
  146. sqlspec/adapters/psycopg/config/_async.py +0 -169
  147. sqlspec/adapters/psycopg/config/_common.py +0 -56
  148. sqlspec/adapters/psycopg/config/_sync.py +0 -168
  149. sqlspec/filters.py +0 -330
  150. sqlspec/mixins.py +0 -306
  151. sqlspec/statement.py +0 -378
  152. sqlspec-0.11.0.dist-info/RECORD +0 -69
  153. {sqlspec-0.11.0.dist-info → sqlspec-0.12.0.dist-info}/WHEEL +0 -0
  154. {sqlspec-0.11.0.dist-info → sqlspec-0.12.0.dist-info}/licenses/LICENSE +0 -0
  155. {sqlspec-0.11.0.dist-info → sqlspec-0.12.0.dist-info}/licenses/NOTICE +0 -0
@@ -1,9 +0,0 @@
1
- from sqlspec.adapters.oracledb.config._asyncio import OracleAsyncConfig, OracleAsyncPoolConfig
2
- from sqlspec.adapters.oracledb.config._sync import OracleSyncConfig, OracleSyncPoolConfig
3
-
4
- __all__ = (
5
- "OracleAsyncConfig",
6
- "OracleAsyncPoolConfig",
7
- "OracleSyncConfig",
8
- "OracleSyncPoolConfig",
9
- )
@@ -1,186 +0,0 @@
1
- from contextlib import asynccontextmanager
2
- from dataclasses import dataclass, field
3
- from typing import TYPE_CHECKING, Any, Optional, cast
4
-
5
- from oracledb import create_pool_async as oracledb_create_pool # pyright: ignore[reportUnknownVariableType]
6
-
7
- from sqlspec.adapters.oracledb.config._common import OracleGenericPoolConfig
8
- from sqlspec.adapters.oracledb.driver import OracleAsyncConnection, OracleAsyncDriver
9
- from sqlspec.base import AsyncDatabaseConfig
10
- from sqlspec.exceptions import ImproperConfigurationError
11
- from sqlspec.typing import dataclass_to_dict
12
-
13
- if TYPE_CHECKING:
14
- from collections.abc import AsyncGenerator, Awaitable
15
-
16
- from oracledb.pool import AsyncConnectionPool
17
-
18
-
19
- __all__ = (
20
- "OracleAsyncConfig",
21
- "OracleAsyncPoolConfig",
22
- )
23
-
24
-
25
- @dataclass
26
- class OracleAsyncPoolConfig(OracleGenericPoolConfig["OracleAsyncConnection", "AsyncConnectionPool"]):
27
- """Async Oracle Pool Config"""
28
-
29
-
30
- @dataclass
31
- class OracleAsyncConfig(AsyncDatabaseConfig["OracleAsyncConnection", "AsyncConnectionPool", "OracleAsyncDriver"]):
32
- """Oracle Async database Configuration.
33
-
34
- This class provides the base configuration for Oracle database connections, extending
35
- the generic database configuration with Oracle-specific settings. It supports both
36
- thin and thick modes of the python-oracledb driver.([1](https://python-oracledb.readthedocs.io/en/latest/index.html))
37
-
38
- The configuration supports all standard Oracle connection parameters and can be used
39
- with both synchronous and asynchronous connections. It includes support for features
40
- like Oracle Wallet, external authentication, connection pooling, and advanced security
41
- options.([2](https://python-oracledb.readthedocs.io/en/latest/user_guide/tuning.html))
42
- """
43
-
44
- pool_config: "Optional[OracleAsyncPoolConfig]" = None
45
- """Oracle Pool configuration"""
46
- pool_instance: "Optional[AsyncConnectionPool]" = None
47
- """Optional pool to use.
48
-
49
- If set, the plugin will use the provided pool rather than instantiate one.
50
- """
51
- connection_type: "type[OracleAsyncConnection]" = field(init=False, default_factory=lambda: OracleAsyncConnection)
52
- """Connection class to use.
53
-
54
- Defaults to :class:`AsyncConnection`.
55
- """
56
- driver_type: "type[OracleAsyncDriver]" = field(init=False, default_factory=lambda: OracleAsyncDriver) # type: ignore[type-abstract,unused-ignore]
57
- """Driver class to use.
58
-
59
- Defaults to :class:`OracleAsyncDriver`.
60
- """
61
-
62
- @property
63
- def connection_config_dict(self) -> "dict[str, Any]":
64
- """Return the connection configuration as a dict.
65
-
66
- Returns:
67
- A string keyed dict of config kwargs for the oracledb.connect function.
68
-
69
- Raises:
70
- ImproperConfigurationError: If the connection configuration is not provided.
71
- """
72
- if self.pool_config:
73
- # Filter out pool-specific parameters
74
- pool_only_params = {
75
- "min",
76
- "max",
77
- "increment",
78
- "timeout",
79
- "wait_timeout",
80
- "max_lifetime_session",
81
- "session_callback",
82
- }
83
- return dataclass_to_dict(
84
- self.pool_config,
85
- exclude_empty=True,
86
- convert_nested=False,
87
- exclude=pool_only_params.union({"pool_instance", "connection_type", "driver_type"}),
88
- )
89
- msg = "You must provide a 'pool_config' for this adapter."
90
- raise ImproperConfigurationError(msg)
91
-
92
- @property
93
- def pool_config_dict(self) -> "dict[str, Any]":
94
- """Return the pool configuration as a dict.
95
-
96
- Raises:
97
- ImproperConfigurationError: If no pool_config is provided but a pool_instance
98
-
99
- Returns:
100
- A string keyed dict of config kwargs for the Asyncpg :func:`create_pool <oracledb.pool.create_pool>`
101
- function.
102
- """
103
- if self.pool_config is not None:
104
- return dataclass_to_dict(
105
- self.pool_config,
106
- exclude_empty=True,
107
- convert_nested=False,
108
- exclude={"pool_instance", "connection_type", "driver_type"},
109
- )
110
- msg = "'pool_config' methods can not be used when a 'pool_instance' is provided."
111
- raise ImproperConfigurationError(msg)
112
-
113
- async def create_connection(self) -> "OracleAsyncConnection":
114
- """Create and return a new oracledb async connection from the pool.
115
-
116
- Returns:
117
- An AsyncConnection instance.
118
-
119
- Raises:
120
- ImproperConfigurationError: If the connection could not be created.
121
- """
122
- try:
123
- pool = await self.provide_pool()
124
- return cast("OracleAsyncConnection", await pool.acquire()) # type: ignore[no-any-return,unused-ignore]
125
- except Exception as e:
126
- msg = f"Could not configure the Oracle async connection. Error: {e!s}"
127
- raise ImproperConfigurationError(msg) from e
128
-
129
- async def create_pool(self) -> "AsyncConnectionPool":
130
- """Return a pool. If none exists yet, create one.
131
-
132
- Raises:
133
- ImproperConfigurationError: If neither pool_config nor pool_instance are provided,
134
- or if the pool could not be configured.
135
-
136
- Returns:
137
- Getter that returns the pool instance used by the plugin.
138
- """
139
- if self.pool_instance is not None:
140
- return self.pool_instance
141
-
142
- if self.pool_config is None:
143
- msg = "One of 'pool_config' or 'pool_instance' must be provided."
144
- raise ImproperConfigurationError(msg)
145
-
146
- pool_config = self.pool_config_dict
147
- self.pool_instance = oracledb_create_pool(**pool_config)
148
- if self.pool_instance is None: # pyright: ignore[reportUnnecessaryComparison]
149
- msg = "Could not configure the 'pool_instance'. Please check your configuration." # type: ignore[unreachable]
150
- raise ImproperConfigurationError(msg)
151
- return self.pool_instance
152
-
153
- def provide_pool(self, *args: "Any", **kwargs: "Any") -> "Awaitable[AsyncConnectionPool]":
154
- """Create a pool instance.
155
-
156
- Returns:
157
- A Pool instance.
158
- """
159
- return self.create_pool()
160
-
161
- @asynccontextmanager
162
- async def provide_connection(self, *args: "Any", **kwargs: "Any") -> "AsyncGenerator[OracleAsyncConnection, None]":
163
- """Create a connection instance.
164
-
165
- Yields:
166
- AsyncConnection: A connection instance.
167
- """
168
- db_pool = await self.provide_pool(*args, **kwargs)
169
- async with db_pool.acquire() as connection: # pyright: ignore[reportUnknownMemberType]
170
- yield connection
171
-
172
- @asynccontextmanager
173
- async def provide_session(self, *args: "Any", **kwargs: "Any") -> "AsyncGenerator[OracleAsyncDriver, None]":
174
- """Create and provide a database session.
175
-
176
- Yields:
177
- OracleAsyncDriver: A driver instance with an active connection.
178
- """
179
- async with self.provide_connection(*args, **kwargs) as connection:
180
- yield self.driver_type(connection)
181
-
182
- async def close_pool(self) -> None:
183
- """Close the connection pool."""
184
- if self.pool_instance is not None:
185
- await self.pool_instance.close()
186
- self.pool_instance = None
@@ -1,131 +0,0 @@
1
- from dataclasses import dataclass
2
- from typing import TYPE_CHECKING, Generic, TypeVar, Union
3
-
4
- from oracledb import ConnectionPool
5
-
6
- from sqlspec.base import GenericPoolConfig
7
- from sqlspec.typing import Empty
8
-
9
- if TYPE_CHECKING:
10
- import ssl
11
- from collections.abc import Callable
12
- from typing import Any
13
-
14
- from oracledb import AuthMode, ConnectParams, Purity
15
- from oracledb.connection import AsyncConnection, Connection
16
- from oracledb.pool import AsyncConnectionPool, ConnectionPool
17
-
18
- from sqlspec.typing import EmptyType
19
-
20
- __all__ = ("OracleGenericPoolConfig",)
21
-
22
-
23
- T = TypeVar("T")
24
-
25
- ConnectionT = TypeVar("ConnectionT", bound="Union[Connection, AsyncConnection]")
26
- PoolT = TypeVar("PoolT", bound="Union[ConnectionPool, AsyncConnectionPool]")
27
-
28
-
29
- @dataclass
30
- class OracleGenericPoolConfig(GenericPoolConfig, Generic[ConnectionT, PoolT]):
31
- """Configuration for Oracle database connection pools.
32
-
33
- This class provides configuration options for both synchronous and asynchronous Oracle
34
- database connection pools. It supports all standard Oracle connection parameters and pool-specific
35
- settings.([1](https://python-oracledb.readthedocs.io/en/latest/api_manual/module.html))
36
- """
37
-
38
- conn_class: "Union[type[ConnectionT], EmptyType]" = Empty
39
- """The connection class to use (Connection or AsyncConnection)"""
40
- dsn: "Union[str, EmptyType]" = Empty
41
- """Connection string for the database """
42
- pool: "Union[PoolT, EmptyType]" = Empty
43
- """Existing pool instance to use"""
44
- params: "Union[ConnectParams, EmptyType]" = Empty
45
- """Connection parameters object"""
46
- user: "Union[str, EmptyType]" = Empty
47
- """Username for database authentication"""
48
- proxy_user: "Union[str, EmptyType]" = Empty
49
- """Name of the proxy user to connect through"""
50
- password: "Union[str, EmptyType]" = Empty
51
- """Password for database authentication"""
52
- newpassword: "Union[str, EmptyType]" = Empty
53
- """New password for password change operations"""
54
- wallet_password: "Union[str, EmptyType]" = Empty
55
- """Password for accessing Oracle Wallet"""
56
- access_token: "Union[str, tuple[str, ...], Callable[[], str], EmptyType]" = Empty
57
- """Token for token-based authentication"""
58
- host: "Union[str, EmptyType]" = Empty
59
- """Database server hostname"""
60
- port: "Union[int, EmptyType]" = Empty
61
- """Database server port number"""
62
- protocol: "Union[str, EmptyType]" = Empty
63
- """Network protocol (TCP or TCPS)"""
64
- https_proxy: "Union[str, EmptyType]" = Empty
65
- """HTTPS proxy server address"""
66
- https_proxy_port: "Union[int, EmptyType]" = Empty
67
- """HTTPS proxy server port"""
68
- service_name: "Union[str, EmptyType]" = Empty
69
- """Oracle service name"""
70
- sid: "Union[str, EmptyType]" = Empty
71
- """Oracle System ID (SID)"""
72
- server_type: "Union[str, EmptyType]" = Empty
73
- """Server type (dedicated, shared, pooled, or drcp)"""
74
- cclass: "Union[str, EmptyType]" = Empty
75
- """Connection class for database resident connection pooling"""
76
- purity: "Union[Purity, EmptyType]" = Empty
77
- """Session purity (NEW, SELF, or DEFAULT)"""
78
- expire_time: "Union[int, EmptyType]" = Empty
79
- """Time in minutes after which idle connections are closed"""
80
- retry_count: "Union[int, EmptyType]" = Empty
81
- """Number of attempts to connect"""
82
- retry_delay: "Union[int, EmptyType]" = Empty
83
- """Time in seconds between connection attempts"""
84
- tcp_connect_timeout: "Union[float, EmptyType]" = Empty
85
- """Timeout for establishing TCP connections"""
86
- ssl_server_dn_match: "Union[bool, EmptyType]" = Empty
87
- """If True, verify server certificate DN"""
88
- ssl_server_cert_dn: "Union[str, EmptyType]" = Empty
89
- """Expected server certificate DN"""
90
- wallet_location: "Union[str, EmptyType]" = Empty
91
- """Location of Oracle Wallet"""
92
- events: "Union[bool, EmptyType]" = Empty
93
- """If True, enables Oracle events for FAN and RLB"""
94
- externalauth: "Union[bool, EmptyType]" = Empty
95
- """If True, uses external authentication"""
96
- mode: "Union[AuthMode, EmptyType]" = Empty
97
- """Session mode (SYSDBA, SYSOPER, etc.)"""
98
- disable_oob: "Union[bool, EmptyType]" = Empty
99
- """If True, disables Oracle out-of-band breaks"""
100
- stmtcachesize: "Union[int, EmptyType]" = Empty
101
- """Size of the statement cache"""
102
- edition: "Union[str, EmptyType]" = Empty
103
- """Edition name for edition-based redefinition"""
104
- tag: "Union[str, EmptyType]" = Empty
105
- """Connection pool tag"""
106
- matchanytag: "Union[bool, EmptyType]" = Empty
107
- """If True, allows connections with different tags"""
108
- config_dir: "Union[str, EmptyType]" = Empty
109
- """Directory containing Oracle configuration files"""
110
- appcontext: "Union[list[str], EmptyType]" = Empty
111
- """Application context list"""
112
- shardingkey: "Union[list[str], EmptyType]" = Empty
113
- """Sharding key list"""
114
- supershardingkey: "Union[list[str], EmptyType]" = Empty
115
- """Super sharding key list"""
116
- debug_jdwp: "Union[str, EmptyType]" = Empty
117
- """JDWP debugging string"""
118
- connection_id_prefix: "Union[str, EmptyType]" = Empty
119
- """Prefix for connection identifiers"""
120
- ssl_context: "Union[Any, EmptyType]" = Empty
121
- """SSL context for TCPS connections"""
122
- sdu: "Union[int, EmptyType]" = Empty
123
- """Session data unit size"""
124
- pool_boundary: "Union[str, EmptyType]" = Empty
125
- """Connection pool boundary (statement or transaction)"""
126
- use_tcp_fast_open: "Union[bool, EmptyType]" = Empty
127
- """If True, enables TCP Fast Open"""
128
- ssl_version: "Union[ssl.TLSVersion, EmptyType]" = Empty
129
- """SSL/TLS protocol version"""
130
- handle: "Union[int, EmptyType]" = Empty
131
- """Oracle service context handle"""
@@ -1,186 +0,0 @@
1
- from contextlib import contextmanager
2
- from dataclasses import dataclass, field
3
- from typing import TYPE_CHECKING, Any, Optional
4
-
5
- from oracledb import create_pool as oracledb_create_pool # pyright: ignore[reportUnknownVariableType]
6
-
7
- from sqlspec.adapters.oracledb.config._common import OracleGenericPoolConfig
8
- from sqlspec.adapters.oracledb.driver import OracleSyncConnection, OracleSyncDriver
9
- from sqlspec.base import SyncDatabaseConfig
10
- from sqlspec.exceptions import ImproperConfigurationError
11
- from sqlspec.typing import dataclass_to_dict
12
-
13
- if TYPE_CHECKING:
14
- from collections.abc import Generator
15
-
16
- from oracledb.pool import ConnectionPool
17
-
18
-
19
- __all__ = (
20
- "OracleSyncConfig",
21
- "OracleSyncPoolConfig",
22
- )
23
-
24
-
25
- @dataclass
26
- class OracleSyncPoolConfig(OracleGenericPoolConfig["OracleSyncConnection", "ConnectionPool"]):
27
- """Sync Oracle Pool Config"""
28
-
29
-
30
- @dataclass
31
- class OracleSyncConfig(SyncDatabaseConfig["OracleSyncConnection", "ConnectionPool", "OracleSyncDriver"]):
32
- """Oracle Sync database Configuration.
33
-
34
- This class provides the base configuration for Oracle database connections, extending
35
- the generic database configuration with Oracle-specific settings. It supports both
36
- thin and thick modes of the python-oracledb driver.([1](https://python-oracledb.readthedocs.io/en/latest/index.html))
37
-
38
- The configuration supports all standard Oracle connection parameters and can be used
39
- with both synchronous and asynchronous connections. It includes support for features
40
- like Oracle Wallet, external authentication, connection pooling, and advanced security
41
- options.([2](https://python-oracledb.readthedocs.io/en/latest/user_guide/tuning.html))
42
- """
43
-
44
- pool_config: "Optional[OracleSyncPoolConfig]" = None
45
- """Oracle Pool configuration"""
46
- pool_instance: "Optional[ConnectionPool]" = None
47
- """Optional pool to use.
48
-
49
- If set, the plugin will use the provided pool rather than instantiate one.
50
- """
51
- connection_type: "type[OracleSyncConnection]" = field(init=False, default_factory=lambda: OracleSyncConnection) # pyright: ignore
52
- """Connection class to use.
53
-
54
- Defaults to :class:`Connection`.
55
- """
56
- driver_type: "type[OracleSyncDriver]" = field(init=False, default_factory=lambda: OracleSyncDriver) # type: ignore[type-abstract,unused-ignore]
57
- """Driver class to use.
58
-
59
- Defaults to :class:`OracleSyncDriver`.
60
- """
61
-
62
- @property
63
- def connection_config_dict(self) -> "dict[str, Any]":
64
- """Return the connection configuration as a dict.
65
-
66
- Returns:
67
- A string keyed dict of config kwargs for the oracledb.connect function.
68
-
69
- Raises:
70
- ImproperConfigurationError: If the connection configuration is not provided.
71
- """
72
- if self.pool_config:
73
- # Filter out pool-specific parameters
74
- pool_only_params = {
75
- "min",
76
- "max",
77
- "increment",
78
- "timeout",
79
- "wait_timeout",
80
- "max_lifetime_session",
81
- "session_callback",
82
- }
83
- return dataclass_to_dict(
84
- self.pool_config,
85
- exclude_empty=True,
86
- convert_nested=False,
87
- exclude=pool_only_params.union({"pool_instance", "connection_type", "driver_type"}),
88
- )
89
- msg = "You must provide a 'pool_config' for this adapter."
90
- raise ImproperConfigurationError(msg)
91
-
92
- @property
93
- def pool_config_dict(self) -> "dict[str, Any]":
94
- """Return the pool configuration as a dict.
95
-
96
- Raises:
97
- ImproperConfigurationError: If no pool_config is provided but a pool_instance
98
-
99
- Returns:
100
- A string keyed dict of config kwargs for the Asyncpg :func:`create_pool <oracledb.pool.create_pool>`
101
- function.
102
- """
103
- if self.pool_config:
104
- return dataclass_to_dict(
105
- self.pool_config,
106
- exclude_empty=True,
107
- convert_nested=False,
108
- exclude={"pool_instance", "connection_type", "driver_type"},
109
- )
110
- msg = "'pool_config' methods can not be used when a 'pool_instance' is provided."
111
- raise ImproperConfigurationError(msg)
112
-
113
- def create_connection(self) -> "OracleSyncConnection":
114
- """Create and return a new oracledb connection from the pool.
115
-
116
- Returns:
117
- A Connection instance.
118
-
119
- Raises:
120
- ImproperConfigurationError: If the connection could not be created.
121
- """
122
- try:
123
- pool = self.provide_pool()
124
- return pool.acquire()
125
- except Exception as e:
126
- msg = f"Could not configure the Oracle connection. Error: {e!s}"
127
- raise ImproperConfigurationError(msg) from e
128
-
129
- def create_pool(self) -> "ConnectionPool":
130
- """Return a pool. If none exists yet, create one.
131
-
132
- Raises:
133
- ImproperConfigurationError: If neither pool_config nor pool_instance is provided,
134
- or if the pool could not be configured.
135
-
136
- Returns:
137
- Getter that returns the pool instance used by the plugin.
138
- """
139
- if self.pool_instance is not None:
140
- return self.pool_instance
141
-
142
- if self.pool_config is None:
143
- msg = "One of 'pool_config' or 'pool_instance' must be provided."
144
- raise ImproperConfigurationError(msg)
145
-
146
- pool_config = self.pool_config_dict
147
- self.pool_instance = oracledb_create_pool(**pool_config)
148
- if self.pool_instance is None: # pyright: ignore[reportUnnecessaryComparison]
149
- msg = "Could not configure the 'pool_instance'. Please check your configuration." # type: ignore[unreachable]
150
- raise ImproperConfigurationError(msg)
151
- return self.pool_instance
152
-
153
- def provide_pool(self, *args: "Any", **kwargs: "Any") -> "ConnectionPool":
154
- """Create a pool instance.
155
-
156
- Returns:
157
- A Pool instance.
158
- """
159
- return self.create_pool()
160
-
161
- @contextmanager
162
- def provide_connection(self, *args: "Any", **kwargs: "Any") -> "Generator[OracleSyncConnection, None, None]":
163
- """Create a connection instance.
164
-
165
- Yields:
166
- Connection: A connection instance from the pool.
167
- """
168
- db_pool = self.provide_pool(*args, **kwargs)
169
- with db_pool.acquire() as connection: # pyright: ignore[reportUnknownMemberType]
170
- yield connection
171
-
172
- @contextmanager
173
- def provide_session(self, *args: "Any", **kwargs: "Any") -> "Generator[OracleSyncDriver, None, None]":
174
- """Create and provide a database session.
175
-
176
- Yields:
177
- OracleSyncDriver: A driver instance with an active connection.
178
- """
179
- with self.provide_connection(*args, **kwargs) as connection:
180
- yield self.driver_type(connection)
181
-
182
- def close_pool(self) -> None:
183
- """Close the connection pool."""
184
- if self.pool_instance is not None:
185
- self.pool_instance.close()
186
- self.pool_instance = None
@@ -1,19 +0,0 @@
1
- from sqlspec.adapters.psycopg.config._async import PsycopgAsyncConfig, PsycopgAsyncPoolConfig
2
- from sqlspec.adapters.psycopg.config._sync import PsycopgSyncConfig, PsycopgSyncPoolConfig
3
- from sqlspec.adapters.psycopg.driver import (
4
- PsycopgAsyncConnection,
5
- PsycopgAsyncDriver,
6
- PsycopgSyncConnection,
7
- PsycopgSyncDriver,
8
- )
9
-
10
- __all__ = (
11
- "PsycopgAsyncConfig",
12
- "PsycopgAsyncConnection",
13
- "PsycopgAsyncDriver",
14
- "PsycopgAsyncPoolConfig",
15
- "PsycopgSyncConfig",
16
- "PsycopgSyncConnection",
17
- "PsycopgSyncDriver",
18
- "PsycopgSyncPoolConfig",
19
- )