Skip to content

Commit 745f8f8

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

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

asyncpg/pool.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -798,14 +798,27 @@ def create_pool(dsn=None, *,
798798
799799
Can be used either with an ``async with`` block:
800800
801+
.. code-block:: python
802+
803+
async with asyncpg.create_pool(user='postgres',
804+
command_timeout=60) as pool:
805+
await pool.fetch('SELECT 1')
806+
807+
Or to perform multiple operations on a single connection:
808+
801809
.. code-block:: python
802810
803811
async with asyncpg.create_pool(user='postgres',
804812
command_timeout=60) as pool:
805813
async with pool.acquire() as con:
814+
await con.execute('''
815+
CREATE TABLE names (
816+
id serial PRIMARY KEY,
817+
name VARCHAR (255) NOT NULL)
818+
''')
806819
await con.fetch('SELECT 1')
807820
808-
Or directly with ``await``:
821+
Or directly with ``await`` (not recommended):
809822
810823
.. code-block:: python
811824

0 commit comments

Comments
 (0)