Skip to content

Commit 773b110

Browse files
committed
Added some docs to README
1 parent 295e369 commit 773b110

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ async def main() -> None:
506506

507507
await transaction.begin()
508508
# Create new savepoint
509-
cursor = await transaction.cursor(
509+
cursor = transaction.cursor(
510510
querystring="SELECT * FROM users WHERE username = $1",
511511
parameters=["SomeUserName"],
512512
fetch_number=100,
@@ -525,6 +525,32 @@ async def main() -> None:
525525
await transaction.commit()
526526
```
527527

528+
### Cursor as an async context manager
529+
```python
530+
from typing import Any
531+
532+
from psqlpy import PSQLPool, IsolationLevel, QueryResult, Transaction, Cursor
533+
534+
535+
db_pool = PSQLPool()
536+
537+
538+
async def main() -> None:
539+
await db_pool.startup()
540+
541+
connection = await db_pool.connection()
542+
transaction: Transaction
543+
cursor: Cursor
544+
async with connection.transaction() as transaction:
545+
async with transaction.cursor(
546+
querystring="SELECT * FROM users WHERE username = $1",
547+
parameters=["SomeUserName"],
548+
fetch_number=100,
549+
) as cursor:
550+
async for fetched_result in cursor:
551+
print(fetched_result.result())
552+
```
553+
528554
### Cursor operations
529555

530556
Available cursor operations:

0 commit comments

Comments
 (0)