r"""Create a connection pool. 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 mul
(dsn=None, *,
init_size=None,
min_size=10,
max_size=10,
max_queries=50000,
max_inactive_connection_lifetime=300.0,
connect=None,
setup=None,
init=None,
reset=None,
loop=None,
connection_class=connection.Connection,
record_class=protocol.Record,
**connect_kwargs)
| 1199 | |
| 1200 | |
| 1201 | def create_pool(dsn=None, *, |
| 1202 | init_size=None, |
| 1203 | min_size=10, |
| 1204 | max_size=10, |
| 1205 | max_queries=50000, |
| 1206 | max_inactive_connection_lifetime=300.0, |
| 1207 | connect=None, |
| 1208 | setup=None, |
| 1209 | init=None, |
| 1210 | reset=None, |
| 1211 | loop=None, |
| 1212 | connection_class=connection.Connection, |
| 1213 | record_class=protocol.Record, |
| 1214 | **connect_kwargs): |
| 1215 | r"""Create a connection pool. |
| 1216 | |
| 1217 | Can be used either with an ``async with`` block: |
| 1218 | |
| 1219 | .. code-block:: python |
| 1220 | |
| 1221 | async with asyncpg.create_pool(user='postgres', |
| 1222 | command_timeout=60) as pool: |
| 1223 | await pool.fetch('SELECT 1') |
| 1224 | |
| 1225 | Or to perform multiple operations on a single connection: |
| 1226 | |
| 1227 | .. code-block:: python |
| 1228 | |
| 1229 | async with asyncpg.create_pool(user='postgres', |
| 1230 | command_timeout=60) as pool: |
| 1231 | async with pool.acquire() as con: |
| 1232 | await con.execute(''' |
| 1233 | CREATE TABLE names ( |
| 1234 | id serial PRIMARY KEY, |
| 1235 | name VARCHAR (255) NOT NULL) |
| 1236 | ''') |
| 1237 | await con.fetch('SELECT 1') |
| 1238 | |
| 1239 | Or directly with ``await`` (not recommended): |
| 1240 | |
| 1241 | .. code-block:: python |
| 1242 | |
| 1243 | pool = await asyncpg.create_pool(user='postgres', command_timeout=60) |
| 1244 | con = await pool.acquire() |
| 1245 | try: |
| 1246 | await con.fetch('SELECT 1') |
| 1247 | finally: |
| 1248 | await pool.release(con) |
| 1249 | |
| 1250 | .. warning:: |
| 1251 | Prepared statements and cursors returned by |
| 1252 | :meth:`Connection.prepare() <asyncpg.connection.Connection.prepare>` |
| 1253 | and :meth:`Connection.cursor() <asyncpg.connection.Connection.cursor>` |
| 1254 | become invalid once the connection is released. Likewise, all |
| 1255 | notification and log listeners are removed, and ``asyncpg`` will |
| 1256 | issue a warning if there are any listener callbacks registered on a |
| 1257 | connection that is being released to the pool. |
| 1258 |