From 745f8f817fc06115f96f8a376199d9bdfb556c44 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 18 Jul 2020 12:25:26 -0400 Subject: [PATCH] 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. --- asyncpg/pool.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/asyncpg/pool.py b/asyncpg/pool.py index 20a3234e..ec42f816 100644 --- a/asyncpg/pool.py +++ b/asyncpg/pool.py @@ -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