Skip to content

Commit 18d7d60

Browse files
authored
Improve pool documentation examples
I think pool documentation should recommend the safest approaches first (i.e. with the fewest possible mistakes), and discourage lower-level approach.
1 parent c7c0007 commit 18d7d60

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

asyncpg/pool.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,14 +789,23 @@ def create_pool(dsn=None, *,
789789
790790
Can be used either with an ``async with`` block:
791791
792+
.. code-block:: python
793+
794+
async with asyncpg.create_pool(user='postgres',
795+
command_timeout=60) as pool:
796+
await pool.fetch('SELECT 1')
797+
798+
Or to perform multiple operations on a single connection:
799+
792800
.. code-block:: python
793801
794802
async with asyncpg.create_pool(user='postgres',
795803
command_timeout=60) as pool:
796804
async with pool.acquire() as con:
805+
await con.execute('CREATE TABLE names (id serial PRIMARY KEY, name VARCHAR (255) NOT NULL)')
797806
await con.fetch('SELECT 1')
798807
799-
Or directly with ``await``:
808+
Or directly with ``await`` (not recommended):
800809
801810
.. code-block:: python
802811

0 commit comments

Comments
 (0)