From 18d7d609194b104ba679d46da156ef5683056f19 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 25 Oct 2019 14:15:29 -0400 Subject: [PATCH 1/4] 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. --- asyncpg/pool.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/asyncpg/pool.py b/asyncpg/pool.py index 64f4071e..951907e6 100644 --- a/asyncpg/pool.py +++ b/asyncpg/pool.py @@ -789,14 +789,23 @@ 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 From 73e717e6e698626cd2c9e4d32844e1b1a7f1d583 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 19 Nov 2019 15:54:01 -0500 Subject: [PATCH 2/4] line len fix --- asyncpg/pool.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/asyncpg/pool.py b/asyncpg/pool.py index 951907e6..d9a4d6f1 100644 --- a/asyncpg/pool.py +++ b/asyncpg/pool.py @@ -802,7 +802,9 @@ def create_pool(dsn=None, *, 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.execute('CREATE TABLE \ + names (id serial PRIMARY KEY, \ + name VARCHAR (255) NOT NULL)') await con.fetch('SELECT 1') Or directly with ``await`` (not recommended): From 5211617908e82aa21983df870c7d6ec1f993bac3 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 17 Jul 2020 21:37:49 -0400 Subject: [PATCH 3/4] Update pool.py --- asyncpg/pool.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/asyncpg/pool.py b/asyncpg/pool.py index d9a4d6f1..9cbb65ae 100644 --- a/asyncpg/pool.py +++ b/asyncpg/pool.py @@ -802,9 +802,11 @@ def create_pool(dsn=None, *, 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.execute(""" +CREATE TABLE names ( + id serial PRIMARY KEY, + name VARCHAR (255) NOT NULL) + """) await con.fetch('SELECT 1') Or directly with ``await`` (not recommended): From 270bc4c537d3b64e742dc4fffeed5cf4f45bb1f3 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 18 Jul 2020 00:16:42 -0400 Subject: [PATCH 4/4] Update pool.py --- asyncpg/pool.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/asyncpg/pool.py b/asyncpg/pool.py index 9979d181..ec42f816 100644 --- a/asyncpg/pool.py +++ b/asyncpg/pool.py @@ -811,11 +811,11 @@ def create_pool(dsn=None, *, 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.execute(''' + CREATE TABLE names ( + id serial PRIMARY KEY, + name VARCHAR (255) NOT NULL) + ''') await con.fetch('SELECT 1') Or directly with ``await`` (not recommended):