ddsql 0.2.0__tar.gz → 0.3.0__tar.gz
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.
- {ddsql-0.2.0 → ddsql-0.3.0}/PKG-INFO +6 -6
- {ddsql-0.2.0 → ddsql-0.3.0}/README.md +5 -5
- {ddsql-0.2.0 → ddsql-0.3.0}/ddsql/adapter.py +4 -4
- {ddsql-0.2.0 → ddsql-0.3.0}/ddsql/connections.py +6 -6
- {ddsql-0.2.0 → ddsql-0.3.0}/pyproject.toml +1 -1
- {ddsql-0.2.0 → ddsql-0.3.0}/pyproject.toml.orig +1 -1
- {ddsql-0.2.0 → ddsql-0.3.0}/LICENSE +0 -0
- {ddsql-0.2.0 → ddsql-0.3.0}/ddsql/__init__.py +0 -0
- {ddsql-0.2.0 → ddsql-0.3.0}/ddsql/py.typed +0 -0
- {ddsql-0.2.0 → ddsql-0.3.0}/ddsql/query.py +0 -0
- {ddsql-0.2.0 → ddsql-0.3.0}/ddsql/serializers/__init__.py +0 -0
- {ddsql-0.2.0 → ddsql-0.3.0}/ddsql/serializers/base.py +0 -0
- {ddsql-0.2.0 → ddsql-0.3.0}/ddsql/serializers/clickhouse.py +0 -0
- {ddsql-0.2.0 → ddsql-0.3.0}/ddsql/serializers/postgres.py +0 -0
- {ddsql-0.2.0 → ddsql-0.3.0}/ddsql/sqlbase.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ddsql
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: SQL Query Library
|
|
5
5
|
Keywords: python,ddsql
|
|
6
6
|
Author: davyddd
|
|
@@ -141,7 +141,7 @@ per task. The connections module adds two things on top:
|
|
|
141
141
|
|
|
142
142
|
- `ConnectionManagerFactory(registries, default, connection_manager_class=ConnectionManager)` resolves a
|
|
143
143
|
connection alias to its registry, like Django's `using`. Calling it opens a connection manager on the
|
|
144
|
-
chosen registry; `registry(
|
|
144
|
+
chosen registry; `registry(alias)` returns the registry itself.
|
|
145
145
|
- `ConnectionManager(registry)` is the default connection manager: an async context manager that hands out
|
|
146
146
|
the connection of the registry's current scope and releases nothing on exit. Enough for clients that are
|
|
147
147
|
pools themselves, such as ClickHouse.
|
|
@@ -177,7 +177,7 @@ async with clickhouse() as client:
|
|
|
177
177
|
atomic = ConnectionManagerFactory(session_registries, default=PostgresDB.PRIMARY, connection_manager_class=Atomic)
|
|
178
178
|
|
|
179
179
|
|
|
180
|
-
async with atomic(
|
|
180
|
+
async with atomic(alias=PostgresDB.REPLICA) as session:
|
|
181
181
|
...
|
|
182
182
|
```
|
|
183
183
|
|
|
@@ -202,7 +202,7 @@ class PostgresAdapter(Adapter):
|
|
|
202
202
|
serializer = PostgresSerializer()
|
|
203
203
|
|
|
204
204
|
async def _execute(self) -> Sequence[dict[str, Any]]:
|
|
205
|
-
async with atomic(
|
|
205
|
+
async with atomic(alias=self.alias) as session:
|
|
206
206
|
query = await self.get_query() # the rendered SQL query
|
|
207
207
|
result = await session.execute(text(query))
|
|
208
208
|
return [dict(zip(result.keys(), row)) for row in result.fetchall()]
|
|
@@ -213,8 +213,8 @@ adapters are validated.
|
|
|
213
213
|
|
|
214
214
|
### Choosing the database
|
|
215
215
|
|
|
216
|
-
`Adapter.using(
|
|
217
|
-
`self.
|
|
216
|
+
`Adapter.using(alias)` picks the connection alias right before executing, like Django's `using`. `_execute`
|
|
217
|
+
reads `self.alias` (`None` means the default) and passes it to whatever opens the connection, as in the example above:
|
|
218
218
|
|
|
219
219
|
```python
|
|
220
220
|
await SQL(query).postgres.execute() # default connection
|
|
@@ -121,7 +121,7 @@ per task. The connections module adds two things on top:
|
|
|
121
121
|
|
|
122
122
|
- `ConnectionManagerFactory(registries, default, connection_manager_class=ConnectionManager)` resolves a
|
|
123
123
|
connection alias to its registry, like Django's `using`. Calling it opens a connection manager on the
|
|
124
|
-
chosen registry; `registry(
|
|
124
|
+
chosen registry; `registry(alias)` returns the registry itself.
|
|
125
125
|
- `ConnectionManager(registry)` is the default connection manager: an async context manager that hands out
|
|
126
126
|
the connection of the registry's current scope and releases nothing on exit. Enough for clients that are
|
|
127
127
|
pools themselves, such as ClickHouse.
|
|
@@ -157,7 +157,7 @@ async with clickhouse() as client:
|
|
|
157
157
|
atomic = ConnectionManagerFactory(session_registries, default=PostgresDB.PRIMARY, connection_manager_class=Atomic)
|
|
158
158
|
|
|
159
159
|
|
|
160
|
-
async with atomic(
|
|
160
|
+
async with atomic(alias=PostgresDB.REPLICA) as session:
|
|
161
161
|
...
|
|
162
162
|
```
|
|
163
163
|
|
|
@@ -182,7 +182,7 @@ class PostgresAdapter(Adapter):
|
|
|
182
182
|
serializer = PostgresSerializer()
|
|
183
183
|
|
|
184
184
|
async def _execute(self) -> Sequence[dict[str, Any]]:
|
|
185
|
-
async with atomic(
|
|
185
|
+
async with atomic(alias=self.alias) as session:
|
|
186
186
|
query = await self.get_query() # the rendered SQL query
|
|
187
187
|
result = await session.execute(text(query))
|
|
188
188
|
return [dict(zip(result.keys(), row)) for row in result.fetchall()]
|
|
@@ -193,8 +193,8 @@ adapters are validated.
|
|
|
193
193
|
|
|
194
194
|
### Choosing the database
|
|
195
195
|
|
|
196
|
-
`Adapter.using(
|
|
197
|
-
`self.
|
|
196
|
+
`Adapter.using(alias)` picks the connection alias right before executing, like Django's `using`. `_execute`
|
|
197
|
+
reads `self.alias` (`None` means the default) and passes it to whatever opens the connection, as in the example above:
|
|
198
198
|
|
|
199
199
|
```python
|
|
200
200
|
await SQL(query).postgres.execute() # default connection
|
|
@@ -31,17 +31,17 @@ class Adapter(ABC):
|
|
|
31
31
|
|
|
32
32
|
def __init__(self, sql: SQLBase) -> None:
|
|
33
33
|
self.sql = sql
|
|
34
|
-
self.
|
|
34
|
+
self.alias: Hashable | None = None
|
|
35
35
|
|
|
36
|
-
def using(self,
|
|
36
|
+
def using(self, alias: Hashable) -> Self:
|
|
37
37
|
"""
|
|
38
|
-
Picks the
|
|
38
|
+
Picks the connection alias for this execution, like Django's `using`; `_execute` reads `self.alias`
|
|
39
39
|
(`None` = default) and passes it to whatever opens the connection:
|
|
40
40
|
|
|
41
41
|
await SQL(query).postgres.execute() # default connection
|
|
42
42
|
await SQL(query).postgres.using(PostgresDB.REPLICA).execute()
|
|
43
43
|
"""
|
|
44
|
-
self.
|
|
44
|
+
self.alias = alias
|
|
45
45
|
return self
|
|
46
46
|
|
|
47
47
|
async def get_query(self) -> str:
|
|
@@ -41,7 +41,7 @@ class ConnectionManagerFactory(Generic[ConnectionAliasT, ConnectionT, Connection
|
|
|
41
41
|
atomic = ConnectionManagerFactory(session_registries, default=PostgresDB.PRIMARY, connection_manager_class=Atomic)
|
|
42
42
|
|
|
43
43
|
async with clickhouse() as client: ...
|
|
44
|
-
async with atomic(
|
|
44
|
+
async with atomic(alias=PostgresDB.REPLICA) as session: ...
|
|
45
45
|
"""
|
|
46
46
|
|
|
47
47
|
def __init__(
|
|
@@ -56,15 +56,15 @@ class ConnectionManagerFactory(Generic[ConnectionAliasT, ConnectionT, Connection
|
|
|
56
56
|
self.default = default
|
|
57
57
|
self.connection_manager_class = connection_manager_class
|
|
58
58
|
|
|
59
|
-
def registry(self,
|
|
60
|
-
"""The registry of `
|
|
61
|
-
alias = self.default if
|
|
59
|
+
def registry(self, alias: Hashable | None = None) -> ScopedRegistry[ConnectionT]:
|
|
60
|
+
"""The registry of `alias`, or of the default connection; `Hashable` because `Adapter.alias` is untyped."""
|
|
61
|
+
alias = self.default if alias is None else alias
|
|
62
62
|
if alias not in self.registries:
|
|
63
63
|
raise KeyError(f'Unknown connection {alias!r}; expected one of {list(self.registries)!r}')
|
|
64
64
|
return self.registries[alias] # type: ignore[index]
|
|
65
65
|
|
|
66
|
-
def __call__(self,
|
|
67
|
-
return self.connection_manager_class(self.registry(
|
|
66
|
+
def __call__(self, alias: Hashable | None = None) -> ConnectionManagerT:
|
|
67
|
+
return self.connection_manager_class(self.registry(alias))
|
|
68
68
|
|
|
69
69
|
|
|
70
70
|
__all__ = ('ConnectionManager', 'ConnectionManagerFactory')
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|