sqlspec 0.13.1__py3-none-any.whl → 0.16.2__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 +71 -8
- sqlspec/__main__.py +12 -0
- sqlspec/__metadata__.py +1 -3
- sqlspec/_serialization.py +1 -2
- sqlspec/_sql.py +930 -136
- sqlspec/_typing.py +278 -142
- sqlspec/adapters/adbc/__init__.py +4 -3
- sqlspec/adapters/adbc/_types.py +12 -0
- sqlspec/adapters/adbc/config.py +116 -285
- sqlspec/adapters/adbc/driver.py +462 -340
- sqlspec/adapters/aiosqlite/__init__.py +18 -3
- sqlspec/adapters/aiosqlite/_types.py +13 -0
- sqlspec/adapters/aiosqlite/config.py +202 -150
- sqlspec/adapters/aiosqlite/driver.py +226 -247
- sqlspec/adapters/asyncmy/__init__.py +18 -3
- sqlspec/adapters/asyncmy/_types.py +12 -0
- sqlspec/adapters/asyncmy/config.py +80 -199
- sqlspec/adapters/asyncmy/driver.py +257 -215
- sqlspec/adapters/asyncpg/__init__.py +19 -4
- sqlspec/adapters/asyncpg/_types.py +17 -0
- sqlspec/adapters/asyncpg/config.py +81 -214
- sqlspec/adapters/asyncpg/driver.py +284 -359
- sqlspec/adapters/bigquery/__init__.py +17 -3
- sqlspec/adapters/bigquery/_types.py +12 -0
- sqlspec/adapters/bigquery/config.py +191 -299
- sqlspec/adapters/bigquery/driver.py +474 -634
- sqlspec/adapters/duckdb/__init__.py +14 -3
- sqlspec/adapters/duckdb/_types.py +12 -0
- sqlspec/adapters/duckdb/config.py +414 -397
- sqlspec/adapters/duckdb/driver.py +342 -393
- sqlspec/adapters/oracledb/__init__.py +19 -5
- sqlspec/adapters/oracledb/_types.py +14 -0
- sqlspec/adapters/oracledb/config.py +123 -458
- sqlspec/adapters/oracledb/driver.py +505 -531
- sqlspec/adapters/psqlpy/__init__.py +13 -3
- sqlspec/adapters/psqlpy/_types.py +11 -0
- sqlspec/adapters/psqlpy/config.py +93 -307
- sqlspec/adapters/psqlpy/driver.py +504 -213
- sqlspec/adapters/psycopg/__init__.py +19 -5
- sqlspec/adapters/psycopg/_types.py +17 -0
- sqlspec/adapters/psycopg/config.py +143 -472
- sqlspec/adapters/psycopg/driver.py +704 -825
- sqlspec/adapters/sqlite/__init__.py +14 -3
- sqlspec/adapters/sqlite/_types.py +11 -0
- sqlspec/adapters/sqlite/config.py +208 -142
- sqlspec/adapters/sqlite/driver.py +263 -278
- sqlspec/base.py +105 -9
- sqlspec/{statement/builder → builder}/__init__.py +12 -14
- sqlspec/{statement/builder/base.py → builder/_base.py} +184 -86
- sqlspec/{statement/builder/column.py → builder/_column.py} +97 -60
- sqlspec/{statement/builder/ddl.py → builder/_ddl.py} +61 -131
- sqlspec/{statement/builder → builder}/_ddl_utils.py +4 -10
- sqlspec/{statement/builder/delete.py → builder/_delete.py} +10 -30
- sqlspec/builder/_insert.py +421 -0
- sqlspec/builder/_merge.py +71 -0
- sqlspec/{statement/builder → builder}/_parsing_utils.py +49 -26
- sqlspec/builder/_select.py +170 -0
- sqlspec/{statement/builder/update.py → builder/_update.py} +16 -20
- sqlspec/builder/mixins/__init__.py +55 -0
- sqlspec/builder/mixins/_cte_and_set_ops.py +222 -0
- sqlspec/{statement/builder/mixins/_delete_from.py → builder/mixins/_delete_operations.py} +8 -1
- sqlspec/builder/mixins/_insert_operations.py +244 -0
- sqlspec/{statement/builder/mixins/_join.py → builder/mixins/_join_operations.py} +45 -13
- sqlspec/{statement/builder/mixins/_merge_clauses.py → builder/mixins/_merge_operations.py} +188 -30
- sqlspec/builder/mixins/_order_limit_operations.py +135 -0
- sqlspec/builder/mixins/_pivot_operations.py +153 -0
- sqlspec/builder/mixins/_select_operations.py +604 -0
- sqlspec/builder/mixins/_update_operations.py +202 -0
- sqlspec/builder/mixins/_where_clause.py +644 -0
- sqlspec/cli.py +247 -0
- sqlspec/config.py +183 -138
- sqlspec/core/__init__.py +63 -0
- sqlspec/core/cache.py +871 -0
- sqlspec/core/compiler.py +417 -0
- sqlspec/core/filters.py +830 -0
- sqlspec/core/hashing.py +310 -0
- sqlspec/core/parameters.py +1237 -0
- sqlspec/core/result.py +677 -0
- sqlspec/{statement → core}/splitter.py +321 -191
- sqlspec/core/statement.py +676 -0
- sqlspec/driver/__init__.py +7 -10
- sqlspec/driver/_async.py +422 -163
- sqlspec/driver/_common.py +545 -287
- sqlspec/driver/_sync.py +426 -160
- sqlspec/driver/mixins/__init__.py +2 -13
- sqlspec/driver/mixins/_result_tools.py +193 -0
- sqlspec/driver/mixins/_sql_translator.py +65 -14
- sqlspec/exceptions.py +5 -252
- sqlspec/extensions/aiosql/adapter.py +93 -96
- sqlspec/extensions/litestar/__init__.py +2 -1
- sqlspec/extensions/litestar/cli.py +48 -0
- sqlspec/extensions/litestar/config.py +0 -1
- sqlspec/extensions/litestar/handlers.py +15 -26
- sqlspec/extensions/litestar/plugin.py +21 -16
- sqlspec/extensions/litestar/providers.py +17 -52
- sqlspec/loader.py +423 -104
- sqlspec/migrations/__init__.py +35 -0
- sqlspec/migrations/base.py +414 -0
- sqlspec/migrations/commands.py +443 -0
- sqlspec/migrations/loaders.py +402 -0
- sqlspec/migrations/runner.py +213 -0
- sqlspec/migrations/tracker.py +140 -0
- sqlspec/migrations/utils.py +129 -0
- sqlspec/protocols.py +51 -186
- 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 -2
- 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 +482 -235
- {sqlspec-0.13.1.dist-info → sqlspec-0.16.2.dist-info}/METADATA +7 -2
- sqlspec-0.16.2.dist-info/RECORD +134 -0
- sqlspec-0.16.2.dist-info/entry_points.txt +2 -0
- sqlspec/driver/connection.py +0 -207
- sqlspec/driver/mixins/_csv_writer.py +0 -91
- sqlspec/driver/mixins/_pipeline.py +0 -512
- sqlspec/driver/mixins/_result_utils.py +0 -140
- sqlspec/driver/mixins/_storage.py +0 -926
- sqlspec/driver/mixins/_type_coercion.py +0 -130
- sqlspec/driver/parameters.py +0 -138
- sqlspec/service/__init__.py +0 -4
- sqlspec/service/_util.py +0 -147
- sqlspec/service/base.py +0 -1131
- sqlspec/service/pagination.py +0 -26
- sqlspec/statement/__init__.py +0 -21
- sqlspec/statement/builder/insert.py +0 -288
- sqlspec/statement/builder/merge.py +0 -95
- sqlspec/statement/builder/mixins/__init__.py +0 -65
- sqlspec/statement/builder/mixins/_aggregate_functions.py +0 -250
- sqlspec/statement/builder/mixins/_case_builder.py +0 -91
- sqlspec/statement/builder/mixins/_common_table_expr.py +0 -90
- sqlspec/statement/builder/mixins/_from.py +0 -63
- sqlspec/statement/builder/mixins/_group_by.py +0 -118
- sqlspec/statement/builder/mixins/_having.py +0 -35
- sqlspec/statement/builder/mixins/_insert_from_select.py +0 -47
- sqlspec/statement/builder/mixins/_insert_into.py +0 -36
- sqlspec/statement/builder/mixins/_insert_values.py +0 -67
- sqlspec/statement/builder/mixins/_limit_offset.py +0 -53
- sqlspec/statement/builder/mixins/_order_by.py +0 -46
- sqlspec/statement/builder/mixins/_pivot.py +0 -79
- sqlspec/statement/builder/mixins/_returning.py +0 -37
- sqlspec/statement/builder/mixins/_select_columns.py +0 -61
- sqlspec/statement/builder/mixins/_set_ops.py +0 -122
- sqlspec/statement/builder/mixins/_unpivot.py +0 -77
- sqlspec/statement/builder/mixins/_update_from.py +0 -55
- sqlspec/statement/builder/mixins/_update_set.py +0 -94
- sqlspec/statement/builder/mixins/_update_table.py +0 -29
- sqlspec/statement/builder/mixins/_where.py +0 -401
- sqlspec/statement/builder/mixins/_window_functions.py +0 -86
- sqlspec/statement/builder/select.py +0 -221
- sqlspec/statement/filters.py +0 -596
- sqlspec/statement/parameter_manager.py +0 -220
- sqlspec/statement/parameters.py +0 -867
- 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 -115
- 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 -718
- sqlspec/statement/pipelines/validators/_security.py +0 -967
- sqlspec/statement/result.py +0 -435
- sqlspec/statement/sql.py +0 -1704
- sqlspec/statement/sql_compiler.py +0 -140
- sqlspec/utils/cached_property.py +0 -25
- sqlspec-0.13.1.dist-info/RECORD +0 -150
- {sqlspec-0.13.1.dist-info → sqlspec-0.16.2.dist-info}/WHEEL +0 -0
- {sqlspec-0.13.1.dist-info → sqlspec-0.16.2.dist-info}/licenses/LICENSE +0 -0
- {sqlspec-0.13.1.dist-info → sqlspec-0.16.2.dist-info}/licenses/NOTICE +0 -0
|
@@ -3,222 +3,106 @@
|
|
|
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, Union
|
|
6
|
+
from typing import TYPE_CHECKING, Any, ClassVar, Optional, TypedDict, Union
|
|
7
7
|
|
|
8
8
|
import asyncmy
|
|
9
|
+
from asyncmy.cursors import Cursor, DictCursor
|
|
9
10
|
from asyncmy.pool import Pool as AsyncmyPool
|
|
11
|
+
from typing_extensions import NotRequired
|
|
10
12
|
|
|
11
|
-
from sqlspec.adapters.asyncmy.
|
|
13
|
+
from sqlspec.adapters.asyncmy._types import AsyncmyConnection
|
|
14
|
+
from sqlspec.adapters.asyncmy.driver import AsyncmyCursor, AsyncmyDriver, asyncmy_statement_config
|
|
12
15
|
from sqlspec.config import AsyncDatabaseConfig
|
|
13
|
-
from sqlspec.statement.sql import SQLConfig
|
|
14
|
-
from sqlspec.typing import DictRow, Empty
|
|
15
16
|
|
|
16
17
|
if TYPE_CHECKING:
|
|
17
18
|
from asyncmy.cursors import Cursor, DictCursor
|
|
18
19
|
from asyncmy.pool import Pool
|
|
19
|
-
from sqlglot.dialects.dialect import DialectType
|
|
20
20
|
|
|
21
|
+
from sqlspec.core.statement import StatementConfig
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
|
|
24
|
+
__all__ = ("AsyncmyConfig", "AsyncmyConnectionParams", "AsyncmyPoolParams")
|
|
23
25
|
|
|
24
26
|
logger = logging.getLogger(__name__)
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
28
|
+
|
|
29
|
+
class AsyncmyConnectionParams(TypedDict, total=False):
|
|
30
|
+
"""Asyncmy connection parameters."""
|
|
31
|
+
|
|
32
|
+
host: NotRequired[str]
|
|
33
|
+
user: NotRequired[str]
|
|
34
|
+
password: NotRequired[str]
|
|
35
|
+
database: NotRequired[str]
|
|
36
|
+
port: NotRequired[int]
|
|
37
|
+
unix_socket: NotRequired[str]
|
|
38
|
+
charset: NotRequired[str]
|
|
39
|
+
connect_timeout: NotRequired[int]
|
|
40
|
+
read_default_file: NotRequired[str]
|
|
41
|
+
read_default_group: NotRequired[str]
|
|
42
|
+
autocommit: NotRequired[bool]
|
|
43
|
+
local_infile: NotRequired[bool]
|
|
44
|
+
ssl: NotRequired[Any]
|
|
45
|
+
sql_mode: NotRequired[str]
|
|
46
|
+
init_command: NotRequired[str]
|
|
47
|
+
cursor_class: NotRequired[Union[type["Cursor"], type["DictCursor"]]]
|
|
48
|
+
extra: NotRequired[dict[str, Any]]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class AsyncmyPoolParams(AsyncmyConnectionParams, total=False):
|
|
52
|
+
"""Asyncmy pool parameters."""
|
|
53
|
+
|
|
54
|
+
minsize: NotRequired[int]
|
|
55
|
+
maxsize: NotRequired[int]
|
|
56
|
+
echo: NotRequired[bool]
|
|
57
|
+
pool_recycle: NotRequired[int]
|
|
48
58
|
|
|
49
59
|
|
|
50
60
|
class AsyncmyConfig(AsyncDatabaseConfig[AsyncmyConnection, "Pool", AsyncmyDriver]): # pyright: ignore
|
|
51
61
|
"""Configuration for Asyncmy database connections with direct field-based configuration."""
|
|
52
62
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"autocommit",
|
|
56
|
-
"charset",
|
|
57
|
-
"connect_timeout",
|
|
58
|
-
"cursor_class",
|
|
59
|
-
"database",
|
|
60
|
-
"default_row_type",
|
|
61
|
-
"echo",
|
|
62
|
-
"extras",
|
|
63
|
-
"host",
|
|
64
|
-
"init_command",
|
|
65
|
-
"local_infile",
|
|
66
|
-
"maxsize",
|
|
67
|
-
"minsize",
|
|
68
|
-
"password",
|
|
69
|
-
"pool_instance",
|
|
70
|
-
"pool_recycle",
|
|
71
|
-
"port",
|
|
72
|
-
"read_default_file",
|
|
73
|
-
"read_default_group",
|
|
74
|
-
"sql_mode",
|
|
75
|
-
"ssl",
|
|
76
|
-
"statement_config",
|
|
77
|
-
"unix_socket",
|
|
78
|
-
"user",
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
is_async: ClassVar[bool] = True
|
|
82
|
-
supports_connection_pooling: ClassVar[bool] = True
|
|
83
|
-
driver_type: type[AsyncmyDriver] = AsyncmyDriver
|
|
84
|
-
connection_type: type[AsyncmyConnection] = AsyncmyConnection # pyright: ignore
|
|
85
|
-
|
|
86
|
-
# Parameter style support information
|
|
87
|
-
supported_parameter_styles: ClassVar[tuple[str, ...]] = ("pyformat_positional",)
|
|
88
|
-
"""AsyncMy only supports %s (pyformat_positional) parameter style."""
|
|
89
|
-
|
|
90
|
-
preferred_parameter_style: ClassVar[str] = "pyformat_positional"
|
|
91
|
-
"""AsyncMy's native parameter style is %s (pyformat_positional)."""
|
|
63
|
+
driver_type: ClassVar[type[AsyncmyDriver]] = AsyncmyDriver
|
|
64
|
+
connection_type: "ClassVar[type[AsyncmyConnection]]" = AsyncmyConnection # pyright: ignore
|
|
92
65
|
|
|
93
66
|
def __init__(
|
|
94
67
|
self,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
password: Optional[str] = None,
|
|
101
|
-
database: Optional[str] = None,
|
|
102
|
-
port: Optional[int] = None,
|
|
103
|
-
unix_socket: Optional[str] = None,
|
|
104
|
-
charset: Optional[str] = None,
|
|
105
|
-
connect_timeout: Optional[float] = None,
|
|
106
|
-
read_default_file: Optional[str] = None,
|
|
107
|
-
read_default_group: Optional[str] = None,
|
|
108
|
-
autocommit: Optional[bool] = None,
|
|
109
|
-
local_infile: Optional[bool] = None,
|
|
110
|
-
ssl: Optional[Any] = None,
|
|
111
|
-
sql_mode: Optional[str] = None,
|
|
112
|
-
init_command: Optional[str] = None,
|
|
113
|
-
cursor_class: Optional[Union["type[Cursor]", "type[DictCursor]"]] = None,
|
|
114
|
-
# Pool parameters
|
|
115
|
-
minsize: Optional[int] = None,
|
|
116
|
-
maxsize: Optional[int] = None,
|
|
117
|
-
echo: Optional[bool] = None,
|
|
118
|
-
pool_recycle: Optional[int] = None,
|
|
119
|
-
pool_instance: Optional["Pool"] = None,
|
|
120
|
-
**kwargs: Any,
|
|
68
|
+
*,
|
|
69
|
+
pool_config: "Optional[Union[AsyncmyPoolParams, dict[str, Any]]]" = None,
|
|
70
|
+
pool_instance: "Optional[Pool]" = None,
|
|
71
|
+
migration_config: Optional[dict[str, Any]] = None,
|
|
72
|
+
statement_config: "Optional[StatementConfig]" = None,
|
|
121
73
|
) -> None:
|
|
122
74
|
"""Initialize Asyncmy configuration.
|
|
123
75
|
|
|
124
76
|
Args:
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
password: The password used to authenticate with the database
|
|
130
|
-
database: The database name to use
|
|
131
|
-
port: The TCP/IP port of the MySQL server
|
|
132
|
-
unix_socket: The location of the Unix socket file
|
|
133
|
-
charset: The character set to use for the connection
|
|
134
|
-
connect_timeout: Timeout before throwing an error when connecting
|
|
135
|
-
read_default_file: MySQL configuration file to read
|
|
136
|
-
read_default_group: Group to read from the configuration file
|
|
137
|
-
autocommit: If True, autocommit mode will be enabled
|
|
138
|
-
local_infile: If True, enables LOAD LOCAL INFILE
|
|
139
|
-
ssl: SSL connection parameters or boolean
|
|
140
|
-
sql_mode: Default SQL_MODE to use
|
|
141
|
-
init_command: Initial SQL statement to execute once connected
|
|
142
|
-
cursor_class: Custom cursor class to use
|
|
143
|
-
minsize: Minimum number of connections to keep in the pool
|
|
144
|
-
maxsize: Maximum number of connections allowed in the pool
|
|
145
|
-
echo: If True, logging will be enabled for all SQL statements
|
|
146
|
-
pool_recycle: Number of seconds after which a connection is recycled
|
|
147
|
-
pool_instance: Existing connection pool instance to use
|
|
148
|
-
**kwargs: Additional parameters (stored in extras)
|
|
149
|
-
"""
|
|
150
|
-
# Store connection parameters as instance attributes
|
|
151
|
-
self.host = host
|
|
152
|
-
self.user = user
|
|
153
|
-
self.password = password
|
|
154
|
-
self.database = database
|
|
155
|
-
self.port = port
|
|
156
|
-
self.unix_socket = unix_socket
|
|
157
|
-
self.charset = charset
|
|
158
|
-
self.connect_timeout = connect_timeout
|
|
159
|
-
self.read_default_file = read_default_file
|
|
160
|
-
self.read_default_group = read_default_group
|
|
161
|
-
self.autocommit = autocommit
|
|
162
|
-
self.local_infile = local_infile
|
|
163
|
-
self.ssl = ssl
|
|
164
|
-
self.sql_mode = sql_mode
|
|
165
|
-
self.init_command = init_command
|
|
166
|
-
self.cursor_class = cursor_class
|
|
167
|
-
|
|
168
|
-
# Store pool parameters as instance attributes
|
|
169
|
-
self.minsize = minsize
|
|
170
|
-
self.maxsize = maxsize
|
|
171
|
-
self.echo = echo
|
|
172
|
-
self.pool_recycle = pool_recycle
|
|
173
|
-
self.extras = kwargs or {}
|
|
174
|
-
|
|
175
|
-
# Store other config
|
|
176
|
-
self.statement_config = statement_config or SQLConfig()
|
|
177
|
-
self.default_row_type = default_row_type
|
|
178
|
-
self.pool_instance: Optional[Pool] = pool_instance
|
|
179
|
-
self._dialect: DialectType = None
|
|
180
|
-
|
|
181
|
-
super().__init__() # pyright: ignore
|
|
182
|
-
|
|
183
|
-
@property
|
|
184
|
-
def connection_config_dict(self) -> dict[str, Any]:
|
|
185
|
-
"""Return the connection configuration as a dict for asyncmy.connect().
|
|
186
|
-
|
|
187
|
-
This method filters out pool-specific parameters that are not valid for asyncmy.connect().
|
|
188
|
-
"""
|
|
189
|
-
# Gather non-None connection parameters
|
|
190
|
-
config = {
|
|
191
|
-
field: getattr(self, field)
|
|
192
|
-
for field in CONNECTION_FIELDS
|
|
193
|
-
if getattr(self, field, None) is not None and getattr(self, field) is not Empty
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
config.update(self.extras)
|
|
197
|
-
|
|
198
|
-
return config
|
|
199
|
-
|
|
200
|
-
@property
|
|
201
|
-
def pool_config_dict(self) -> dict[str, Any]:
|
|
202
|
-
"""Return the full pool configuration as a dict for asyncmy.create_pool().
|
|
203
|
-
|
|
204
|
-
Returns:
|
|
205
|
-
A dictionary containing all pool configuration parameters.
|
|
77
|
+
pool_config: Pool configuration parameters
|
|
78
|
+
pool_instance: Existing pool instance to use
|
|
79
|
+
migration_config: Migration configuration
|
|
80
|
+
statement_config: Statement configuration override
|
|
206
81
|
"""
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
82
|
+
processed_pool_config: dict[str, Any] = dict(pool_config) if pool_config else {}
|
|
83
|
+
if "extra" in processed_pool_config:
|
|
84
|
+
extras = processed_pool_config.pop("extra")
|
|
85
|
+
processed_pool_config.update(extras)
|
|
86
|
+
|
|
87
|
+
if "host" not in processed_pool_config:
|
|
88
|
+
processed_pool_config["host"] = "localhost"
|
|
89
|
+
if "port" not in processed_pool_config:
|
|
90
|
+
processed_pool_config["port"] = 3306
|
|
91
|
+
|
|
92
|
+
if statement_config is None:
|
|
93
|
+
statement_config = asyncmy_statement_config
|
|
94
|
+
|
|
95
|
+
super().__init__(
|
|
96
|
+
pool_config=processed_pool_config,
|
|
97
|
+
pool_instance=pool_instance,
|
|
98
|
+
migration_config=migration_config,
|
|
99
|
+
statement_config=statement_config,
|
|
100
|
+
driver_features={},
|
|
101
|
+
)
|
|
218
102
|
|
|
219
103
|
async def _create_pool(self) -> "Pool": # pyright: ignore
|
|
220
104
|
"""Create the actual async connection pool."""
|
|
221
|
-
return await asyncmy.create_pool(**self.
|
|
105
|
+
return await asyncmy.create_pool(**dict(self.pool_config))
|
|
222
106
|
|
|
223
107
|
async def _close_pool(self) -> None:
|
|
224
108
|
"""Close the actual async connection pool."""
|
|
@@ -252,28 +136,22 @@ class AsyncmyConfig(AsyncDatabaseConfig[AsyncmyConnection, "Pool", AsyncmyDriver
|
|
|
252
136
|
yield connection
|
|
253
137
|
|
|
254
138
|
@asynccontextmanager
|
|
255
|
-
async def provide_session(
|
|
139
|
+
async def provide_session(
|
|
140
|
+
self, *args: Any, statement_config: "Optional[StatementConfig]" = None, **kwargs: Any
|
|
141
|
+
) -> AsyncGenerator[AsyncmyDriver, None]:
|
|
256
142
|
"""Provide an async driver session context manager.
|
|
257
143
|
|
|
258
144
|
Args:
|
|
259
145
|
*args: Additional arguments.
|
|
146
|
+
statement_config: Optional statement configuration override.
|
|
260
147
|
**kwargs: Additional keyword arguments.
|
|
261
148
|
|
|
262
149
|
Yields:
|
|
263
150
|
An AsyncmyDriver instance.
|
|
264
151
|
"""
|
|
265
152
|
async with self.provide_connection(*args, **kwargs) as connection:
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if statement_config.allowed_parameter_styles is None:
|
|
269
|
-
from dataclasses import replace
|
|
270
|
-
|
|
271
|
-
statement_config = replace(
|
|
272
|
-
statement_config,
|
|
273
|
-
allowed_parameter_styles=self.supported_parameter_styles,
|
|
274
|
-
target_parameter_style=self.preferred_parameter_style,
|
|
275
|
-
)
|
|
276
|
-
yield self.driver_type(connection=connection, config=statement_config)
|
|
153
|
+
final_statement_config = statement_config or asyncmy_statement_config
|
|
154
|
+
yield self.driver_type(connection=connection, statement_config=final_statement_config)
|
|
277
155
|
|
|
278
156
|
async def provide_pool(self, *args: Any, **kwargs: Any) -> "Pool": # pyright: ignore
|
|
279
157
|
"""Provide async pool instance.
|
|
@@ -294,6 +172,9 @@ class AsyncmyConfig(AsyncDatabaseConfig[AsyncmyConnection, "Pool", AsyncmyDriver
|
|
|
294
172
|
Returns:
|
|
295
173
|
Dictionary mapping type names to types.
|
|
296
174
|
"""
|
|
175
|
+
|
|
297
176
|
namespace = super().get_signature_namespace()
|
|
298
|
-
namespace.update(
|
|
177
|
+
namespace.update(
|
|
178
|
+
{"AsyncmyConnection": AsyncmyConnection, "AsyncmyPool": AsyncmyPool, "AsyncmyCursor": AsyncmyCursor}
|
|
179
|
+
)
|
|
299
180
|
return namespace
|