Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
426fad10ed |
@@ -10,18 +10,18 @@ a sibling of the `mongo` lib. Class is **`PsqlDB`**.
|
|||||||
`requirements.txt`:
|
`requirements.txt`:
|
||||||
|
|
||||||
```
|
```
|
||||||
psql @ git+ssh://git@git.rethinkstudios.io/rethink-public/psql.git@v0.1.0
|
psql @ git+ssh://git@git.rethinkstudios.io/rethink-public/psql.git@v0.1.1
|
||||||
```
|
```
|
||||||
|
|
||||||
Direct:
|
Direct:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "psql @ git+ssh://git@git.rethinkstudios.io/rethink-public/psql.git@v0.1.0"
|
pip install "psql @ git+ssh://git@git.rethinkstudios.io/rethink-public/psql.git@v0.1.1"
|
||||||
```
|
```
|
||||||
|
|
||||||
Pulls `asyncpg`.
|
Pulls `asyncpg`.
|
||||||
|
|
||||||
Drop the `@v0.1.0` suffix from the line above to install the latest unpinned.
|
Drop the `@v0.1.1` suffix from the line above to install the latest unpinned.
|
||||||
|
|
||||||
## The two-layer API
|
## The two-layer API
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "psql"
|
name = "psql"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
description = "async postgres wrapper over asyncpg: two-layer API (friendly verbs + raw escape hatch), fail-loud, config-free"
|
description = "async postgres wrapper over asyncpg: two-layer API (friendly verbs + raw escape hatch), fail-loud, config-free"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
@@ -338,8 +338,16 @@ class _Transaction:
|
|||||||
|
|
||||||
async def __aenter__(self):
|
async def __aenter__(self):
|
||||||
self._conn = await self._pool.acquire()
|
self._conn = await self._pool.acquire()
|
||||||
|
try:
|
||||||
self._tx = self._conn.transaction()
|
self._tx = self._conn.transaction()
|
||||||
await self._tx.start()
|
await self._tx.start()
|
||||||
|
except BaseException:
|
||||||
|
# start() (or transaction()) failing after acquire would otherwise leak the
|
||||||
|
# pooled connection — __aexit__ is not called when __aenter__ raises. release
|
||||||
|
# it and reset so a failed transaction start never burns a pool slot.
|
||||||
|
await self._pool.release(self._conn)
|
||||||
|
self._conn = None
|
||||||
|
raise
|
||||||
return self._conn
|
return self._conn
|
||||||
|
|
||||||
async def __aexit__(self, exc_type, exc, tb) -> None:
|
async def __aexit__(self, exc_type, exc, tb) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user