sqlspec 0.14.0__py3-none-any.whl → 0.15.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 (158) hide show
  1. sqlspec/__init__.py +50 -25
  2. sqlspec/__main__.py +12 -0
  3. sqlspec/__metadata__.py +1 -3
  4. sqlspec/_serialization.py +1 -2
  5. sqlspec/_sql.py +256 -120
  6. sqlspec/_typing.py +278 -142
  7. sqlspec/adapters/adbc/__init__.py +4 -3
  8. sqlspec/adapters/adbc/_types.py +12 -0
  9. sqlspec/adapters/adbc/config.py +115 -248
  10. sqlspec/adapters/adbc/driver.py +462 -353
  11. sqlspec/adapters/aiosqlite/__init__.py +18 -3
  12. sqlspec/adapters/aiosqlite/_types.py +13 -0
  13. sqlspec/adapters/aiosqlite/config.py +199 -129
  14. sqlspec/adapters/aiosqlite/driver.py +230 -269
  15. sqlspec/adapters/asyncmy/__init__.py +18 -3
  16. sqlspec/adapters/asyncmy/_types.py +12 -0
  17. sqlspec/adapters/asyncmy/config.py +80 -168
  18. sqlspec/adapters/asyncmy/driver.py +260 -225
  19. sqlspec/adapters/asyncpg/__init__.py +19 -4
  20. sqlspec/adapters/asyncpg/_types.py +17 -0
  21. sqlspec/adapters/asyncpg/config.py +82 -181
  22. sqlspec/adapters/asyncpg/driver.py +285 -383
  23. sqlspec/adapters/bigquery/__init__.py +17 -3
  24. sqlspec/adapters/bigquery/_types.py +12 -0
  25. sqlspec/adapters/bigquery/config.py +191 -258
  26. sqlspec/adapters/bigquery/driver.py +474 -646
  27. sqlspec/adapters/duckdb/__init__.py +14 -3
  28. sqlspec/adapters/duckdb/_types.py +12 -0
  29. sqlspec/adapters/duckdb/config.py +415 -351
  30. sqlspec/adapters/duckdb/driver.py +343 -413
  31. sqlspec/adapters/oracledb/__init__.py +19 -5
  32. sqlspec/adapters/oracledb/_types.py +14 -0
  33. sqlspec/adapters/oracledb/config.py +123 -379
  34. sqlspec/adapters/oracledb/driver.py +507 -560
  35. sqlspec/adapters/psqlpy/__init__.py +13 -3
  36. sqlspec/adapters/psqlpy/_types.py +11 -0
  37. sqlspec/adapters/psqlpy/config.py +93 -254
  38. sqlspec/adapters/psqlpy/driver.py +505 -234
  39. sqlspec/adapters/psycopg/__init__.py +19 -5
  40. sqlspec/adapters/psycopg/_types.py +17 -0
  41. sqlspec/adapters/psycopg/config.py +143 -403
  42. sqlspec/adapters/psycopg/driver.py +706 -872
  43. sqlspec/adapters/sqlite/__init__.py +14 -3
  44. sqlspec/adapters/sqlite/_types.py +11 -0
  45. sqlspec/adapters/sqlite/config.py +202 -118
  46. sqlspec/adapters/sqlite/driver.py +264 -303
  47. sqlspec/base.py +105 -9
  48. sqlspec/{statement/builder → builder}/__init__.py +12 -14
  49. sqlspec/{statement/builder → builder}/_base.py +120 -55
  50. sqlspec/{statement/builder → builder}/_column.py +17 -6
  51. sqlspec/{statement/builder → builder}/_ddl.py +46 -79
  52. sqlspec/{statement/builder → builder}/_ddl_utils.py +5 -10
  53. sqlspec/{statement/builder → builder}/_delete.py +6 -25
  54. sqlspec/{statement/builder → builder}/_insert.py +6 -64
  55. sqlspec/builder/_merge.py +56 -0
  56. sqlspec/{statement/builder → builder}/_parsing_utils.py +3 -10
  57. sqlspec/{statement/builder → builder}/_select.py +11 -56
  58. sqlspec/{statement/builder → builder}/_update.py +12 -18
  59. sqlspec/{statement/builder → builder}/mixins/__init__.py +10 -14
  60. sqlspec/{statement/builder → builder}/mixins/_cte_and_set_ops.py +48 -59
  61. sqlspec/{statement/builder → builder}/mixins/_insert_operations.py +22 -16
  62. sqlspec/{statement/builder → builder}/mixins/_join_operations.py +1 -3
  63. sqlspec/{statement/builder → builder}/mixins/_merge_operations.py +3 -5
  64. sqlspec/{statement/builder → builder}/mixins/_order_limit_operations.py +3 -3
  65. sqlspec/{statement/builder → builder}/mixins/_pivot_operations.py +4 -8
  66. sqlspec/{statement/builder → builder}/mixins/_select_operations.py +21 -36
  67. sqlspec/{statement/builder → builder}/mixins/_update_operations.py +3 -14
  68. sqlspec/{statement/builder → builder}/mixins/_where_clause.py +52 -79
  69. sqlspec/cli.py +4 -5
  70. sqlspec/config.py +180 -133
  71. sqlspec/core/__init__.py +63 -0
  72. sqlspec/core/cache.py +873 -0
  73. sqlspec/core/compiler.py +396 -0
  74. sqlspec/core/filters.py +828 -0
  75. sqlspec/core/hashing.py +310 -0
  76. sqlspec/core/parameters.py +1209 -0
  77. sqlspec/core/result.py +664 -0
  78. sqlspec/{statement → core}/splitter.py +321 -191
  79. sqlspec/core/statement.py +651 -0
  80. sqlspec/driver/__init__.py +7 -10
  81. sqlspec/driver/_async.py +387 -176
  82. sqlspec/driver/_common.py +527 -289
  83. sqlspec/driver/_sync.py +390 -172
  84. sqlspec/driver/mixins/__init__.py +2 -19
  85. sqlspec/driver/mixins/_result_tools.py +168 -0
  86. sqlspec/driver/mixins/_sql_translator.py +6 -3
  87. sqlspec/exceptions.py +5 -252
  88. sqlspec/extensions/aiosql/adapter.py +93 -96
  89. sqlspec/extensions/litestar/config.py +0 -1
  90. sqlspec/extensions/litestar/handlers.py +15 -26
  91. sqlspec/extensions/litestar/plugin.py +16 -14
  92. sqlspec/extensions/litestar/providers.py +17 -52
  93. sqlspec/loader.py +424 -105
  94. sqlspec/migrations/__init__.py +12 -0
  95. sqlspec/migrations/base.py +92 -68
  96. sqlspec/migrations/commands.py +24 -106
  97. sqlspec/migrations/loaders.py +402 -0
  98. sqlspec/migrations/runner.py +49 -51
  99. sqlspec/migrations/tracker.py +31 -44
  100. sqlspec/migrations/utils.py +64 -24
  101. sqlspec/protocols.py +7 -183
  102. sqlspec/storage/__init__.py +1 -1
  103. sqlspec/storage/backends/base.py +37 -40
  104. sqlspec/storage/backends/fsspec.py +136 -112
  105. sqlspec/storage/backends/obstore.py +138 -160
  106. sqlspec/storage/capabilities.py +5 -4
  107. sqlspec/storage/registry.py +57 -106
  108. sqlspec/typing.py +136 -115
  109. sqlspec/utils/__init__.py +2 -3
  110. sqlspec/utils/correlation.py +0 -3
  111. sqlspec/utils/deprecation.py +6 -6
  112. sqlspec/utils/fixtures.py +6 -6
  113. sqlspec/utils/logging.py +0 -2
  114. sqlspec/utils/module_loader.py +7 -12
  115. sqlspec/utils/singleton.py +0 -1
  116. sqlspec/utils/sync_tools.py +16 -37
  117. sqlspec/utils/text.py +12 -51
  118. sqlspec/utils/type_guards.py +443 -232
  119. {sqlspec-0.14.0.dist-info → sqlspec-0.15.0.dist-info}/METADATA +7 -2
  120. sqlspec-0.15.0.dist-info/RECORD +134 -0
  121. sqlspec-0.15.0.dist-info/entry_points.txt +2 -0
  122. sqlspec/driver/connection.py +0 -207
  123. sqlspec/driver/mixins/_cache.py +0 -114
  124. sqlspec/driver/mixins/_csv_writer.py +0 -91
  125. sqlspec/driver/mixins/_pipeline.py +0 -508
  126. sqlspec/driver/mixins/_query_tools.py +0 -796
  127. sqlspec/driver/mixins/_result_utils.py +0 -138
  128. sqlspec/driver/mixins/_storage.py +0 -912
  129. sqlspec/driver/mixins/_type_coercion.py +0 -128
  130. sqlspec/driver/parameters.py +0 -138
  131. sqlspec/statement/__init__.py +0 -21
  132. sqlspec/statement/builder/_merge.py +0 -95
  133. sqlspec/statement/cache.py +0 -50
  134. sqlspec/statement/filters.py +0 -625
  135. sqlspec/statement/parameters.py +0 -996
  136. sqlspec/statement/pipelines/__init__.py +0 -210
  137. sqlspec/statement/pipelines/analyzers/__init__.py +0 -9
  138. sqlspec/statement/pipelines/analyzers/_analyzer.py +0 -646
  139. sqlspec/statement/pipelines/context.py +0 -115
  140. sqlspec/statement/pipelines/transformers/__init__.py +0 -7
  141. sqlspec/statement/pipelines/transformers/_expression_simplifier.py +0 -88
  142. sqlspec/statement/pipelines/transformers/_literal_parameterizer.py +0 -1247
  143. sqlspec/statement/pipelines/transformers/_remove_comments_and_hints.py +0 -76
  144. sqlspec/statement/pipelines/validators/__init__.py +0 -23
  145. sqlspec/statement/pipelines/validators/_dml_safety.py +0 -290
  146. sqlspec/statement/pipelines/validators/_parameter_style.py +0 -370
  147. sqlspec/statement/pipelines/validators/_performance.py +0 -714
  148. sqlspec/statement/pipelines/validators/_security.py +0 -967
  149. sqlspec/statement/result.py +0 -435
  150. sqlspec/statement/sql.py +0 -1774
  151. sqlspec/utils/cached_property.py +0 -25
  152. sqlspec/utils/statement_hashing.py +0 -203
  153. sqlspec-0.14.0.dist-info/RECORD +0 -143
  154. sqlspec-0.14.0.dist-info/entry_points.txt +0 -2
  155. /sqlspec/{statement/builder → builder}/mixins/_delete_operations.py +0 -0
  156. {sqlspec-0.14.0.dist-info → sqlspec-0.15.0.dist-info}/WHEEL +0 -0
  157. {sqlspec-0.14.0.dist-info → sqlspec-0.15.0.dist-info}/licenses/LICENSE +0 -0
  158. {sqlspec-0.14.0.dist-info → sqlspec-0.15.0.dist-info}/licenses/NOTICE +0 -0
@@ -1,6 +1,16 @@
1
1
  """Psqlpy adapter for SQLSpec."""
2
2
 
3
- from sqlspec.adapters.psqlpy.config import CONNECTION_FIELDS, POOL_FIELDS, PsqlpyConfig
4
- from sqlspec.adapters.psqlpy.driver import PsqlpyConnection, PsqlpyDriver
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__ = ("CONNECTION_FIELDS", "POOL_FIELDS", "PsqlpyConfig", "PsqlpyConnection", "PsqlpyDriver")
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.driver import PsqlpyConnection, PsqlpyDriver
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.sql import SQLConfig
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
- CONNECTION_FIELDS = frozenset(
22
- {
23
- "dsn",
24
- "username",
25
- "password",
26
- "db_name",
27
- "host",
28
- "port",
29
- "connect_timeout_sec",
30
- "connect_timeout_nanosec",
31
- "tcp_user_timeout_sec",
32
- "tcp_user_timeout_nanosec",
33
- "keepalives",
34
- "keepalives_idle_sec",
35
- "keepalives_idle_nanosec",
36
- "keepalives_interval_sec",
37
- "keepalives_interval_nanosec",
38
- "keepalives_retries",
39
- "ssl_mode",
40
- "ca_file",
41
- "target_session_attrs",
42
- "options",
43
- "application_name",
44
- "client_encoding",
45
- "gssencmode",
46
- "sslnegotiation",
47
- "sslcompression",
48
- "sslcert",
49
- "sslkey",
50
- "sslpassword",
51
- "sslrootcert",
52
- "sslcrl",
53
- "require_auth",
54
- "channel_binding",
55
- "krbsrvname",
56
- "gsslib",
57
- "gssdelegation",
58
- "service",
59
- "load_balance_hosts",
60
- }
61
- )
62
-
63
- POOL_FIELDS = CONNECTION_FIELDS.union({"hosts", "ports", "conn_recycling_method", "max_db_pool_size", "configure"})
64
-
65
- __all__ = ("CONNECTION_FIELDS", "POOL_FIELDS", "PsqlpyConfig")
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
- is_async: ClassVar[bool] = True
72
- supports_connection_pooling: ClassVar[bool] = True
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
- statement_config: Optional[SQLConfig] = None,
86
- default_row_type: type[DictRow] = DictRow,
87
- # Connection parameters
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
- **kwargs: Any,
91
+ migration_config: Optional[dict[str, Any]] = None,
133
92
  ) -> None:
134
93
  """Initialize Psqlpy asynchronous configuration.
135
94
 
136
95
  Args:
137
- statement_config: Default SQL statement configuration
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
- **kwargs: Additional parameters (stored in extras)
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
- # Gather non-None connection parameters
245
- config = {
246
- field: getattr(self, field)
247
- for field in CONNECTION_FIELDS
248
- if getattr(self, field, None) is not None and getattr(self, field) is not Empty
249
- }
250
-
251
- config.update(self.extras)
252
-
253
- return config
254
-
255
- @property
256
- def pool_config_dict(self) -> dict[str, Any]:
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
- A dictionary containing all pool configuration parameters.
116
+ Dictionary with pool parameters, filtering out None values.
261
117
  """
262
- # Gather non-None parameters from all fields (connection + pool)
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.pool_config_dict
280
- pool = ConnectionPool(**config) # pyright: ignore
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(self, *args: Any, **kwargs: Any) -> AsyncGenerator[PsqlpyDriver, None]:
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
- statement_config = self.statement_config
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