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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ddsql
3
- Version: 0.2.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(using)` returns the registry itself.
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(using=PostgresDB.REPLICA) as session:
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(using=self.db) as session:
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(db)` picks the database right before executing, like Django's `using`. `_execute` reads
217
- `self.db` (`None` means the default) and passes it to whatever opens the connection, as in the example above:
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(using)` returns the registry itself.
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(using=PostgresDB.REPLICA) as session:
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(using=self.db) as session:
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(db)` picks the database right before executing, like Django's `using`. `_execute` reads
197
- `self.db` (`None` means the default) and passes it to whatever opens the connection, as in the example above:
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.db: Hashable | None = None
34
+ self.alias: Hashable | None = None
35
35
 
36
- def using(self, db: Hashable) -> Self:
36
+ def using(self, alias: Hashable) -> Self:
37
37
  """
38
- Picks the database for this execution, like Django's `using`; `_execute` reads `self.db`
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.db = db
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(using=PostgresDB.REPLICA) as session: ...
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, using: Hashable | None = None) -> ScopedRegistry[ConnectionT]:
60
- """The registry of `using`, or of the default connection; `Hashable` because `Adapter.db` is untyped."""
61
- alias = self.default if using is None else using
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, using: Hashable | None = None) -> ConnectionManagerT:
67
- return self.connection_manager_class(self.registry(using))
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')
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "ddsql"
3
3
  description = "SQL Query Library"
4
- version = "0.2.0"
4
+ version = "0.3.0"
5
5
  license = "MIT"
6
6
  license-files = ["LICENSE"]
7
7
  readme = "README.md"
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "ddsql"
3
3
  description = "SQL Query Library"
4
- version = "0.2.0"
4
+ version = "0.3.0"
5
5
  authors = [{ name = "davyddd" }]
6
6
  license = "MIT"
7
7
  license-files = ["LICENSE"]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes