sqlspec 0.5.0__py3-none-any.whl → 0.7.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 +0 -1
- sqlspec/__metadata__.py +1 -3
- sqlspec/_serialization.py +55 -8
- sqlspec/_typing.py +69 -20
- sqlspec/adapters/adbc/config.py +8 -13
- sqlspec/adapters/aiosqlite/__init__.py +1 -1
- sqlspec/adapters/aiosqlite/config.py +15 -24
- sqlspec/adapters/asyncmy/__init__.py +1 -1
- sqlspec/adapters/asyncmy/config.py +46 -46
- sqlspec/adapters/asyncpg/config.py +28 -33
- sqlspec/adapters/duckdb/config.py +75 -79
- sqlspec/adapters/oracledb/config/_asyncio.py +23 -18
- sqlspec/adapters/oracledb/config/_common.py +52 -72
- sqlspec/adapters/oracledb/config/_sync.py +21 -16
- sqlspec/adapters/psycopg/config/_async.py +17 -17
- sqlspec/adapters/psycopg/config/_common.py +17 -34
- sqlspec/adapters/psycopg/config/_sync.py +16 -17
- sqlspec/adapters/sqlite/config.py +13 -15
- sqlspec/base.py +148 -8
- sqlspec/exceptions.py +4 -6
- sqlspec/extensions/litestar/config.py +0 -0
- sqlspec/extensions/litestar/plugin.py +21 -12
- sqlspec/filters.py +11 -13
- sqlspec/typing.py +110 -127
- sqlspec/utils/deprecation.py +8 -10
- sqlspec/utils/fixtures.py +3 -5
- sqlspec/utils/module_loader.py +4 -6
- sqlspec/utils/text.py +2 -3
- {sqlspec-0.5.0.dist-info → sqlspec-0.7.0.dist-info}/METADATA +24 -15
- sqlspec-0.7.0.dist-info/RECORD +46 -0
- sqlspec-0.7.0.dist-info/licenses/LICENSE +21 -0
- sqlspec-0.5.0.dist-info/RECORD +0 -44
- {sqlspec-0.5.0.dist-info → sqlspec-0.7.0.dist-info}/WHEEL +0 -0
- {sqlspec-0.5.0.dist-info → sqlspec-0.7.0.dist-info}/licenses/NOTICE +0 -0
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
1
|
from dataclasses import dataclass
|
|
4
|
-
from typing import TYPE_CHECKING, Generic, TypeVar
|
|
2
|
+
from typing import TYPE_CHECKING, Generic, TypeVar, Union
|
|
5
3
|
|
|
6
4
|
from oracledb import ConnectionPool
|
|
7
5
|
|
|
8
|
-
from sqlspec.base import
|
|
6
|
+
from sqlspec.base import GenericPoolConfig
|
|
9
7
|
from sqlspec.typing import Empty
|
|
10
8
|
|
|
11
9
|
if TYPE_CHECKING:
|
|
@@ -19,16 +17,13 @@ if TYPE_CHECKING:
|
|
|
19
17
|
|
|
20
18
|
from sqlspec.typing import EmptyType
|
|
21
19
|
|
|
22
|
-
__all__ = (
|
|
23
|
-
"OracleGenericDatabaseConfig",
|
|
24
|
-
"OracleGenericPoolConfig",
|
|
25
|
-
)
|
|
20
|
+
__all__ = ("OracleGenericPoolConfig",)
|
|
26
21
|
|
|
27
22
|
|
|
28
23
|
T = TypeVar("T")
|
|
29
24
|
|
|
30
|
-
ConnectionT = TypeVar("ConnectionT", bound="Connection
|
|
31
|
-
PoolT = TypeVar("PoolT", bound="ConnectionPool
|
|
25
|
+
ConnectionT = TypeVar("ConnectionT", bound="Union[Connection, AsyncConnection]")
|
|
26
|
+
PoolT = TypeVar("PoolT", bound="Union[ConnectionPool, AsyncConnectionPool]")
|
|
32
27
|
|
|
33
28
|
|
|
34
29
|
@dataclass
|
|
@@ -40,112 +35,97 @@ class OracleGenericPoolConfig(Generic[ConnectionT, PoolT], GenericPoolConfig):
|
|
|
40
35
|
settings.([1](https://python-oracledb.readthedocs.io/en/latest/api_manual/module.html))
|
|
41
36
|
"""
|
|
42
37
|
|
|
43
|
-
conn_class: type[ConnectionT]
|
|
38
|
+
conn_class: "Union[type[ConnectionT], EmptyType]" = Empty
|
|
44
39
|
"""The connection class to use (Connection or AsyncConnection)"""
|
|
45
|
-
dsn: str
|
|
40
|
+
dsn: "Union[str, EmptyType]" = Empty
|
|
46
41
|
"""Connection string for the database """
|
|
47
|
-
pool: PoolT
|
|
42
|
+
pool: "Union[PoolT, EmptyType]" = Empty
|
|
48
43
|
"""Existing pool instance to use"""
|
|
49
|
-
params: ConnectParams
|
|
44
|
+
params: "Union[ConnectParams, EmptyType]" = Empty
|
|
50
45
|
"""Connection parameters object"""
|
|
51
|
-
user: str
|
|
46
|
+
user: "Union[str, EmptyType]" = Empty
|
|
52
47
|
"""Username for database authentication"""
|
|
53
|
-
proxy_user: str
|
|
48
|
+
proxy_user: "Union[str, EmptyType]" = Empty
|
|
54
49
|
"""Name of the proxy user to connect through"""
|
|
55
|
-
password: str
|
|
50
|
+
password: "Union[str, EmptyType]" = Empty
|
|
56
51
|
"""Password for database authentication"""
|
|
57
|
-
newpassword: str
|
|
52
|
+
newpassword: "Union[str, EmptyType]" = Empty
|
|
58
53
|
"""New password for password change operations"""
|
|
59
|
-
wallet_password: str
|
|
54
|
+
wallet_password: "Union[str, EmptyType]" = Empty
|
|
60
55
|
"""Password for accessing Oracle Wallet"""
|
|
61
|
-
access_token: str
|
|
56
|
+
access_token: "Union[str, tuple[str, ...], Callable[[], str], EmptyType]" = Empty
|
|
62
57
|
"""Token for token-based authentication"""
|
|
63
|
-
host: str
|
|
58
|
+
host: "Union[str, EmptyType]" = Empty
|
|
64
59
|
"""Database server hostname"""
|
|
65
|
-
port: int
|
|
60
|
+
port: "Union[int, EmptyType]" = Empty
|
|
66
61
|
"""Database server port number"""
|
|
67
|
-
protocol: str
|
|
62
|
+
protocol: "Union[str, EmptyType]" = Empty
|
|
68
63
|
"""Network protocol (TCP or TCPS)"""
|
|
69
|
-
https_proxy: str
|
|
64
|
+
https_proxy: "Union[str, EmptyType]" = Empty
|
|
70
65
|
"""HTTPS proxy server address"""
|
|
71
|
-
https_proxy_port: int
|
|
66
|
+
https_proxy_port: "Union[int, EmptyType]" = Empty
|
|
72
67
|
"""HTTPS proxy server port"""
|
|
73
|
-
service_name: str
|
|
68
|
+
service_name: "Union[str, EmptyType]" = Empty
|
|
74
69
|
"""Oracle service name"""
|
|
75
|
-
sid: str
|
|
70
|
+
sid: "Union[str, EmptyType]" = Empty
|
|
76
71
|
"""Oracle System ID (SID)"""
|
|
77
|
-
server_type: str
|
|
72
|
+
server_type: "Union[str, EmptyType]" = Empty
|
|
78
73
|
"""Server type (dedicated, shared, pooled, or drcp)"""
|
|
79
|
-
cclass: str
|
|
74
|
+
cclass: "Union[str, EmptyType]" = Empty
|
|
80
75
|
"""Connection class for database resident connection pooling"""
|
|
81
|
-
purity: Purity
|
|
76
|
+
purity: "Union[Purity, EmptyType]" = Empty
|
|
82
77
|
"""Session purity (NEW, SELF, or DEFAULT)"""
|
|
83
|
-
expire_time: int
|
|
78
|
+
expire_time: "Union[int, EmptyType]" = Empty
|
|
84
79
|
"""Time in minutes after which idle connections are closed"""
|
|
85
|
-
retry_count: int
|
|
80
|
+
retry_count: "Union[int, EmptyType]" = Empty
|
|
86
81
|
"""Number of attempts to connect"""
|
|
87
|
-
retry_delay: int
|
|
82
|
+
retry_delay: "Union[int, EmptyType]" = Empty
|
|
88
83
|
"""Time in seconds between connection attempts"""
|
|
89
|
-
tcp_connect_timeout: float
|
|
84
|
+
tcp_connect_timeout: "Union[float, EmptyType]" = Empty
|
|
90
85
|
"""Timeout for establishing TCP connections"""
|
|
91
|
-
ssl_server_dn_match: bool
|
|
86
|
+
ssl_server_dn_match: "Union[bool, EmptyType]" = Empty
|
|
92
87
|
"""If True, verify server certificate DN"""
|
|
93
|
-
ssl_server_cert_dn: str
|
|
88
|
+
ssl_server_cert_dn: "Union[str, EmptyType]" = Empty
|
|
94
89
|
"""Expected server certificate DN"""
|
|
95
|
-
wallet_location: str
|
|
90
|
+
wallet_location: "Union[str, EmptyType]" = Empty
|
|
96
91
|
"""Location of Oracle Wallet"""
|
|
97
|
-
events: bool
|
|
92
|
+
events: "Union[bool, EmptyType]" = Empty
|
|
98
93
|
"""If True, enables Oracle events for FAN and RLB"""
|
|
99
|
-
externalauth: bool
|
|
94
|
+
externalauth: "Union[bool, EmptyType]" = Empty
|
|
100
95
|
"""If True, uses external authentication"""
|
|
101
|
-
mode: AuthMode
|
|
96
|
+
mode: "Union[AuthMode, EmptyType]" = Empty
|
|
102
97
|
"""Session mode (SYSDBA, SYSOPER, etc.)"""
|
|
103
|
-
disable_oob: bool
|
|
98
|
+
disable_oob: "Union[bool, EmptyType]" = Empty
|
|
104
99
|
"""If True, disables Oracle out-of-band breaks"""
|
|
105
|
-
stmtcachesize: int
|
|
100
|
+
stmtcachesize: "Union[int, EmptyType]" = Empty
|
|
106
101
|
"""Size of the statement cache"""
|
|
107
|
-
edition: str
|
|
102
|
+
edition: "Union[str, EmptyType]" = Empty
|
|
108
103
|
"""Edition name for edition-based redefinition"""
|
|
109
|
-
tag: str
|
|
104
|
+
tag: "Union[str, EmptyType]" = Empty
|
|
110
105
|
"""Connection pool tag"""
|
|
111
|
-
matchanytag: bool
|
|
106
|
+
matchanytag: "Union[bool, EmptyType]" = Empty
|
|
112
107
|
"""If True, allows connections with different tags"""
|
|
113
|
-
config_dir: str
|
|
108
|
+
config_dir: "Union[str, EmptyType]" = Empty
|
|
114
109
|
"""Directory containing Oracle configuration files"""
|
|
115
|
-
appcontext: list[str]
|
|
110
|
+
appcontext: "Union[list[str], EmptyType]" = Empty
|
|
116
111
|
"""Application context list"""
|
|
117
|
-
shardingkey: list[str]
|
|
112
|
+
shardingkey: "Union[list[str], EmptyType]" = Empty
|
|
118
113
|
"""Sharding key list"""
|
|
119
|
-
supershardingkey: list[str]
|
|
114
|
+
supershardingkey: "Union[list[str], EmptyType]" = Empty
|
|
120
115
|
"""Super sharding key list"""
|
|
121
|
-
debug_jdwp: str
|
|
116
|
+
debug_jdwp: "Union[str, EmptyType]" = Empty
|
|
122
117
|
"""JDWP debugging string"""
|
|
123
|
-
connection_id_prefix: str
|
|
118
|
+
connection_id_prefix: "Union[str, EmptyType]" = Empty
|
|
124
119
|
"""Prefix for connection identifiers"""
|
|
125
|
-
ssl_context: Any
|
|
120
|
+
ssl_context: "Union[Any, EmptyType]" = Empty
|
|
126
121
|
"""SSL context for TCPS connections"""
|
|
127
|
-
sdu: int
|
|
122
|
+
sdu: "Union[int, EmptyType]" = Empty
|
|
128
123
|
"""Session data unit size"""
|
|
129
|
-
pool_boundary: str
|
|
124
|
+
pool_boundary: "Union[str, EmptyType]" = Empty
|
|
130
125
|
"""Connection pool boundary (statement or transaction)"""
|
|
131
|
-
use_tcp_fast_open: bool
|
|
126
|
+
use_tcp_fast_open: "Union[bool, EmptyType]" = Empty
|
|
132
127
|
"""If True, enables TCP Fast Open"""
|
|
133
|
-
ssl_version: ssl.TLSVersion
|
|
128
|
+
ssl_version: "Union[ssl.TLSVersion, EmptyType]" = Empty
|
|
134
129
|
"""SSL/TLS protocol version"""
|
|
135
|
-
handle: int
|
|
130
|
+
handle: "Union[int, EmptyType]" = Empty
|
|
136
131
|
"""Oracle service context handle"""
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
@dataclass
|
|
140
|
-
class OracleGenericDatabaseConfig(DatabaseConfigProtocol[ConnectionT, PoolT], GenericDatabaseConfig):
|
|
141
|
-
"""Oracle database Configuration.
|
|
142
|
-
|
|
143
|
-
This class provides the base configuration for Oracle database connections, extending
|
|
144
|
-
the generic database configuration with Oracle-specific settings. It supports both
|
|
145
|
-
thin and thick modes of the python-oracledb driver.([1](https://python-oracledb.readthedocs.io/en/latest/index.html))
|
|
146
|
-
|
|
147
|
-
The configuration supports all standard Oracle connection parameters and can be used
|
|
148
|
-
with both synchronous and asynchronous connections. It includes support for features
|
|
149
|
-
like Oracle Wallet, external authentication, connection pooling, and advanced security
|
|
150
|
-
options.([2](https://python-oracledb.readthedocs.io/en/latest/user_guide/tuning.html))
|
|
151
|
-
"""
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
1
|
from contextlib import contextmanager
|
|
4
2
|
from dataclasses import dataclass
|
|
5
|
-
from typing import TYPE_CHECKING
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
6
4
|
|
|
7
|
-
from oracledb import create_pool as oracledb_create_pool
|
|
5
|
+
from oracledb import create_pool as oracledb_create_pool # pyright: ignore[reportUnknownVariableType]
|
|
8
6
|
from oracledb.connection import Connection
|
|
9
7
|
from oracledb.pool import ConnectionPool
|
|
10
8
|
|
|
11
9
|
from sqlspec.adapters.oracledb.config._common import (
|
|
12
|
-
OracleGenericDatabaseConfig,
|
|
13
10
|
OracleGenericPoolConfig,
|
|
14
11
|
)
|
|
12
|
+
from sqlspec.base import SyncDatabaseConfig
|
|
15
13
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
16
14
|
from sqlspec.typing import dataclass_to_dict
|
|
17
15
|
|
|
@@ -31,22 +29,29 @@ class OracleSyncPoolConfig(OracleGenericPoolConfig[Connection, ConnectionPool]):
|
|
|
31
29
|
|
|
32
30
|
|
|
33
31
|
@dataclass
|
|
34
|
-
class OracleSyncDatabaseConfig(
|
|
35
|
-
"""Oracle database Configuration.
|
|
32
|
+
class OracleSyncDatabaseConfig(SyncDatabaseConfig[Connection, ConnectionPool]):
|
|
33
|
+
"""Oracle Sync database Configuration.
|
|
34
|
+
|
|
35
|
+
This class provides the base configuration for Oracle database connections, extending
|
|
36
|
+
the generic database configuration with Oracle-specific settings. It supports both
|
|
37
|
+
thin and thick modes of the python-oracledb driver.([1](https://python-oracledb.readthedocs.io/en/latest/index.html))
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
The configuration supports all standard Oracle connection parameters and can be used
|
|
40
|
+
with both synchronous and asynchronous connections. It includes support for features
|
|
41
|
+
like Oracle Wallet, external authentication, connection pooling, and advanced security
|
|
42
|
+
options.([2](https://python-oracledb.readthedocs.io/en/latest/user_guide/tuning.html))
|
|
43
|
+
"""
|
|
39
44
|
|
|
40
|
-
pool_config: OracleSyncPoolConfig
|
|
45
|
+
pool_config: "Optional[OracleSyncPoolConfig]" = None
|
|
41
46
|
"""Oracle Pool configuration"""
|
|
42
|
-
pool_instance: ConnectionPool
|
|
47
|
+
pool_instance: "Optional[ConnectionPool]" = None
|
|
43
48
|
"""Optional pool to use.
|
|
44
49
|
|
|
45
50
|
If set, the plugin will use the provided pool rather than instantiate one.
|
|
46
51
|
"""
|
|
47
52
|
|
|
48
53
|
@property
|
|
49
|
-
def pool_config_dict(self) -> dict[str, Any]:
|
|
54
|
+
def pool_config_dict(self) -> "dict[str, Any]":
|
|
50
55
|
"""Return the pool configuration as a dict.
|
|
51
56
|
|
|
52
57
|
Returns:
|
|
@@ -58,7 +63,7 @@ class OracleSyncDatabaseConfig(OracleGenericDatabaseConfig[Connection, Connectio
|
|
|
58
63
|
msg = "'pool_config' methods can not be used when a 'pool_instance' is provided."
|
|
59
64
|
raise ImproperConfigurationError(msg)
|
|
60
65
|
|
|
61
|
-
def create_pool(self) -> ConnectionPool:
|
|
66
|
+
def create_pool(self) -> "ConnectionPool":
|
|
62
67
|
"""Return a pool. If none exists yet, create one.
|
|
63
68
|
|
|
64
69
|
Returns:
|
|
@@ -74,11 +79,11 @@ class OracleSyncDatabaseConfig(OracleGenericDatabaseConfig[Connection, Connectio
|
|
|
74
79
|
pool_config = self.pool_config_dict
|
|
75
80
|
self.pool_instance = oracledb_create_pool(**pool_config)
|
|
76
81
|
if self.pool_instance is None: # pyright: ignore[reportUnnecessaryComparison]
|
|
77
|
-
msg = "Could not configure the 'pool_instance'. Please check your configuration."
|
|
82
|
+
msg = "Could not configure the 'pool_instance'. Please check your configuration." # type: ignore[unreachable]
|
|
78
83
|
raise ImproperConfigurationError(msg)
|
|
79
84
|
return self.pool_instance
|
|
80
85
|
|
|
81
|
-
def provide_pool(self, *args: Any, **kwargs: Any) -> ConnectionPool:
|
|
86
|
+
def provide_pool(self, *args: "Any", **kwargs: "Any") -> "ConnectionPool":
|
|
82
87
|
"""Create a pool instance.
|
|
83
88
|
|
|
84
89
|
Returns:
|
|
@@ -87,7 +92,7 @@ class OracleSyncDatabaseConfig(OracleGenericDatabaseConfig[Connection, Connectio
|
|
|
87
92
|
return self.create_pool()
|
|
88
93
|
|
|
89
94
|
@contextmanager
|
|
90
|
-
def provide_connection(self, *args: Any, **kwargs: Any) -> Generator[Connection, None, None]:
|
|
95
|
+
def provide_connection(self, *args: "Any", **kwargs: "Any") -> "Generator[Connection, None, None]":
|
|
91
96
|
"""Create a connection instance.
|
|
92
97
|
|
|
93
98
|
Returns:
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
1
|
from contextlib import asynccontextmanager
|
|
4
2
|
from dataclasses import dataclass
|
|
5
|
-
from typing import TYPE_CHECKING
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
6
4
|
|
|
7
5
|
from psycopg import AsyncConnection
|
|
8
6
|
from psycopg_pool import AsyncConnectionPool
|
|
9
7
|
|
|
10
|
-
from sqlspec.adapters.psycopg.config._common import
|
|
11
|
-
|
|
12
|
-
PsycoPgGenericPoolConfig,
|
|
13
|
-
)
|
|
8
|
+
from sqlspec.adapters.psycopg.config._common import PsycoPgGenericPoolConfig
|
|
9
|
+
from sqlspec.base import AsyncDatabaseConfig
|
|
14
10
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
15
11
|
from sqlspec.typing import dataclass_to_dict
|
|
16
12
|
|
|
@@ -31,26 +27,30 @@ class PsycoPgAsyncPoolConfig(PsycoPgGenericPoolConfig[AsyncConnection, AsyncConn
|
|
|
31
27
|
|
|
32
28
|
|
|
33
29
|
@dataclass
|
|
34
|
-
class PsycoPgAsyncDatabaseConfig(
|
|
35
|
-
"""Async Psycopg database Configuration.
|
|
30
|
+
class PsycoPgAsyncDatabaseConfig(AsyncDatabaseConfig[AsyncConnection, AsyncConnectionPool]):
|
|
31
|
+
"""Async Psycopg database Configuration.
|
|
32
|
+
|
|
33
|
+
This class provides the base configuration for Psycopg database connections, extending
|
|
34
|
+
the generic database configuration with Psycopg-specific settings.([1](https://www.psycopg.org/psycopg3/docs/api/connections.html))
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
The configuration supports all standard Psycopg connection parameters and can be used
|
|
37
|
+
with both synchronous and asynchronous connections.([2](https://www.psycopg.org/psycopg3/docs/api/connections.html))
|
|
38
|
+
"""
|
|
39
39
|
|
|
40
|
-
pool_config: PsycoPgAsyncPoolConfig
|
|
40
|
+
pool_config: "Optional[PsycoPgAsyncPoolConfig]" = None
|
|
41
41
|
"""Psycopg Pool configuration"""
|
|
42
|
-
pool_instance: AsyncConnectionPool
|
|
42
|
+
pool_instance: "Optional[AsyncConnectionPool]" = None
|
|
43
43
|
"""Optional pool to use"""
|
|
44
44
|
|
|
45
45
|
@property
|
|
46
|
-
def pool_config_dict(self) -> dict[str, Any]:
|
|
46
|
+
def pool_config_dict(self) -> "dict[str, Any]":
|
|
47
47
|
"""Return the pool configuration as a dict."""
|
|
48
48
|
if self.pool_config:
|
|
49
49
|
return dataclass_to_dict(self.pool_config, exclude_empty=True, convert_nested=False)
|
|
50
50
|
msg = "'pool_config' methods can not be used when a 'pool_instance' is provided."
|
|
51
51
|
raise ImproperConfigurationError(msg)
|
|
52
52
|
|
|
53
|
-
async def create_pool(self) -> AsyncConnectionPool:
|
|
53
|
+
async def create_pool(self) -> "AsyncConnectionPool":
|
|
54
54
|
"""Create and return a connection pool."""
|
|
55
55
|
if self.pool_instance is not None:
|
|
56
56
|
return self.pool_instance
|
|
@@ -66,12 +66,12 @@ class PsycoPgAsyncDatabaseConfig(PsycoPgGenericDatabaseConfig[AsyncConnection, A
|
|
|
66
66
|
raise ImproperConfigurationError(msg)
|
|
67
67
|
return self.pool_instance
|
|
68
68
|
|
|
69
|
-
def provide_pool(self, *args: Any, **kwargs: Any) -> Awaitable[AsyncConnectionPool]:
|
|
69
|
+
def provide_pool(self, *args: "Any", **kwargs: "Any") -> "Awaitable[AsyncConnectionPool]":
|
|
70
70
|
"""Create and return a connection pool."""
|
|
71
71
|
return self.create_pool()
|
|
72
72
|
|
|
73
73
|
@asynccontextmanager
|
|
74
|
-
async def provide_connection(self, *args: Any, **kwargs: Any) -> AsyncGenerator[AsyncConnection, None]:
|
|
74
|
+
async def provide_connection(self, *args: "Any", **kwargs: "Any") -> "AsyncGenerator[AsyncConnection, None]":
|
|
75
75
|
"""Create and provide a database connection."""
|
|
76
76
|
pool = await self.provide_pool(*args, **kwargs)
|
|
77
77
|
async with pool.connection() as connection:
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
1
|
from dataclasses import dataclass
|
|
4
|
-
from typing import TYPE_CHECKING, Generic, TypeVar
|
|
2
|
+
from typing import TYPE_CHECKING, Generic, TypeVar, Union
|
|
5
3
|
|
|
6
|
-
from sqlspec.base import
|
|
4
|
+
from sqlspec.base import GenericPoolConfig
|
|
7
5
|
from sqlspec.typing import Empty
|
|
8
6
|
|
|
9
7
|
if TYPE_CHECKING:
|
|
@@ -16,14 +14,11 @@ if TYPE_CHECKING:
|
|
|
16
14
|
from sqlspec.typing import EmptyType
|
|
17
15
|
|
|
18
16
|
|
|
19
|
-
__all__ = (
|
|
20
|
-
"PsycoPgGenericDatabaseConfig",
|
|
21
|
-
"PsycoPgGenericPoolConfig",
|
|
22
|
-
)
|
|
17
|
+
__all__ = ("PsycoPgGenericPoolConfig",)
|
|
23
18
|
|
|
24
19
|
|
|
25
|
-
ConnectionT = TypeVar("ConnectionT", bound="Connection
|
|
26
|
-
PoolT = TypeVar("PoolT", bound="ConnectionPool
|
|
20
|
+
ConnectionT = TypeVar("ConnectionT", bound="Union[Connection, AsyncConnection]")
|
|
21
|
+
PoolT = TypeVar("PoolT", bound="Union[ConnectionPool, AsyncConnectionPool]")
|
|
27
22
|
|
|
28
23
|
|
|
29
24
|
@dataclass
|
|
@@ -35,39 +30,27 @@ class PsycoPgGenericPoolConfig(Generic[ConnectionT, PoolT], GenericPoolConfig):
|
|
|
35
30
|
settings.([1](https://www.psycopg.org/psycopg3/docs/api/pool.html))
|
|
36
31
|
"""
|
|
37
32
|
|
|
38
|
-
conninfo: str
|
|
33
|
+
conninfo: "Union[str, EmptyType]" = Empty
|
|
39
34
|
"""Connection string in libpq format"""
|
|
40
|
-
kwargs: dict[str, Any]
|
|
35
|
+
kwargs: "Union[dict[str, Any], EmptyType]" = Empty
|
|
41
36
|
"""Additional connection parameters"""
|
|
42
|
-
min_size: int
|
|
37
|
+
min_size: "Union[int, EmptyType]" = Empty
|
|
43
38
|
"""Minimum number of connections in the pool"""
|
|
44
|
-
max_size: int
|
|
39
|
+
max_size: "Union[int, EmptyType]" = Empty
|
|
45
40
|
"""Maximum number of connections in the pool"""
|
|
46
|
-
name: str
|
|
41
|
+
name: "Union[str, EmptyType]" = Empty
|
|
47
42
|
"""Name of the connection pool"""
|
|
48
|
-
timeout: float
|
|
43
|
+
timeout: "Union[float, EmptyType]" = Empty
|
|
49
44
|
"""Timeout for acquiring connections"""
|
|
50
|
-
max_waiting: int
|
|
45
|
+
max_waiting: "Union[int, EmptyType]" = Empty
|
|
51
46
|
"""Maximum number of waiting clients"""
|
|
52
|
-
max_lifetime: float
|
|
47
|
+
max_lifetime: "Union[float, EmptyType]" = Empty
|
|
53
48
|
"""Maximum connection lifetime"""
|
|
54
|
-
max_idle: float
|
|
49
|
+
max_idle: "Union[float, EmptyType]" = Empty
|
|
55
50
|
"""Maximum idle time for connections"""
|
|
56
|
-
reconnect_timeout: float
|
|
51
|
+
reconnect_timeout: "Union[float, EmptyType]" = Empty
|
|
57
52
|
"""Time between reconnection attempts"""
|
|
58
|
-
num_workers: int
|
|
53
|
+
num_workers: "Union[int, EmptyType]" = Empty
|
|
59
54
|
"""Number of background workers"""
|
|
60
|
-
configure: Callable[[ConnectionT], None]
|
|
55
|
+
configure: "Union[Callable[[ConnectionT], None], EmptyType]" = Empty
|
|
61
56
|
"""Callback to configure new connections"""
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
@dataclass
|
|
65
|
-
class PsycoPgGenericDatabaseConfig(DatabaseConfigProtocol[ConnectionT, PoolT], GenericDatabaseConfig):
|
|
66
|
-
"""Psycopg database Configuration.
|
|
67
|
-
|
|
68
|
-
This class provides the base configuration for Psycopg database connections, extending
|
|
69
|
-
the generic database configuration with Psycopg-specific settings.([1](https://www.psycopg.org/psycopg3/docs/api/connections.html))
|
|
70
|
-
|
|
71
|
-
The configuration supports all standard Psycopg connection parameters and can be used
|
|
72
|
-
with both synchronous and asynchronous connections.([2](https://www.psycopg.org/psycopg3/docs/api/connections.html))
|
|
73
|
-
"""
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
1
|
from contextlib import contextmanager
|
|
4
2
|
from dataclasses import dataclass
|
|
5
|
-
from typing import TYPE_CHECKING
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
6
4
|
|
|
7
5
|
from psycopg import Connection
|
|
8
6
|
from psycopg_pool import ConnectionPool
|
|
9
7
|
|
|
10
|
-
from sqlspec.adapters.psycopg.config._common import
|
|
11
|
-
|
|
12
|
-
PsycoPgGenericPoolConfig,
|
|
13
|
-
)
|
|
8
|
+
from sqlspec.adapters.psycopg.config._common import PsycoPgGenericPoolConfig
|
|
9
|
+
from sqlspec.base import SyncDatabaseConfig
|
|
14
10
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
15
11
|
from sqlspec.typing import dataclass_to_dict
|
|
16
12
|
|
|
@@ -31,26 +27,29 @@ class PsycoPgSyncPoolConfig(PsycoPgGenericPoolConfig[Connection, ConnectionPool]
|
|
|
31
27
|
|
|
32
28
|
|
|
33
29
|
@dataclass
|
|
34
|
-
class PsycoPgSyncDatabaseConfig(
|
|
35
|
-
"""Sync Psycopg database Configuration.
|
|
30
|
+
class PsycoPgSyncDatabaseConfig(SyncDatabaseConfig[Connection, ConnectionPool]):
|
|
31
|
+
"""Sync Psycopg database Configuration.
|
|
32
|
+
This class provides the base configuration for Psycopg database connections, extending
|
|
33
|
+
the generic database configuration with Psycopg-specific settings.([1](https://www.psycopg.org/psycopg3/docs/api/connections.html))
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
The configuration supports all standard Psycopg connection parameters and can be used
|
|
36
|
+
with both synchronous and asynchronous connections.([2](https://www.psycopg.org/psycopg3/docs/api/connections.html))
|
|
37
|
+
"""
|
|
39
38
|
|
|
40
|
-
pool_config: PsycoPgSyncPoolConfig
|
|
39
|
+
pool_config: "Optional[PsycoPgSyncPoolConfig]" = None
|
|
41
40
|
"""Psycopg Pool configuration"""
|
|
42
|
-
pool_instance: ConnectionPool
|
|
41
|
+
pool_instance: "Optional[ConnectionPool]" = None
|
|
43
42
|
"""Optional pool to use"""
|
|
44
43
|
|
|
45
44
|
@property
|
|
46
|
-
def pool_config_dict(self) -> dict[str, Any]:
|
|
45
|
+
def pool_config_dict(self) -> "dict[str, Any]":
|
|
47
46
|
"""Return the pool configuration as a dict."""
|
|
48
47
|
if self.pool_config:
|
|
49
48
|
return dataclass_to_dict(self.pool_config, exclude_empty=True, convert_nested=False)
|
|
50
49
|
msg = "'pool_config' methods can not be used when a 'pool_instance' is provided."
|
|
51
50
|
raise ImproperConfigurationError(msg)
|
|
52
51
|
|
|
53
|
-
def create_pool(self) -> ConnectionPool:
|
|
52
|
+
def create_pool(self) -> "ConnectionPool":
|
|
54
53
|
"""Create and return a connection pool."""
|
|
55
54
|
if self.pool_instance is not None:
|
|
56
55
|
return self.pool_instance
|
|
@@ -66,12 +65,12 @@ class PsycoPgSyncDatabaseConfig(PsycoPgGenericDatabaseConfig[Connection, Connect
|
|
|
66
65
|
raise ImproperConfigurationError(msg)
|
|
67
66
|
return self.pool_instance
|
|
68
67
|
|
|
69
|
-
def provide_pool(self, *args: Any, **kwargs: Any) -> ConnectionPool:
|
|
68
|
+
def provide_pool(self, *args: "Any", **kwargs: "Any") -> "ConnectionPool":
|
|
70
69
|
"""Create and return a connection pool."""
|
|
71
70
|
return self.create_pool()
|
|
72
71
|
|
|
73
72
|
@contextmanager
|
|
74
|
-
def provide_connection(self, *args: Any, **kwargs: Any) -> Generator[Connection, None, None]:
|
|
73
|
+
def provide_connection(self, *args: "Any", **kwargs: "Any") -> "Generator[Connection, None, None]":
|
|
75
74
|
"""Create and provide a database connection."""
|
|
76
75
|
pool = self.provide_pool(*args, **kwargs)
|
|
77
76
|
with pool.connection() as connection:
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
1
|
from contextlib import contextmanager
|
|
4
2
|
from dataclasses import dataclass
|
|
5
|
-
from typing import TYPE_CHECKING, Any, Literal
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Literal, Optional, Union
|
|
6
4
|
|
|
7
|
-
from sqlspec.base import
|
|
5
|
+
from sqlspec.base import NoPoolSyncConfig
|
|
8
6
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
9
7
|
from sqlspec.typing import Empty, EmptyType, dataclass_to_dict
|
|
10
8
|
|
|
@@ -16,7 +14,7 @@ __all__ = ("SqliteConfig",)
|
|
|
16
14
|
|
|
17
15
|
|
|
18
16
|
@dataclass
|
|
19
|
-
class SqliteConfig(
|
|
17
|
+
class SqliteConfig(NoPoolSyncConfig["Connection"]):
|
|
20
18
|
"""Configuration for SQLite database connections.
|
|
21
19
|
|
|
22
20
|
This class provides configuration options for SQLite database connections, wrapping all parameters
|
|
@@ -28,29 +26,29 @@ class SqliteConfig(NoPoolConfig["Connection"], GenericDatabaseConfig):
|
|
|
28
26
|
database: str = ":memory:"
|
|
29
27
|
"""The path to the database file to be opened. Pass ":memory:" to open a connection to a database that resides in RAM instead of on disk."""
|
|
30
28
|
|
|
31
|
-
timeout: float
|
|
29
|
+
timeout: "Union[float, EmptyType]" = Empty
|
|
32
30
|
"""How many seconds the connection should wait before raising an OperationalError when a table is locked. If another thread or process has acquired a shared lock, a wait for the specified timeout occurs."""
|
|
33
31
|
|
|
34
|
-
detect_types: int
|
|
32
|
+
detect_types: "Union[int, EmptyType]" = Empty
|
|
35
33
|
"""Control whether and how data types are detected. It can be 0 (default) or a combination of PARSE_DECLTYPES and PARSE_COLNAMES."""
|
|
36
34
|
|
|
37
|
-
isolation_level: Literal[
|
|
35
|
+
isolation_level: "Optional[Union[Literal['DEFERRED', 'IMMEDIATE', 'EXCLUSIVE'], EmptyType]]" = Empty
|
|
38
36
|
"""The isolation_level of the connection. This can be None for autocommit mode or one of "DEFERRED", "IMMEDIATE" or "EXCLUSIVE"."""
|
|
39
37
|
|
|
40
|
-
check_same_thread: bool
|
|
38
|
+
check_same_thread: "Union[bool, EmptyType]" = Empty
|
|
41
39
|
"""If True (default), ProgrammingError is raised if the database connection is used by a thread other than the one that created it. If False, the connection may be shared across multiple threads."""
|
|
42
40
|
|
|
43
|
-
factory: type[Connection]
|
|
41
|
+
factory: "Union[type[Connection], EmptyType]" = Empty
|
|
44
42
|
"""A custom Connection class factory. If given, must be a callable that returns a Connection instance."""
|
|
45
43
|
|
|
46
|
-
cached_statements: int
|
|
44
|
+
cached_statements: "Union[int, EmptyType]" = Empty
|
|
47
45
|
"""The number of statements that SQLite will cache for this connection. The default is 128."""
|
|
48
46
|
|
|
49
|
-
uri: bool
|
|
47
|
+
uri: "Union[bool, EmptyType]" = Empty
|
|
50
48
|
"""If set to True, database is interpreted as a URI with supported options."""
|
|
51
49
|
|
|
52
50
|
@property
|
|
53
|
-
def connection_config_dict(self) -> dict[str, Any]:
|
|
51
|
+
def connection_config_dict(self) -> "dict[str, Any]":
|
|
54
52
|
"""Return the connection configuration as a dict.
|
|
55
53
|
|
|
56
54
|
Returns:
|
|
@@ -58,7 +56,7 @@ class SqliteConfig(NoPoolConfig["Connection"], GenericDatabaseConfig):
|
|
|
58
56
|
"""
|
|
59
57
|
return dataclass_to_dict(self, exclude_empty=True, convert_nested=False)
|
|
60
58
|
|
|
61
|
-
def create_connection(self) -> Connection:
|
|
59
|
+
def create_connection(self) -> "Connection":
|
|
62
60
|
"""Create and return a new database connection.
|
|
63
61
|
|
|
64
62
|
Returns:
|
|
@@ -76,7 +74,7 @@ class SqliteConfig(NoPoolConfig["Connection"], GenericDatabaseConfig):
|
|
|
76
74
|
raise ImproperConfigurationError(msg) from e
|
|
77
75
|
|
|
78
76
|
@contextmanager
|
|
79
|
-
def provide_connection(self, *args: Any, **kwargs: Any) -> Generator[Connection, None, None]:
|
|
77
|
+
def provide_connection(self, *args: "Any", **kwargs: "Any") -> "Generator[Connection, None, None]":
|
|
80
78
|
"""Create and provide a database connection.
|
|
81
79
|
|
|
82
80
|
Yields:
|