Skip to content

Commit

Permalink
Improve pool documentation examples (#491)
Browse files Browse the repository at this point in the history
I think pool documentation should recommend the safest approaches first (i.e. with the fewest possible mistakes), and discourage lower-level approach.
  • Loading branch information
nyurik committed Jul 18, 2020
1 parent ac6a2fc commit 745f8f8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion asyncpg/pool.py
Expand Up @@ -798,14 +798,27 @@ def create_pool(dsn=None, *,
Can be used either with an ``async with`` block:
.. code-block:: python
async with asyncpg.create_pool(user='postgres',
command_timeout=60) as pool:
await pool.fetch('SELECT 1')
Or to perform multiple operations on a single connection:
.. code-block:: python
async with asyncpg.create_pool(user='postgres',
command_timeout=60) as pool:
async with pool.acquire() as con:
await con.execute('''
CREATE TABLE names (
id serial PRIMARY KEY,
name VARCHAR (255) NOT NULL)
''')
await con.fetch('SELECT 1')
Or directly with ``await``:
Or directly with ``await`` (not recommended):
.. code-block:: python
Expand Down

0 comments on commit 745f8f8

Please sign in to comment.