sqlspec 0.4.0__py3-none-any.whl → 0.6.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/__metadata__.py +1 -1
- sqlspec/_serialization.py +1 -1
- sqlspec/_typing.py +31 -1
- sqlspec/adapters/adbc/config.py +7 -7
- sqlspec/adapters/aiosqlite/config.py +11 -18
- sqlspec/adapters/asyncmy/config.py +9 -4
- sqlspec/adapters/asyncpg/config.py +10 -10
- sqlspec/adapters/duckdb/__init__.py +3 -0
- sqlspec/adapters/duckdb/config.py +15 -14
- sqlspec/adapters/oracledb/__init__.py +1 -1
- sqlspec/adapters/oracledb/config/_asyncio.py +17 -7
- sqlspec/adapters/oracledb/config/_common.py +7 -25
- sqlspec/adapters/oracledb/config/_sync.py +17 -7
- sqlspec/adapters/psycopg/config/__init__.py +2 -2
- sqlspec/adapters/psycopg/config/_async.py +13 -8
- sqlspec/adapters/psycopg/config/_common.py +3 -18
- sqlspec/adapters/psycopg/config/_sync.py +12 -8
- sqlspec/adapters/sqlite/config.py +3 -3
- sqlspec/base.py +221 -0
- sqlspec/extensions/litestar/config.py +0 -0
- sqlspec/extensions/litestar/plugin.py +18 -10
- sqlspec/filters.py +2 -1
- sqlspec/typing.py +119 -31
- sqlspec/utils/__init__.py +0 -0
- sqlspec/utils/deprecation.py +111 -0
- sqlspec/utils/fixtures.py +66 -0
- sqlspec/utils/module_loader.py +94 -0
- sqlspec/utils/text.py +46 -0
- sqlspec-0.6.0.dist-info/METADATA +128 -0
- sqlspec-0.6.0.dist-info/RECORD +46 -0
- sqlspec-0.6.0.dist-info/licenses/LICENSE +21 -0
- sqlspec/config.py +0 -16
- sqlspec-0.4.0.dist-info/METADATA +0 -84
- sqlspec-0.4.0.dist-info/RECORD +0 -39
- {sqlspec-0.4.0.dist-info → sqlspec-0.6.0.dist-info}/WHEEL +0 -0
- {sqlspec-0.4.0.dist-info → sqlspec-0.6.0.dist-info}/licenses/NOTICE +0 -0
sqlspec/__metadata__.py
CHANGED
sqlspec/_serialization.py
CHANGED
|
@@ -13,7 +13,7 @@ try:
|
|
|
13
13
|
|
|
14
14
|
except ImportError:
|
|
15
15
|
try:
|
|
16
|
-
from orjson import dumps as _encode_json # pyright: ignore[reportMissingImports]
|
|
16
|
+
from orjson import dumps as _encode_json # pyright: ignore[reportMissingImports,reportUnknownVariableType]
|
|
17
17
|
from orjson import loads as decode_json # type: ignore[no-redef]
|
|
18
18
|
|
|
19
19
|
def encode_json(data: Any) -> str:
|
sqlspec/_typing.py
CHANGED
|
@@ -29,7 +29,6 @@ class DataclassProtocol(Protocol):
|
|
|
29
29
|
T = TypeVar("T")
|
|
30
30
|
T_co = TypeVar("T_co", covariant=True)
|
|
31
31
|
|
|
32
|
-
|
|
33
32
|
try:
|
|
34
33
|
from pydantic import BaseModel, FailFast, TypeAdapter
|
|
35
34
|
|
|
@@ -110,6 +109,35 @@ except ImportError:
|
|
|
110
109
|
UNSET = UnsetType.UNSET # pyright: ignore[reportConstantRedefinition]
|
|
111
110
|
MSGSPEC_INSTALLED = False # pyright: ignore[reportConstantRedefinition]
|
|
112
111
|
|
|
112
|
+
try:
|
|
113
|
+
from litestar.dto.data_structures import DTOData # pyright: ignore[reportUnknownVariableType]
|
|
114
|
+
|
|
115
|
+
LITESTAR_INSTALLED = True
|
|
116
|
+
except ImportError:
|
|
117
|
+
|
|
118
|
+
@runtime_checkable
|
|
119
|
+
class DTOData(Protocol[T]): # type: ignore[no-redef]
|
|
120
|
+
"""Placeholder implementation"""
|
|
121
|
+
|
|
122
|
+
__slots__ = ("_backend", "_data_as_builtins")
|
|
123
|
+
|
|
124
|
+
def __init__(self, backend: Any, data_as_builtins: Any) -> None:
|
|
125
|
+
"""Placeholder init"""
|
|
126
|
+
|
|
127
|
+
def create_instance(self, **kwargs: Any) -> T:
|
|
128
|
+
"""Placeholder implementation"""
|
|
129
|
+
return cast("T", kwargs)
|
|
130
|
+
|
|
131
|
+
def update_instance(self, instance: T, **kwargs: Any) -> T:
|
|
132
|
+
"""Placeholder implementation"""
|
|
133
|
+
return cast("T", kwargs)
|
|
134
|
+
|
|
135
|
+
def as_builtins(self) -> Any:
|
|
136
|
+
"""Placeholder implementation"""
|
|
137
|
+
return {}
|
|
138
|
+
|
|
139
|
+
LITESTAR_INSTALLED = False # pyright: ignore[reportConstantRedefinition]
|
|
140
|
+
|
|
113
141
|
|
|
114
142
|
class EmptyEnum(Enum):
|
|
115
143
|
"""A sentinel enum used as placeholder."""
|
|
@@ -122,10 +150,12 @@ Empty: Final = EmptyEnum.EMPTY
|
|
|
122
150
|
|
|
123
151
|
|
|
124
152
|
__all__ = (
|
|
153
|
+
"LITESTAR_INSTALLED",
|
|
125
154
|
"MSGSPEC_INSTALLED",
|
|
126
155
|
"PYDANTIC_INSTALLED",
|
|
127
156
|
"UNSET",
|
|
128
157
|
"BaseModel",
|
|
158
|
+
"DTOData",
|
|
129
159
|
"DataclassProtocol",
|
|
130
160
|
"Empty",
|
|
131
161
|
"EmptyEnum",
|
sqlspec/adapters/adbc/config.py
CHANGED
|
@@ -2,31 +2,31 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from contextlib import contextmanager
|
|
4
4
|
from dataclasses import dataclass
|
|
5
|
-
from typing import TYPE_CHECKING
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
6
|
|
|
7
|
-
from sqlspec.
|
|
7
|
+
from sqlspec.base import NoPoolSyncConfig
|
|
8
8
|
from sqlspec.typing import Empty, EmptyType
|
|
9
9
|
|
|
10
10
|
if TYPE_CHECKING:
|
|
11
11
|
from collections.abc import Generator
|
|
12
12
|
from typing import Any
|
|
13
13
|
|
|
14
|
-
from adbc_driver_manager.dbapi import Connection
|
|
14
|
+
from adbc_driver_manager.dbapi import Connection
|
|
15
15
|
|
|
16
16
|
__all__ = ("AdbcDatabaseConfig",)
|
|
17
17
|
|
|
18
|
-
ConnectionT = TypeVar("ConnectionT", bound="Connection")
|
|
19
|
-
CursorT = TypeVar("CursorT", bound="Cursor")
|
|
20
|
-
|
|
21
18
|
|
|
22
19
|
@dataclass
|
|
23
|
-
class AdbcDatabaseConfig(
|
|
20
|
+
class AdbcDatabaseConfig(NoPoolSyncConfig["Connection"]):
|
|
24
21
|
"""Configuration for ADBC connections.
|
|
25
22
|
|
|
26
23
|
This class provides configuration options for ADBC database connections using the
|
|
27
24
|
ADBC Driver Manager.([1](https://arrow.apache.org/adbc/current/python/api/adbc_driver_manager.html))
|
|
28
25
|
"""
|
|
29
26
|
|
|
27
|
+
__supports_connection_pooling = False
|
|
28
|
+
__is_async = False
|
|
29
|
+
|
|
30
30
|
uri: str | EmptyType = Empty
|
|
31
31
|
"""Database URI"""
|
|
32
32
|
driver_name: str | EmptyType = Empty
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from contextlib import asynccontextmanager
|
|
4
|
-
from dataclasses import dataclass
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
5
|
from typing import TYPE_CHECKING, Any
|
|
6
6
|
|
|
7
|
-
from sqlspec.
|
|
7
|
+
from sqlspec.base import NoPoolSyncConfig
|
|
8
8
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
9
9
|
from sqlspec.typing import Empty, EmptyType, dataclass_to_dict
|
|
10
10
|
|
|
@@ -19,7 +19,7 @@ __all__ = ("AiosqliteConfig",)
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
@dataclass
|
|
22
|
-
class AiosqliteConfig(
|
|
22
|
+
class AiosqliteConfig(NoPoolSyncConfig["Connection"]):
|
|
23
23
|
"""Configuration for Aiosqlite database connections.
|
|
24
24
|
|
|
25
25
|
This class provides configuration options for Aiosqlite database connections, wrapping all parameters
|
|
@@ -28,28 +28,21 @@ class AiosqliteConfig(GenericDatabaseConfig):
|
|
|
28
28
|
For details see: https://github.com/omnilib/aiosqlite/blob/main/aiosqlite/__init__.pyi
|
|
29
29
|
"""
|
|
30
30
|
|
|
31
|
-
database: str
|
|
31
|
+
database: str = field(default=":memory:")
|
|
32
32
|
"""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."""
|
|
33
|
-
|
|
34
|
-
timeout: float | EmptyType = Empty
|
|
33
|
+
timeout: float | EmptyType = field(default=Empty)
|
|
35
34
|
"""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."""
|
|
36
|
-
|
|
37
|
-
detect_types: int | EmptyType = Empty
|
|
35
|
+
detect_types: int | EmptyType = field(default=Empty)
|
|
38
36
|
"""Control whether and how data types are detected. It can be 0 (default) or a combination of PARSE_DECLTYPES and PARSE_COLNAMES."""
|
|
39
|
-
|
|
40
|
-
isolation_level: Literal["DEFERRED", "IMMEDIATE", "EXCLUSIVE"] | None | EmptyType = Empty
|
|
37
|
+
isolation_level: Literal["DEFERRED", "IMMEDIATE", "EXCLUSIVE"] | None | EmptyType = field(default=Empty)
|
|
41
38
|
"""The isolation_level of the connection. This can be None for autocommit mode or one of "DEFERRED", "IMMEDIATE" or "EXCLUSIVE"."""
|
|
42
|
-
|
|
43
|
-
check_same_thread: bool | EmptyType = Empty
|
|
39
|
+
check_same_thread: bool | EmptyType = field(default=Empty)
|
|
44
40
|
"""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."""
|
|
45
|
-
|
|
46
|
-
factory: type[SQLite3Connection] | EmptyType = Empty
|
|
41
|
+
factory: type[SQLite3Connection] | EmptyType = field(default=Empty)
|
|
47
42
|
"""A custom Connection class factory. If given, must be a callable that returns a Connection instance."""
|
|
48
|
-
|
|
49
|
-
cached_statements: int | EmptyType = Empty
|
|
43
|
+
cached_statements: int | EmptyType = field(default=Empty)
|
|
50
44
|
"""The number of statements that SQLite will cache for this connection. The default is 128."""
|
|
51
|
-
|
|
52
|
-
uri: bool | EmptyType = Empty
|
|
45
|
+
uri: bool | EmptyType = field(default=Empty)
|
|
53
46
|
"""If set to True, database is interpreted as a URI with supported options."""
|
|
54
47
|
|
|
55
48
|
@property
|
|
@@ -4,6 +4,10 @@ from contextlib import asynccontextmanager
|
|
|
4
4
|
from dataclasses import dataclass
|
|
5
5
|
from typing import TYPE_CHECKING, TypeVar
|
|
6
6
|
|
|
7
|
+
from asyncmy.connection import Connection
|
|
8
|
+
from asyncmy.pool import Pool
|
|
9
|
+
|
|
10
|
+
from sqlspec.base import AsyncDatabaseConfig, GenericPoolConfig
|
|
7
11
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
8
12
|
from sqlspec.typing import Empty, EmptyType, dataclass_to_dict
|
|
9
13
|
|
|
@@ -11,9 +15,7 @@ if TYPE_CHECKING:
|
|
|
11
15
|
from collections.abc import AsyncGenerator
|
|
12
16
|
from typing import Any
|
|
13
17
|
|
|
14
|
-
from asyncmy.connection import Connection
|
|
15
18
|
from asyncmy.cursors import Cursor, DictCursor
|
|
16
|
-
from asyncmy.pool import Pool
|
|
17
19
|
|
|
18
20
|
__all__ = (
|
|
19
21
|
"AsyncMyConfig",
|
|
@@ -25,7 +27,7 @@ T = TypeVar("T")
|
|
|
25
27
|
|
|
26
28
|
|
|
27
29
|
@dataclass
|
|
28
|
-
class AsyncmyPoolConfig:
|
|
30
|
+
class AsyncmyPoolConfig(GenericPoolConfig):
|
|
29
31
|
"""Configuration for Asyncmy's connection pool.
|
|
30
32
|
|
|
31
33
|
This class provides configuration options for Asyncmy database connection pools.
|
|
@@ -104,9 +106,12 @@ class AsyncmyPoolConfig:
|
|
|
104
106
|
|
|
105
107
|
|
|
106
108
|
@dataclass
|
|
107
|
-
class AsyncMyConfig:
|
|
109
|
+
class AsyncMyConfig(AsyncDatabaseConfig[Connection, Pool]):
|
|
108
110
|
"""Asyncmy Configuration."""
|
|
109
111
|
|
|
112
|
+
__is_async__ = True
|
|
113
|
+
__supports_connection_pooling__ = True
|
|
114
|
+
|
|
110
115
|
pool_config: AsyncmyPoolConfig | None = None
|
|
111
116
|
"""Asyncmy Pool configuration"""
|
|
112
117
|
|
|
@@ -2,23 +2,23 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from contextlib import asynccontextmanager
|
|
4
4
|
from dataclasses import dataclass
|
|
5
|
-
from typing import TYPE_CHECKING, TypeVar
|
|
5
|
+
from typing import TYPE_CHECKING, Any, TypeVar, Union
|
|
6
6
|
|
|
7
7
|
from asyncpg import Record
|
|
8
8
|
from asyncpg import create_pool as asyncpg_create_pool
|
|
9
|
+
from asyncpg.connection import Connection
|
|
10
|
+
from asyncpg.pool import Pool, PoolConnectionProxy
|
|
11
|
+
from typing_extensions import TypeAlias
|
|
9
12
|
|
|
10
13
|
from sqlspec._serialization import decode_json, encode_json
|
|
11
|
-
from sqlspec.
|
|
14
|
+
from sqlspec.base import AsyncDatabaseConfig, GenericPoolConfig
|
|
12
15
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
13
16
|
from sqlspec.typing import Empty, EmptyType, dataclass_to_dict
|
|
14
17
|
|
|
15
18
|
if TYPE_CHECKING:
|
|
16
|
-
from asyncio import AbstractEventLoop
|
|
19
|
+
from asyncio import AbstractEventLoop # pyright: ignore[reportAttributeAccessIssue]
|
|
17
20
|
from collections.abc import AsyncGenerator, Awaitable, Callable, Coroutine
|
|
18
|
-
from typing import Any
|
|
19
21
|
|
|
20
|
-
from asyncpg.connection import Connection
|
|
21
|
-
from asyncpg.pool import Pool, PoolConnectionProxy
|
|
22
22
|
|
|
23
23
|
__all__ = (
|
|
24
24
|
"AsyncPgConfig",
|
|
@@ -28,6 +28,8 @@ __all__ = (
|
|
|
28
28
|
|
|
29
29
|
T = TypeVar("T")
|
|
30
30
|
|
|
31
|
+
PgConnection: TypeAlias = Union[Connection, PoolConnectionProxy]
|
|
32
|
+
|
|
31
33
|
|
|
32
34
|
@dataclass
|
|
33
35
|
class AsyncPgPoolConfig(GenericPoolConfig):
|
|
@@ -70,7 +72,7 @@ class AsyncPgPoolConfig(GenericPoolConfig):
|
|
|
70
72
|
|
|
71
73
|
|
|
72
74
|
@dataclass
|
|
73
|
-
class AsyncPgConfig(
|
|
75
|
+
class AsyncPgConfig(AsyncDatabaseConfig[PgConnection, Pool]):
|
|
74
76
|
"""Asyncpg Configuration."""
|
|
75
77
|
|
|
76
78
|
pool_config: AsyncPgPoolConfig | None = None
|
|
@@ -132,9 +134,7 @@ class AsyncPgConfig(GenericDatabaseConfig):
|
|
|
132
134
|
return self.create_pool()
|
|
133
135
|
|
|
134
136
|
@asynccontextmanager
|
|
135
|
-
async def provide_connection(
|
|
136
|
-
self, *args: Any, **kwargs: Any
|
|
137
|
-
) -> AsyncGenerator[Connection | PoolConnectionProxy, None]:
|
|
137
|
+
async def provide_connection(self, *args: Any, **kwargs: Any) -> AsyncGenerator[PoolConnectionProxy, None]:
|
|
138
138
|
"""Create a connection instance.
|
|
139
139
|
|
|
140
140
|
Returns:
|
|
@@ -4,14 +4,15 @@ from contextlib import contextmanager
|
|
|
4
4
|
from dataclasses import dataclass
|
|
5
5
|
from typing import TYPE_CHECKING, Any, cast
|
|
6
6
|
|
|
7
|
-
from
|
|
7
|
+
from duckdb import DuckDBPyConnection
|
|
8
|
+
|
|
9
|
+
from sqlspec.base import NoPoolSyncConfig
|
|
8
10
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
9
11
|
from sqlspec.typing import Empty, EmptyType, dataclass_to_dict
|
|
10
12
|
|
|
11
13
|
if TYPE_CHECKING:
|
|
12
14
|
from collections.abc import Generator, Sequence
|
|
13
15
|
|
|
14
|
-
from duckdb import DuckDBPyConnection
|
|
15
16
|
|
|
16
17
|
__all__ = ("DuckDBConfig", "ExtensionConfig")
|
|
17
18
|
|
|
@@ -23,21 +24,21 @@ class ExtensionConfig:
|
|
|
23
24
|
This class provides configuration options for DuckDB extensions, including installation
|
|
24
25
|
and post-install configuration settings.
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
name: The name of the extension to install
|
|
28
|
-
config: Optional configuration settings to apply after installation
|
|
29
|
-
force_install: Whether to force reinstall if already present
|
|
30
|
-
repository: Optional repository name to install from
|
|
31
|
-
repository_url: Optional repository URL to install from
|
|
32
|
-
version: Optional version of the extension to install
|
|
27
|
+
For details see: https://duckdb.org/docs/extensions/overview
|
|
33
28
|
"""
|
|
34
29
|
|
|
35
30
|
name: str
|
|
31
|
+
"""The name of the extension to install"""
|
|
36
32
|
config: dict[str, Any] | None = None
|
|
33
|
+
"""Optional configuration settings to apply after installation"""
|
|
37
34
|
force_install: bool = False
|
|
35
|
+
"""Whether to force reinstall if already present"""
|
|
38
36
|
repository: str | None = None
|
|
37
|
+
"""Optional repository name to install from"""
|
|
39
38
|
repository_url: str | None = None
|
|
39
|
+
"""Optional repository URL to install from"""
|
|
40
40
|
version: str | None = None
|
|
41
|
+
"""Optional version of the extension to install"""
|
|
41
42
|
|
|
42
43
|
@classmethod
|
|
43
44
|
def from_dict(cls, name: str, config: dict[str, Any] | bool | None = None) -> ExtensionConfig:
|
|
@@ -65,7 +66,7 @@ class ExtensionConfig:
|
|
|
65
66
|
|
|
66
67
|
|
|
67
68
|
@dataclass
|
|
68
|
-
class DuckDBConfig(
|
|
69
|
+
class DuckDBConfig(NoPoolSyncConfig[DuckDBPyConnection]):
|
|
69
70
|
"""Configuration for DuckDB database connections.
|
|
70
71
|
|
|
71
72
|
This class provides configuration options for DuckDB database connections, wrapping all parameters
|
|
@@ -114,13 +115,13 @@ class DuckDBConfig(GenericDatabaseConfig):
|
|
|
114
115
|
msg = "When configuring extensions in the 'config' dictionary, the value must be a dictionary or sequence of extension names"
|
|
115
116
|
raise ImproperConfigurationError(msg)
|
|
116
117
|
if not isinstance(_e, dict):
|
|
117
|
-
_e = {str(ext): {"force_install": False} for ext in _e}
|
|
118
|
+
_e = {str(ext): {"force_install": False} for ext in _e} # pyright: ignore[reportUnknownVariableType,reportUnknownArgumentType]
|
|
118
119
|
|
|
119
|
-
if len(set(_e.keys()).intersection({ext.name for ext in self.extensions})) > 0:
|
|
120
|
+
if len(set(_e.keys()).intersection({ext.name for ext in self.extensions})) > 0: # pyright: ignore[ reportUnknownArgumentType]
|
|
120
121
|
msg = "Configuring the same extension in both 'extensions' and as a key in 'config['extensions']' is not allowed"
|
|
121
122
|
raise ImproperConfigurationError(msg)
|
|
122
123
|
|
|
123
|
-
self.extensions.extend([ExtensionConfig.from_dict(name, ext_config) for name, ext_config in _e.items()])
|
|
124
|
+
self.extensions.extend([ExtensionConfig.from_dict(name, ext_config) for name, ext_config in _e.items()]) # pyright: ignore[reportUnknownArgumentType,reportUnknownVariableType]
|
|
124
125
|
|
|
125
126
|
def _configure_extensions(self, connection: DuckDBPyConnection) -> None:
|
|
126
127
|
"""Configure extensions for the connection.
|
|
@@ -177,7 +178,7 @@ class DuckDBConfig(GenericDatabaseConfig):
|
|
|
177
178
|
import duckdb
|
|
178
179
|
|
|
179
180
|
try:
|
|
180
|
-
connection = duckdb.connect(**self.connection_config_dict)
|
|
181
|
+
connection = duckdb.connect(**self.connection_config_dict) # pyright: ignore[reportUnknownMemberType]
|
|
181
182
|
self._configure_extensions(connection)
|
|
182
183
|
return connection
|
|
183
184
|
except Exception as e:
|
|
@@ -4,14 +4,14 @@ from contextlib import asynccontextmanager
|
|
|
4
4
|
from dataclasses import dataclass
|
|
5
5
|
from typing import TYPE_CHECKING
|
|
6
6
|
|
|
7
|
-
from oracledb import create_pool_async as oracledb_create_pool
|
|
7
|
+
from oracledb import create_pool_async as oracledb_create_pool # pyright: ignore[reportUnknownVariableType]
|
|
8
8
|
from oracledb.connection import AsyncConnection
|
|
9
9
|
from oracledb.pool import AsyncConnectionPool
|
|
10
10
|
|
|
11
11
|
from sqlspec.adapters.oracledb.config._common import (
|
|
12
|
-
OracleGenericDatabaseConfig,
|
|
13
12
|
OracleGenericPoolConfig,
|
|
14
13
|
)
|
|
14
|
+
from sqlspec.base import AsyncDatabaseConfig
|
|
15
15
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
16
16
|
from sqlspec.typing import dataclass_to_dict
|
|
17
17
|
|
|
@@ -26,13 +26,23 @@ __all__ = (
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
@dataclass
|
|
29
|
-
class OracleAsyncPoolConfig(OracleGenericPoolConfig[
|
|
29
|
+
class OracleAsyncPoolConfig(OracleGenericPoolConfig[AsyncConnection, AsyncConnectionPool]):
|
|
30
30
|
"""Async Oracle Pool Config"""
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
@dataclass
|
|
34
|
-
class OracleAsyncDatabaseConfig(
|
|
35
|
-
"""Async
|
|
34
|
+
class OracleAsyncDatabaseConfig(AsyncDatabaseConfig[AsyncConnection, AsyncConnectionPool]):
|
|
35
|
+
"""Oracle Async database Configuration.
|
|
36
|
+
|
|
37
|
+
This class provides the base configuration for Oracle database connections, extending
|
|
38
|
+
the generic database configuration with Oracle-specific settings. It supports both
|
|
39
|
+
thin and thick modes of the python-oracledb driver.([1](https://python-oracledb.readthedocs.io/en/latest/index.html))
|
|
40
|
+
|
|
41
|
+
The configuration supports all standard Oracle connection parameters and can be used
|
|
42
|
+
with both synchronous and asynchronous connections. It includes support for features
|
|
43
|
+
like Oracle Wallet, external authentication, connection pooling, and advanced security
|
|
44
|
+
options.([2](https://python-oracledb.readthedocs.io/en/latest/user_guide/tuning.html))
|
|
45
|
+
"""
|
|
36
46
|
|
|
37
47
|
pool_config: OracleAsyncPoolConfig | None = None
|
|
38
48
|
"""Oracle Pool configuration"""
|
|
@@ -70,7 +80,7 @@ class OracleAsyncDatabaseConfig(OracleGenericDatabaseConfig[AsyncConnectionPool,
|
|
|
70
80
|
|
|
71
81
|
pool_config = self.pool_config_dict
|
|
72
82
|
self.pool_instance = oracledb_create_pool(**pool_config)
|
|
73
|
-
if self.pool_instance is None:
|
|
83
|
+
if self.pool_instance is None: # pyright: ignore[reportUnnecessaryComparison]
|
|
74
84
|
msg = "Could not configure the 'pool_instance'. Please check your configuration."
|
|
75
85
|
raise ImproperConfigurationError(msg)
|
|
76
86
|
return self.pool_instance
|
|
@@ -91,5 +101,5 @@ class OracleAsyncDatabaseConfig(OracleGenericDatabaseConfig[AsyncConnectionPool,
|
|
|
91
101
|
A connection instance.
|
|
92
102
|
"""
|
|
93
103
|
db_pool = await self.provide_pool(*args, **kwargs)
|
|
94
|
-
async with db_pool.acquire() as connection:
|
|
104
|
+
async with db_pool.acquire() as connection: # pyright: ignore[reportUnknownMemberType]
|
|
95
105
|
yield connection
|
|
@@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Generic, TypeVar
|
|
|
5
5
|
|
|
6
6
|
from oracledb import ConnectionPool
|
|
7
7
|
|
|
8
|
-
from sqlspec.
|
|
8
|
+
from sqlspec.base import GenericPoolConfig
|
|
9
9
|
from sqlspec.typing import Empty
|
|
10
10
|
|
|
11
11
|
if TYPE_CHECKING:
|
|
@@ -19,10 +19,7 @@ if TYPE_CHECKING:
|
|
|
19
19
|
|
|
20
20
|
from sqlspec.typing import EmptyType
|
|
21
21
|
|
|
22
|
-
__all__ = (
|
|
23
|
-
"OracleGenericDatabaseConfig",
|
|
24
|
-
"OracleGenericPoolConfig",
|
|
25
|
-
)
|
|
22
|
+
__all__ = ("OracleGenericPoolConfig",)
|
|
26
23
|
|
|
27
24
|
|
|
28
25
|
T = TypeVar("T")
|
|
@@ -32,7 +29,7 @@ PoolT = TypeVar("PoolT", bound="ConnectionPool | AsyncConnectionPool")
|
|
|
32
29
|
|
|
33
30
|
|
|
34
31
|
@dataclass
|
|
35
|
-
class OracleGenericPoolConfig(Generic[
|
|
32
|
+
class OracleGenericPoolConfig(Generic[ConnectionT, PoolT], GenericPoolConfig):
|
|
36
33
|
"""Configuration for Oracle database connection pools.
|
|
37
34
|
|
|
38
35
|
This class provides configuration options for both synchronous and asynchronous Oracle
|
|
@@ -58,7 +55,7 @@ class OracleGenericPoolConfig(Generic[PoolT, ConnectionT], GenericPoolConfig):
|
|
|
58
55
|
"""New password for password change operations"""
|
|
59
56
|
wallet_password: str | EmptyType = Empty
|
|
60
57
|
"""Password for accessing Oracle Wallet"""
|
|
61
|
-
access_token: str | tuple | Callable | EmptyType = Empty
|
|
58
|
+
access_token: str | tuple[str, ...] | Callable[[], str] | EmptyType = Empty
|
|
62
59
|
"""Token for token-based authentication"""
|
|
63
60
|
host: str | EmptyType = Empty
|
|
64
61
|
"""Database server hostname"""
|
|
@@ -112,11 +109,11 @@ class OracleGenericPoolConfig(Generic[PoolT, ConnectionT], GenericPoolConfig):
|
|
|
112
109
|
"""If True, allows connections with different tags"""
|
|
113
110
|
config_dir: str | EmptyType = Empty
|
|
114
111
|
"""Directory containing Oracle configuration files"""
|
|
115
|
-
appcontext: list | EmptyType = Empty
|
|
112
|
+
appcontext: list[str] | EmptyType = Empty
|
|
116
113
|
"""Application context list"""
|
|
117
|
-
shardingkey: list | EmptyType = Empty
|
|
114
|
+
shardingkey: list[str] | EmptyType = Empty
|
|
118
115
|
"""Sharding key list"""
|
|
119
|
-
supershardingkey: list | EmptyType = Empty
|
|
116
|
+
supershardingkey: list[str] | EmptyType = Empty
|
|
120
117
|
"""Super sharding key list"""
|
|
121
118
|
debug_jdwp: str | EmptyType = Empty
|
|
122
119
|
"""JDWP debugging string"""
|
|
@@ -134,18 +131,3 @@ class OracleGenericPoolConfig(Generic[PoolT, ConnectionT], GenericPoolConfig):
|
|
|
134
131
|
"""SSL/TLS protocol version"""
|
|
135
132
|
handle: int | EmptyType = Empty
|
|
136
133
|
"""Oracle service context handle"""
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
@dataclass
|
|
140
|
-
class OracleGenericDatabaseConfig(Generic[PoolT, ConnectionT], 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
|
-
"""
|
|
@@ -4,14 +4,14 @@ from contextlib import contextmanager
|
|
|
4
4
|
from dataclasses import dataclass
|
|
5
5
|
from typing import TYPE_CHECKING
|
|
6
6
|
|
|
7
|
-
from oracledb import create_pool as oracledb_create_pool
|
|
7
|
+
from oracledb import create_pool as oracledb_create_pool # pyright: ignore[reportUnknownVariableType]
|
|
8
8
|
from oracledb.connection import Connection
|
|
9
9
|
from oracledb.pool import ConnectionPool
|
|
10
10
|
|
|
11
11
|
from sqlspec.adapters.oracledb.config._common import (
|
|
12
|
-
OracleGenericDatabaseConfig,
|
|
13
12
|
OracleGenericPoolConfig,
|
|
14
13
|
)
|
|
14
|
+
from sqlspec.base import SyncDatabaseConfig
|
|
15
15
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
16
16
|
from sqlspec.typing import dataclass_to_dict
|
|
17
17
|
|
|
@@ -26,13 +26,23 @@ __all__ = (
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
@dataclass
|
|
29
|
-
class OracleSyncPoolConfig(OracleGenericPoolConfig[
|
|
29
|
+
class OracleSyncPoolConfig(OracleGenericPoolConfig[Connection, ConnectionPool]):
|
|
30
30
|
"""Sync Oracle Pool Config"""
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
@dataclass
|
|
34
|
-
class OracleSyncDatabaseConfig(
|
|
35
|
-
"""Oracle database Configuration.
|
|
34
|
+
class OracleSyncDatabaseConfig(SyncDatabaseConfig[Connection, ConnectionPool]):
|
|
35
|
+
"""Oracle Sync database Configuration.
|
|
36
|
+
|
|
37
|
+
This class provides the base configuration for Oracle database connections, extending
|
|
38
|
+
the generic database configuration with Oracle-specific settings. It supports both
|
|
39
|
+
thin and thick modes of the python-oracledb driver.([1](https://python-oracledb.readthedocs.io/en/latest/index.html))
|
|
40
|
+
|
|
41
|
+
The configuration supports all standard Oracle connection parameters and can be used
|
|
42
|
+
with both synchronous and asynchronous connections. It includes support for features
|
|
43
|
+
like Oracle Wallet, external authentication, connection pooling, and advanced security
|
|
44
|
+
options.([2](https://python-oracledb.readthedocs.io/en/latest/user_guide/tuning.html))
|
|
45
|
+
"""
|
|
36
46
|
|
|
37
47
|
pool_config: OracleSyncPoolConfig | None = None
|
|
38
48
|
"""Oracle Pool configuration"""
|
|
@@ -70,7 +80,7 @@ class OracleSyncDatabaseConfig(OracleGenericDatabaseConfig[ConnectionPool, Conne
|
|
|
70
80
|
|
|
71
81
|
pool_config = self.pool_config_dict
|
|
72
82
|
self.pool_instance = oracledb_create_pool(**pool_config)
|
|
73
|
-
if self.pool_instance is None:
|
|
83
|
+
if self.pool_instance is None: # pyright: ignore[reportUnnecessaryComparison]
|
|
74
84
|
msg = "Could not configure the 'pool_instance'. Please check your configuration."
|
|
75
85
|
raise ImproperConfigurationError(msg)
|
|
76
86
|
return self.pool_instance
|
|
@@ -91,5 +101,5 @@ class OracleSyncDatabaseConfig(OracleGenericDatabaseConfig[ConnectionPool, Conne
|
|
|
91
101
|
A connection instance.
|
|
92
102
|
"""
|
|
93
103
|
db_pool = self.provide_pool(*args, **kwargs)
|
|
94
|
-
with db_pool.acquire() as connection:
|
|
104
|
+
with db_pool.acquire() as connection: # pyright: ignore[reportUnknownMemberType]
|
|
95
105
|
yield connection
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
from ._async import PsycoPgAsyncDatabaseConfig, PsycoPgAsyncPoolConfig
|
|
2
|
-
from ._sync import PsycoPgSyncDatabaseConfig, PsycoPgSyncPoolConfig
|
|
1
|
+
from sqlspec.adapters.psycopg.config._async import PsycoPgAsyncDatabaseConfig, PsycoPgAsyncPoolConfig
|
|
2
|
+
from sqlspec.adapters.psycopg.config._sync import PsycoPgSyncDatabaseConfig, PsycoPgSyncPoolConfig
|
|
3
3
|
|
|
4
4
|
__all__ = (
|
|
5
5
|
"PsycoPgAsyncDatabaseConfig",
|
|
@@ -7,10 +7,8 @@ from typing import TYPE_CHECKING
|
|
|
7
7
|
from psycopg import AsyncConnection
|
|
8
8
|
from psycopg_pool import AsyncConnectionPool
|
|
9
9
|
|
|
10
|
-
from sqlspec.adapters.psycopg.config._common import
|
|
11
|
-
|
|
12
|
-
PsycoPgGenericPoolConfig,
|
|
13
|
-
)
|
|
10
|
+
from sqlspec.adapters.psycopg.config._common import PsycoPgGenericPoolConfig
|
|
11
|
+
from sqlspec.base import AsyncDatabaseConfig
|
|
14
12
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
15
13
|
from sqlspec.typing import dataclass_to_dict
|
|
16
14
|
|
|
@@ -26,13 +24,20 @@ __all__ = (
|
|
|
26
24
|
|
|
27
25
|
|
|
28
26
|
@dataclass
|
|
29
|
-
class PsycoPgAsyncPoolConfig(PsycoPgGenericPoolConfig[
|
|
27
|
+
class PsycoPgAsyncPoolConfig(PsycoPgGenericPoolConfig[AsyncConnection, AsyncConnectionPool]):
|
|
30
28
|
"""Async Psycopg Pool Config"""
|
|
31
29
|
|
|
32
30
|
|
|
33
31
|
@dataclass
|
|
34
|
-
class PsycoPgAsyncDatabaseConfig(
|
|
35
|
-
"""Async Psycopg database Configuration.
|
|
32
|
+
class PsycoPgAsyncDatabaseConfig(AsyncDatabaseConfig[AsyncConnection, AsyncConnectionPool]):
|
|
33
|
+
"""Async Psycopg database Configuration.
|
|
34
|
+
|
|
35
|
+
This class provides the base configuration for Psycopg database connections, extending
|
|
36
|
+
the generic database configuration with Psycopg-specific settings.([1](https://www.psycopg.org/psycopg3/docs/api/connections.html))
|
|
37
|
+
|
|
38
|
+
The configuration supports all standard Psycopg connection parameters and can be used
|
|
39
|
+
with both synchronous and asynchronous connections.([2](https://www.psycopg.org/psycopg3/docs/api/connections.html))
|
|
40
|
+
"""
|
|
36
41
|
|
|
37
42
|
pool_config: PsycoPgAsyncPoolConfig | None = None
|
|
38
43
|
"""Psycopg Pool configuration"""
|
|
@@ -58,7 +63,7 @@ class PsycoPgAsyncDatabaseConfig(PsycoPgGenericDatabaseConfig[AsyncConnectionPoo
|
|
|
58
63
|
|
|
59
64
|
pool_config = self.pool_config_dict
|
|
60
65
|
self.pool_instance = AsyncConnectionPool(**pool_config)
|
|
61
|
-
if self.pool_instance is None:
|
|
66
|
+
if self.pool_instance is None: # pyright: ignore[reportUnnecessaryComparison]
|
|
62
67
|
msg = "Could not configure the 'pool_instance'. Please check your configuration." # type: ignore[unreachable]
|
|
63
68
|
raise ImproperConfigurationError(msg)
|
|
64
69
|
return self.pool_instance
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from dataclasses import dataclass
|
|
4
4
|
from typing import TYPE_CHECKING, Generic, TypeVar
|
|
5
5
|
|
|
6
|
-
from sqlspec.
|
|
6
|
+
from sqlspec.base import GenericPoolConfig
|
|
7
7
|
from sqlspec.typing import Empty
|
|
8
8
|
|
|
9
9
|
if TYPE_CHECKING:
|
|
@@ -16,10 +16,7 @@ if TYPE_CHECKING:
|
|
|
16
16
|
from sqlspec.typing import EmptyType
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
__all__ = (
|
|
20
|
-
"PsycoPgGenericDatabaseConfig",
|
|
21
|
-
"PsycoPgGenericPoolConfig",
|
|
22
|
-
)
|
|
19
|
+
__all__ = ("PsycoPgGenericPoolConfig",)
|
|
23
20
|
|
|
24
21
|
|
|
25
22
|
ConnectionT = TypeVar("ConnectionT", bound="Connection | AsyncConnection")
|
|
@@ -27,7 +24,7 @@ PoolT = TypeVar("PoolT", bound="ConnectionPool | AsyncConnectionPool")
|
|
|
27
24
|
|
|
28
25
|
|
|
29
26
|
@dataclass
|
|
30
|
-
class PsycoPgGenericPoolConfig(Generic[
|
|
27
|
+
class PsycoPgGenericPoolConfig(Generic[ConnectionT, PoolT], GenericPoolConfig):
|
|
31
28
|
"""Configuration for Psycopg connection pools.
|
|
32
29
|
|
|
33
30
|
This class provides configuration options for both synchronous and asynchronous Psycopg
|
|
@@ -59,15 +56,3 @@ class PsycoPgGenericPoolConfig(Generic[PoolT, ConnectionT], GenericPoolConfig):
|
|
|
59
56
|
"""Number of background workers"""
|
|
60
57
|
configure: Callable[[ConnectionT], None] | EmptyType = Empty
|
|
61
58
|
"""Callback to configure new connections"""
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
@dataclass
|
|
65
|
-
class PsycoPgGenericDatabaseConfig(Generic[PoolT, ConnectionT], 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
|
-
"""
|