sqlspec 0.14.1__py3-none-any.whl → 0.16.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sqlspec might be problematic. Click here for more details.
- sqlspec/__init__.py +50 -25
- sqlspec/__main__.py +1 -1
- sqlspec/__metadata__.py +1 -3
- sqlspec/_serialization.py +1 -2
- sqlspec/_sql.py +480 -121
- sqlspec/_typing.py +278 -142
- sqlspec/adapters/adbc/__init__.py +4 -3
- sqlspec/adapters/adbc/_types.py +12 -0
- sqlspec/adapters/adbc/config.py +115 -260
- sqlspec/adapters/adbc/driver.py +462 -367
- sqlspec/adapters/aiosqlite/__init__.py +18 -3
- sqlspec/adapters/aiosqlite/_types.py +13 -0
- sqlspec/adapters/aiosqlite/config.py +199 -129
- sqlspec/adapters/aiosqlite/driver.py +230 -269
- sqlspec/adapters/asyncmy/__init__.py +18 -3
- sqlspec/adapters/asyncmy/_types.py +12 -0
- sqlspec/adapters/asyncmy/config.py +80 -168
- sqlspec/adapters/asyncmy/driver.py +260 -225
- sqlspec/adapters/asyncpg/__init__.py +19 -4
- sqlspec/adapters/asyncpg/_types.py +17 -0
- sqlspec/adapters/asyncpg/config.py +82 -181
- sqlspec/adapters/asyncpg/driver.py +285 -383
- sqlspec/adapters/bigquery/__init__.py +17 -3
- sqlspec/adapters/bigquery/_types.py +12 -0
- sqlspec/adapters/bigquery/config.py +191 -258
- sqlspec/adapters/bigquery/driver.py +474 -646
- sqlspec/adapters/duckdb/__init__.py +14 -3
- sqlspec/adapters/duckdb/_types.py +12 -0
- sqlspec/adapters/duckdb/config.py +415 -351
- sqlspec/adapters/duckdb/driver.py +343 -413
- sqlspec/adapters/oracledb/__init__.py +19 -5
- sqlspec/adapters/oracledb/_types.py +14 -0
- sqlspec/adapters/oracledb/config.py +123 -379
- sqlspec/adapters/oracledb/driver.py +507 -560
- sqlspec/adapters/psqlpy/__init__.py +13 -3
- sqlspec/adapters/psqlpy/_types.py +11 -0
- sqlspec/adapters/psqlpy/config.py +93 -254
- sqlspec/adapters/psqlpy/driver.py +505 -234
- sqlspec/adapters/psycopg/__init__.py +19 -5
- sqlspec/adapters/psycopg/_types.py +17 -0
- sqlspec/adapters/psycopg/config.py +143 -403
- sqlspec/adapters/psycopg/driver.py +706 -872
- sqlspec/adapters/sqlite/__init__.py +14 -3
- sqlspec/adapters/sqlite/_types.py +11 -0
- sqlspec/adapters/sqlite/config.py +202 -118
- sqlspec/adapters/sqlite/driver.py +264 -303
- sqlspec/base.py +105 -9
- sqlspec/{statement/builder → builder}/__init__.py +12 -14
- sqlspec/{statement/builder → builder}/_base.py +120 -55
- sqlspec/{statement/builder → builder}/_column.py +17 -6
- sqlspec/{statement/builder → builder}/_ddl.py +46 -79
- sqlspec/{statement/builder → builder}/_ddl_utils.py +5 -10
- sqlspec/{statement/builder → builder}/_delete.py +6 -25
- sqlspec/{statement/builder → builder}/_insert.py +18 -65
- sqlspec/builder/_merge.py +56 -0
- sqlspec/{statement/builder → builder}/_parsing_utils.py +8 -11
- sqlspec/{statement/builder → builder}/_select.py +11 -56
- sqlspec/{statement/builder → builder}/_update.py +12 -18
- sqlspec/{statement/builder → builder}/mixins/__init__.py +10 -14
- sqlspec/{statement/builder → builder}/mixins/_cte_and_set_ops.py +48 -59
- sqlspec/{statement/builder → builder}/mixins/_insert_operations.py +34 -18
- sqlspec/{statement/builder → builder}/mixins/_join_operations.py +1 -3
- sqlspec/{statement/builder → builder}/mixins/_merge_operations.py +19 -9
- sqlspec/{statement/builder → builder}/mixins/_order_limit_operations.py +3 -3
- sqlspec/{statement/builder → builder}/mixins/_pivot_operations.py +4 -8
- sqlspec/{statement/builder → builder}/mixins/_select_operations.py +25 -38
- sqlspec/{statement/builder → builder}/mixins/_update_operations.py +15 -16
- sqlspec/{statement/builder → builder}/mixins/_where_clause.py +210 -137
- sqlspec/cli.py +4 -5
- sqlspec/config.py +180 -133
- sqlspec/core/__init__.py +63 -0
- sqlspec/core/cache.py +873 -0
- sqlspec/core/compiler.py +396 -0
- sqlspec/core/filters.py +830 -0
- sqlspec/core/hashing.py +310 -0
- sqlspec/core/parameters.py +1209 -0
- sqlspec/core/result.py +664 -0
- sqlspec/{statement → core}/splitter.py +321 -191
- sqlspec/core/statement.py +666 -0
- sqlspec/driver/__init__.py +7 -10
- sqlspec/driver/_async.py +387 -176
- sqlspec/driver/_common.py +527 -289
- sqlspec/driver/_sync.py +390 -172
- sqlspec/driver/mixins/__init__.py +2 -19
- sqlspec/driver/mixins/_result_tools.py +164 -0
- sqlspec/driver/mixins/_sql_translator.py +6 -3
- sqlspec/exceptions.py +5 -252
- sqlspec/extensions/aiosql/adapter.py +93 -96
- sqlspec/extensions/litestar/cli.py +1 -1
- sqlspec/extensions/litestar/config.py +0 -1
- sqlspec/extensions/litestar/handlers.py +15 -26
- sqlspec/extensions/litestar/plugin.py +18 -16
- sqlspec/extensions/litestar/providers.py +17 -52
- sqlspec/loader.py +424 -105
- sqlspec/migrations/__init__.py +12 -0
- sqlspec/migrations/base.py +92 -68
- sqlspec/migrations/commands.py +24 -106
- sqlspec/migrations/loaders.py +402 -0
- sqlspec/migrations/runner.py +49 -51
- sqlspec/migrations/tracker.py +31 -44
- sqlspec/migrations/utils.py +64 -24
- sqlspec/protocols.py +7 -183
- sqlspec/storage/__init__.py +1 -1
- sqlspec/storage/backends/base.py +37 -40
- sqlspec/storage/backends/fsspec.py +136 -112
- sqlspec/storage/backends/obstore.py +138 -160
- sqlspec/storage/capabilities.py +5 -4
- sqlspec/storage/registry.py +57 -106
- sqlspec/typing.py +136 -115
- sqlspec/utils/__init__.py +2 -3
- sqlspec/utils/correlation.py +0 -3
- sqlspec/utils/deprecation.py +6 -6
- sqlspec/utils/fixtures.py +6 -6
- sqlspec/utils/logging.py +0 -2
- sqlspec/utils/module_loader.py +7 -12
- sqlspec/utils/singleton.py +0 -1
- sqlspec/utils/sync_tools.py +17 -38
- sqlspec/utils/text.py +12 -51
- sqlspec/utils/type_guards.py +443 -232
- {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/METADATA +7 -2
- sqlspec-0.16.0.dist-info/RECORD +134 -0
- sqlspec/adapters/adbc/transformers.py +0 -108
- sqlspec/driver/connection.py +0 -207
- sqlspec/driver/mixins/_cache.py +0 -114
- sqlspec/driver/mixins/_csv_writer.py +0 -91
- sqlspec/driver/mixins/_pipeline.py +0 -508
- sqlspec/driver/mixins/_query_tools.py +0 -796
- sqlspec/driver/mixins/_result_utils.py +0 -138
- sqlspec/driver/mixins/_storage.py +0 -912
- sqlspec/driver/mixins/_type_coercion.py +0 -128
- sqlspec/driver/parameters.py +0 -138
- sqlspec/statement/__init__.py +0 -21
- sqlspec/statement/builder/_merge.py +0 -95
- sqlspec/statement/cache.py +0 -50
- sqlspec/statement/filters.py +0 -625
- sqlspec/statement/parameters.py +0 -956
- sqlspec/statement/pipelines/__init__.py +0 -210
- sqlspec/statement/pipelines/analyzers/__init__.py +0 -9
- sqlspec/statement/pipelines/analyzers/_analyzer.py +0 -646
- sqlspec/statement/pipelines/context.py +0 -109
- sqlspec/statement/pipelines/transformers/__init__.py +0 -7
- sqlspec/statement/pipelines/transformers/_expression_simplifier.py +0 -88
- sqlspec/statement/pipelines/transformers/_literal_parameterizer.py +0 -1247
- sqlspec/statement/pipelines/transformers/_remove_comments_and_hints.py +0 -76
- sqlspec/statement/pipelines/validators/__init__.py +0 -23
- sqlspec/statement/pipelines/validators/_dml_safety.py +0 -290
- sqlspec/statement/pipelines/validators/_parameter_style.py +0 -370
- sqlspec/statement/pipelines/validators/_performance.py +0 -714
- sqlspec/statement/pipelines/validators/_security.py +0 -967
- sqlspec/statement/result.py +0 -435
- sqlspec/statement/sql.py +0 -1774
- sqlspec/utils/cached_property.py +0 -25
- sqlspec/utils/statement_hashing.py +0 -203
- sqlspec-0.14.1.dist-info/RECORD +0 -145
- /sqlspec/{statement/builder → builder}/mixins/_delete_operations.py +0 -0
- {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/WHEEL +0 -0
- {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/entry_points.txt +0 -0
- {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/licenses/LICENSE +0 -0
- {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/licenses/NOTICE +0 -0
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
"""Psqlpy adapter for SQLSpec."""
|
|
2
2
|
|
|
3
|
-
from sqlspec.adapters.psqlpy.
|
|
4
|
-
from sqlspec.adapters.psqlpy.
|
|
3
|
+
from sqlspec.adapters.psqlpy._types import PsqlpyConnection
|
|
4
|
+
from sqlspec.adapters.psqlpy.config import PsqlpyConfig, PsqlpyConnectionParams, PsqlpyPoolParams
|
|
5
|
+
from sqlspec.adapters.psqlpy.driver import PsqlpyCursor, PsqlpyDriver, PsqlpyExceptionHandler, psqlpy_statement_config
|
|
5
6
|
|
|
6
|
-
__all__ = (
|
|
7
|
+
__all__ = (
|
|
8
|
+
"PsqlpyConfig",
|
|
9
|
+
"PsqlpyConnection",
|
|
10
|
+
"PsqlpyConnectionParams",
|
|
11
|
+
"PsqlpyCursor",
|
|
12
|
+
"PsqlpyDriver",
|
|
13
|
+
"PsqlpyExceptionHandler",
|
|
14
|
+
"PsqlpyPoolParams",
|
|
15
|
+
"psqlpy_statement_config",
|
|
16
|
+
)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING
|
|
2
|
+
|
|
3
|
+
if TYPE_CHECKING:
|
|
4
|
+
from psqlpy import Connection
|
|
5
|
+
from typing_extensions import TypeAlias
|
|
6
|
+
|
|
7
|
+
PsqlpyConnection: TypeAlias = Connection
|
|
8
|
+
else:
|
|
9
|
+
from psqlpy import Connection as PsqlpyConnection
|
|
10
|
+
|
|
11
|
+
__all__ = ("PsqlpyConnection",)
|
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
import logging
|
|
4
4
|
from collections.abc import AsyncGenerator
|
|
5
5
|
from contextlib import asynccontextmanager
|
|
6
|
-
from typing import TYPE_CHECKING, Any, ClassVar, Optional
|
|
6
|
+
from typing import TYPE_CHECKING, Any, ClassVar, Optional, TypedDict, Union
|
|
7
7
|
|
|
8
8
|
from psqlpy import ConnectionPool
|
|
9
|
+
from typing_extensions import NotRequired
|
|
9
10
|
|
|
10
|
-
from sqlspec.adapters.psqlpy.
|
|
11
|
+
from sqlspec.adapters.psqlpy._types import PsqlpyConnection
|
|
12
|
+
from sqlspec.adapters.psqlpy.driver import PsqlpyCursor, PsqlpyDriver, psqlpy_statement_config
|
|
11
13
|
from sqlspec.config import AsyncDatabaseConfig
|
|
12
|
-
from sqlspec.statement
|
|
13
|
-
from sqlspec.typing import DictRow, Empty
|
|
14
|
+
from sqlspec.core.statement import StatementConfig
|
|
14
15
|
|
|
15
16
|
if TYPE_CHECKING:
|
|
16
17
|
from collections.abc import Callable
|
|
@@ -18,266 +19,112 @@ if TYPE_CHECKING:
|
|
|
18
19
|
|
|
19
20
|
logger = logging.getLogger("sqlspec.adapters.psqlpy")
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
22
|
+
|
|
23
|
+
class PsqlpyConnectionParams(TypedDict, total=False):
|
|
24
|
+
"""Psqlpy connection parameters."""
|
|
25
|
+
|
|
26
|
+
dsn: NotRequired[str]
|
|
27
|
+
username: NotRequired[str]
|
|
28
|
+
password: NotRequired[str]
|
|
29
|
+
db_name: NotRequired[str]
|
|
30
|
+
host: NotRequired[str]
|
|
31
|
+
port: NotRequired[int]
|
|
32
|
+
connect_timeout_sec: NotRequired[int]
|
|
33
|
+
connect_timeout_nanosec: NotRequired[int]
|
|
34
|
+
tcp_user_timeout_sec: NotRequired[int]
|
|
35
|
+
tcp_user_timeout_nanosec: NotRequired[int]
|
|
36
|
+
keepalives: NotRequired[bool]
|
|
37
|
+
keepalives_idle_sec: NotRequired[int]
|
|
38
|
+
keepalives_idle_nanosec: NotRequired[int]
|
|
39
|
+
keepalives_interval_sec: NotRequired[int]
|
|
40
|
+
keepalives_interval_nanosec: NotRequired[int]
|
|
41
|
+
keepalives_retries: NotRequired[int]
|
|
42
|
+
ssl_mode: NotRequired[str]
|
|
43
|
+
ca_file: NotRequired[str]
|
|
44
|
+
target_session_attrs: NotRequired[str]
|
|
45
|
+
options: NotRequired[str]
|
|
46
|
+
application_name: NotRequired[str]
|
|
47
|
+
client_encoding: NotRequired[str]
|
|
48
|
+
gssencmode: NotRequired[str]
|
|
49
|
+
sslnegotiation: NotRequired[str]
|
|
50
|
+
sslcompression: NotRequired[str]
|
|
51
|
+
sslcert: NotRequired[str]
|
|
52
|
+
sslkey: NotRequired[str]
|
|
53
|
+
sslpassword: NotRequired[str]
|
|
54
|
+
sslrootcert: NotRequired[str]
|
|
55
|
+
sslcrl: NotRequired[str]
|
|
56
|
+
require_auth: NotRequired[str]
|
|
57
|
+
channel_binding: NotRequired[str]
|
|
58
|
+
krbsrvname: NotRequired[str]
|
|
59
|
+
gsslib: NotRequired[str]
|
|
60
|
+
gssdelegation: NotRequired[str]
|
|
61
|
+
service: NotRequired[str]
|
|
62
|
+
load_balance_hosts: NotRequired[str]
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class PsqlpyPoolParams(PsqlpyConnectionParams, total=False):
|
|
66
|
+
"""Psqlpy pool parameters."""
|
|
67
|
+
|
|
68
|
+
hosts: NotRequired[list[str]]
|
|
69
|
+
ports: NotRequired[list[int]]
|
|
70
|
+
conn_recycling_method: NotRequired[str]
|
|
71
|
+
max_db_pool_size: NotRequired[int]
|
|
72
|
+
configure: NotRequired["Callable[..., Any]"]
|
|
73
|
+
extra: NotRequired[dict[str, Any]]
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
__all__ = ("PsqlpyConfig", "PsqlpyConnectionParams", "PsqlpyCursor", "PsqlpyPoolParams")
|
|
66
77
|
|
|
67
78
|
|
|
68
79
|
class PsqlpyConfig(AsyncDatabaseConfig[PsqlpyConnection, ConnectionPool, PsqlpyDriver]):
|
|
69
80
|
"""Configuration for Psqlpy asynchronous database connections with direct field-based configuration."""
|
|
70
81
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
driver_type: type[PsqlpyDriver] = PsqlpyDriver
|
|
75
|
-
connection_type: type[PsqlpyConnection] = PsqlpyConnection
|
|
76
|
-
# Parameter style support information
|
|
77
|
-
supported_parameter_styles: ClassVar[tuple[str, ...]] = ("numeric",)
|
|
78
|
-
"""Psqlpy only supports $1, $2, ... (numeric) parameter style."""
|
|
79
|
-
|
|
80
|
-
default_parameter_style: ClassVar[str] = "numeric"
|
|
81
|
-
"""Psqlpy's native parameter style is $1, $2, ... (numeric)."""
|
|
82
|
+
driver_type: ClassVar[type[PsqlpyDriver]] = PsqlpyDriver
|
|
83
|
+
connection_type: "ClassVar[type[PsqlpyConnection]]" = PsqlpyConnection
|
|
82
84
|
|
|
83
85
|
def __init__(
|
|
84
86
|
self,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
dsn: Optional[str] = None,
|
|
89
|
-
username: Optional[str] = None,
|
|
90
|
-
password: Optional[str] = None,
|
|
91
|
-
db_name: Optional[str] = None,
|
|
92
|
-
host: Optional[str] = None,
|
|
93
|
-
port: Optional[int] = None,
|
|
94
|
-
hosts: Optional[list[str]] = None,
|
|
95
|
-
ports: Optional[list[int]] = None,
|
|
96
|
-
connect_timeout_sec: Optional[int] = None,
|
|
97
|
-
connect_timeout_nanosec: Optional[int] = None,
|
|
98
|
-
tcp_user_timeout_sec: Optional[int] = None,
|
|
99
|
-
tcp_user_timeout_nanosec: Optional[int] = None,
|
|
100
|
-
keepalives: Optional[bool] = None,
|
|
101
|
-
keepalives_idle_sec: Optional[int] = None,
|
|
102
|
-
keepalives_idle_nanosec: Optional[int] = None,
|
|
103
|
-
keepalives_interval_sec: Optional[int] = None,
|
|
104
|
-
keepalives_interval_nanosec: Optional[int] = None,
|
|
105
|
-
keepalives_retries: Optional[int] = None,
|
|
106
|
-
ssl_mode: Optional[str] = None,
|
|
107
|
-
ca_file: Optional[str] = None,
|
|
108
|
-
target_session_attrs: Optional[str] = None,
|
|
109
|
-
options: Optional[str] = None,
|
|
110
|
-
application_name: Optional[str] = None,
|
|
111
|
-
client_encoding: Optional[str] = None,
|
|
112
|
-
gssencmode: Optional[str] = None,
|
|
113
|
-
sslnegotiation: Optional[str] = None,
|
|
114
|
-
sslcompression: Optional[bool] = None,
|
|
115
|
-
sslcert: Optional[str] = None,
|
|
116
|
-
sslkey: Optional[str] = None,
|
|
117
|
-
sslpassword: Optional[str] = None,
|
|
118
|
-
sslrootcert: Optional[str] = None,
|
|
119
|
-
sslcrl: Optional[str] = None,
|
|
120
|
-
require_auth: Optional[str] = None,
|
|
121
|
-
channel_binding: Optional[str] = None,
|
|
122
|
-
krbsrvname: Optional[str] = None,
|
|
123
|
-
gsslib: Optional[str] = None,
|
|
124
|
-
gssdelegation: Optional[bool] = None,
|
|
125
|
-
service: Optional[str] = None,
|
|
126
|
-
load_balance_hosts: Optional[str] = None,
|
|
127
|
-
# Pool parameters
|
|
128
|
-
conn_recycling_method: Optional[str] = None,
|
|
129
|
-
max_db_pool_size: Optional[int] = None,
|
|
130
|
-
configure: Optional["Callable[[ConnectionPool], None]"] = None,
|
|
87
|
+
*,
|
|
88
|
+
pool_config: Optional[Union[PsqlpyPoolParams, dict[str, Any]]] = None,
|
|
89
|
+
statement_config: Optional[StatementConfig] = None,
|
|
131
90
|
pool_instance: Optional[ConnectionPool] = None,
|
|
132
|
-
|
|
91
|
+
migration_config: Optional[dict[str, Any]] = None,
|
|
133
92
|
) -> None:
|
|
134
93
|
"""Initialize Psqlpy asynchronous configuration.
|
|
135
94
|
|
|
136
95
|
Args:
|
|
137
|
-
|
|
138
|
-
default_row_type: Default row type for results
|
|
139
|
-
dsn: DSN of the PostgreSQL database
|
|
140
|
-
username: Username of the user in the PostgreSQL
|
|
141
|
-
password: Password of the user in the PostgreSQL
|
|
142
|
-
db_name: Name of the database in PostgreSQL
|
|
143
|
-
host: Host of the PostgreSQL (use for single host)
|
|
144
|
-
port: Port of the PostgreSQL (use for single host)
|
|
145
|
-
hosts: List of hosts of the PostgreSQL (use for multiple hosts)
|
|
146
|
-
ports: List of ports of the PostgreSQL (use for multiple hosts)
|
|
147
|
-
connect_timeout_sec: The time limit in seconds applied to each socket-level connection attempt
|
|
148
|
-
connect_timeout_nanosec: Nanoseconds for connection timeout, can be used only with connect_timeout_sec
|
|
149
|
-
tcp_user_timeout_sec: The time limit that transmitted data may remain unacknowledged before a connection is forcibly closed
|
|
150
|
-
tcp_user_timeout_nanosec: Nanoseconds for tcp_user_timeout, can be used only with tcp_user_timeout_sec
|
|
151
|
-
keepalives: Controls the use of TCP keepalive. Defaults to True (on)
|
|
152
|
-
keepalives_idle_sec: The number of seconds of inactivity after which a keepalive message is sent to the server
|
|
153
|
-
keepalives_idle_nanosec: Nanoseconds for keepalives_idle_sec
|
|
154
|
-
keepalives_interval_sec: The time interval between TCP keepalive probes
|
|
155
|
-
keepalives_interval_nanosec: Nanoseconds for keepalives_interval_sec
|
|
156
|
-
keepalives_retries: The maximum number of TCP keepalive probes that will be sent before dropping a connection
|
|
157
|
-
ssl_mode: SSL mode (disable, prefer, require, verify-ca, verify-full)
|
|
158
|
-
ca_file: Path to ca_file for SSL
|
|
159
|
-
target_session_attrs: Specifies requirements of the session (e.g., 'read-write', 'read-only', 'primary', 'standby')
|
|
160
|
-
options: Command line options used to configure the server
|
|
161
|
-
application_name: Sets the application_name parameter on the server
|
|
162
|
-
client_encoding: Sets the client_encoding parameter
|
|
163
|
-
gssencmode: GSS encryption mode (disable, prefer, require)
|
|
164
|
-
sslnegotiation: SSL negotiation mode (postgres, direct)
|
|
165
|
-
sslcompression: Whether to use SSL compression
|
|
166
|
-
sslcert: Client SSL certificate file
|
|
167
|
-
sslkey: Client SSL private key file
|
|
168
|
-
sslpassword: Password for the SSL private key
|
|
169
|
-
sslrootcert: SSL root certificate file
|
|
170
|
-
sslcrl: SSL certificate revocation list file
|
|
171
|
-
require_auth: Authentication method requirements
|
|
172
|
-
channel_binding: Channel binding preference (disable, prefer, require)
|
|
173
|
-
krbsrvname: Kerberos service name
|
|
174
|
-
gsslib: GSS library to use
|
|
175
|
-
gssdelegation: Forward GSS credentials to server
|
|
176
|
-
service: Service name for additional parameters
|
|
177
|
-
load_balance_hosts: Controls the order in which the client tries to connect to the available hosts and addresses ('disable' or 'random')
|
|
178
|
-
conn_recycling_method: How a connection is recycled
|
|
179
|
-
max_db_pool_size: Maximum size of the connection pool. Defaults to 10
|
|
180
|
-
configure: Callback to configure new connections
|
|
96
|
+
pool_config: Pool configuration parameters (TypedDict or dict)
|
|
181
97
|
pool_instance: Existing connection pool instance to use
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
# Store connection parameters as instance attributes
|
|
185
|
-
self.dsn = dsn
|
|
186
|
-
self.username = username
|
|
187
|
-
self.password = password
|
|
188
|
-
self.db_name = db_name
|
|
189
|
-
self.host = host
|
|
190
|
-
self.port = port
|
|
191
|
-
self.hosts = hosts
|
|
192
|
-
self.ports = ports
|
|
193
|
-
self.connect_timeout_sec = connect_timeout_sec
|
|
194
|
-
self.connect_timeout_nanosec = connect_timeout_nanosec
|
|
195
|
-
self.tcp_user_timeout_sec = tcp_user_timeout_sec
|
|
196
|
-
self.tcp_user_timeout_nanosec = tcp_user_timeout_nanosec
|
|
197
|
-
self.keepalives = keepalives
|
|
198
|
-
self.keepalives_idle_sec = keepalives_idle_sec
|
|
199
|
-
self.keepalives_idle_nanosec = keepalives_idle_nanosec
|
|
200
|
-
self.keepalives_interval_sec = keepalives_interval_sec
|
|
201
|
-
self.keepalives_interval_nanosec = keepalives_interval_nanosec
|
|
202
|
-
self.keepalives_retries = keepalives_retries
|
|
203
|
-
self.ssl_mode = ssl_mode
|
|
204
|
-
self.ca_file = ca_file
|
|
205
|
-
self.target_session_attrs = target_session_attrs
|
|
206
|
-
self.options = options
|
|
207
|
-
self.application_name = application_name
|
|
208
|
-
self.client_encoding = client_encoding
|
|
209
|
-
self.gssencmode = gssencmode
|
|
210
|
-
self.sslnegotiation = sslnegotiation
|
|
211
|
-
self.sslcompression = sslcompression
|
|
212
|
-
self.sslcert = sslcert
|
|
213
|
-
self.sslkey = sslkey
|
|
214
|
-
self.sslpassword = sslpassword
|
|
215
|
-
self.sslrootcert = sslrootcert
|
|
216
|
-
self.sslcrl = sslcrl
|
|
217
|
-
self.require_auth = require_auth
|
|
218
|
-
self.channel_binding = channel_binding
|
|
219
|
-
self.krbsrvname = krbsrvname
|
|
220
|
-
self.gsslib = gsslib
|
|
221
|
-
self.gssdelegation = gssdelegation
|
|
222
|
-
self.service = service
|
|
223
|
-
self.load_balance_hosts = load_balance_hosts
|
|
224
|
-
|
|
225
|
-
# Store pool parameters as instance attributes
|
|
226
|
-
self.conn_recycling_method = conn_recycling_method
|
|
227
|
-
self.max_db_pool_size = max_db_pool_size
|
|
228
|
-
self.configure = configure
|
|
229
|
-
|
|
230
|
-
self.extras = kwargs or {}
|
|
231
|
-
|
|
232
|
-
# Store other config
|
|
233
|
-
self.statement_config = statement_config or SQLConfig()
|
|
234
|
-
self.default_row_type = default_row_type
|
|
235
|
-
|
|
236
|
-
super().__init__()
|
|
237
|
-
|
|
238
|
-
@property
|
|
239
|
-
def connection_config_dict(self) -> dict[str, Any]:
|
|
240
|
-
"""Return the connection configuration as a dict for psqlpy.Connection.
|
|
241
|
-
|
|
242
|
-
This method filters out pool-specific parameters that are not valid for psqlpy.Connection.
|
|
98
|
+
statement_config: Default SQL statement configuration
|
|
99
|
+
migration_config: Migration configuration
|
|
243
100
|
"""
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
"""Return the full pool configuration as a dict for psqlpy.ConnectionPool.
|
|
101
|
+
processed_pool_config: dict[str, Any] = dict(pool_config) if pool_config else {}
|
|
102
|
+
if "extra" in processed_pool_config:
|
|
103
|
+
extras = processed_pool_config.pop("extra")
|
|
104
|
+
processed_pool_config.update(extras)
|
|
105
|
+
super().__init__(
|
|
106
|
+
pool_config=processed_pool_config,
|
|
107
|
+
pool_instance=pool_instance,
|
|
108
|
+
migration_config=migration_config,
|
|
109
|
+
statement_config=statement_config or psqlpy_statement_config,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
def _get_pool_config_dict(self) -> dict[str, Any]:
|
|
113
|
+
"""Get pool configuration as plain dict for external library.
|
|
258
114
|
|
|
259
115
|
Returns:
|
|
260
|
-
|
|
116
|
+
Dictionary with pool parameters, filtering out None values.
|
|
261
117
|
"""
|
|
262
|
-
|
|
263
|
-
config = {
|
|
264
|
-
field: getattr(self, field)
|
|
265
|
-
for field in POOL_FIELDS
|
|
266
|
-
if getattr(self, field, None) is not None and getattr(self, field) is not Empty
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
# Merge extras parameters
|
|
270
|
-
config.update(self.extras)
|
|
271
|
-
|
|
272
|
-
return config
|
|
118
|
+
return {k: v for k, v in self.pool_config.items() if v is not None}
|
|
273
119
|
|
|
274
120
|
async def _create_pool(self) -> "ConnectionPool":
|
|
275
121
|
"""Create the actual async connection pool."""
|
|
276
122
|
logger.info("Creating psqlpy connection pool", extra={"adapter": "psqlpy"})
|
|
277
123
|
|
|
278
124
|
try:
|
|
279
|
-
config = self.
|
|
280
|
-
|
|
125
|
+
config = self._get_pool_config_dict()
|
|
126
|
+
|
|
127
|
+
pool = ConnectionPool(**config)
|
|
281
128
|
logger.info("Psqlpy connection pool created successfully", extra={"adapter": "psqlpy"})
|
|
282
129
|
except Exception as e:
|
|
283
130
|
logger.exception("Failed to create psqlpy connection pool", extra={"adapter": "psqlpy", "error": str(e)})
|
|
@@ -327,29 +174,21 @@ class PsqlpyConfig(AsyncDatabaseConfig[PsqlpyConnection, ConnectionPool, PsqlpyD
|
|
|
327
174
|
yield conn
|
|
328
175
|
|
|
329
176
|
@asynccontextmanager
|
|
330
|
-
async def provide_session(
|
|
177
|
+
async def provide_session(
|
|
178
|
+
self, *args: Any, statement_config: "Optional[StatementConfig]" = None, **kwargs: Any
|
|
179
|
+
) -> AsyncGenerator[PsqlpyDriver, None]:
|
|
331
180
|
"""Provide an async driver session context manager.
|
|
332
181
|
|
|
333
182
|
Args:
|
|
334
183
|
*args: Additional arguments.
|
|
184
|
+
statement_config: Optional statement configuration override.
|
|
335
185
|
**kwargs: Additional keyword arguments.
|
|
336
186
|
|
|
337
187
|
Yields:
|
|
338
188
|
A PsqlpyDriver instance.
|
|
339
189
|
"""
|
|
340
190
|
async with self.provide_connection(*args, **kwargs) as conn:
|
|
341
|
-
|
|
342
|
-
# Inject parameter style info if not already set
|
|
343
|
-
if statement_config.allowed_parameter_styles is None:
|
|
344
|
-
from dataclasses import replace
|
|
345
|
-
|
|
346
|
-
statement_config = replace(
|
|
347
|
-
statement_config,
|
|
348
|
-
allowed_parameter_styles=self.supported_parameter_styles,
|
|
349
|
-
default_parameter_style=self.default_parameter_style,
|
|
350
|
-
)
|
|
351
|
-
driver = self.driver_type(connection=conn, config=statement_config)
|
|
352
|
-
yield driver
|
|
191
|
+
yield self.driver_type(connection=conn, statement_config=statement_config or self.statement_config)
|
|
353
192
|
|
|
354
193
|
async def provide_pool(self, *args: Any, **kwargs: Any) -> ConnectionPool:
|
|
355
194
|
"""Provide async pool instance.
|
|
@@ -371,5 +210,5 @@ class PsqlpyConfig(AsyncDatabaseConfig[PsqlpyConnection, ConnectionPool, PsqlpyD
|
|
|
371
210
|
Dictionary mapping type names to types.
|
|
372
211
|
"""
|
|
373
212
|
namespace = super().get_signature_namespace()
|
|
374
|
-
namespace.update({"PsqlpyConnection": PsqlpyConnection})
|
|
213
|
+
namespace.update({"PsqlpyConnection": PsqlpyConnection, "PsqlpyCursor": PsqlpyCursor})
|
|
375
214
|
return namespace
|