@@ -15,51 +15,10 @@ API Reference
15
15
Connection
16
16
==========
17
17
18
- .. coroutinefunction :: connect(dsn=None, *, host=None, port=None, \
19
- user=None, password=None, \
20
- database=None, loop=None, timeout=60, \
21
- statement_cache_size=100, \
22
- command_timeout=None, \
23
- **opts)
18
+ .. autofunction :: asyncpg.connection.connect
24
19
25
- Establish a connection to a PostgreSQL server and return a new
26
- :class: `~asyncpg.connection.Connection ` object.
27
20
28
- :param dsn: Connection arguments specified using as a single string in the
29
- following format:
30
- ``postgres://user:pass@host:port/database?option=value ``
31
-
32
- :param host: database host address or a path to the directory containing
33
- database server UNIX socket (defaults to the default UNIX
34
- socket, or the value of the ``PGHOST `` environment variable,
35
- if set).
36
-
37
- :param port: connection port number (defaults to ``5432 ``, or the value of
38
- the ``PGPORT `` environment variable, if set)
39
-
40
- :param user: the name of the database role used for authentication
41
- (defaults to the name of the effective user of the process
42
- making the connection, or the value of ``PGUSER `` environment
43
- variable, if set)
44
-
45
- :param password: password used for authentication
46
-
47
- :param loop: An asyncio event loop instance. If ``None ``, the default
48
- event loop will be used.
49
-
50
- :param float timeout: connection timeout (in seconds, defaults to 60
51
- seconds).
52
-
53
- :param float statement_timeout: the default timeout for operations on
54
- this connection (the default is no timeout).
55
-
56
- :param int statement_cache_size: the size of prepared statement LRU cache
57
- (defaults to 100).
58
-
59
- :returns: :class: `~asyncpg.connection.Connection ` instance.
60
-
61
-
62
- .. autoclass :: asyncpg.connection.Connection()
21
+ .. autoclass :: asyncpg.connection.Connection
63
22
:members:
64
23
65
24
@@ -149,6 +108,10 @@ Alternatively, transactions can be used without an ``async with`` block:
149
108
await tr.commit()
150
109
151
110
111
+ See also the
112
+ :meth: `Connection.transaction() <asyncpg.connection.Connection.transaction> `
113
+ function.
114
+
152
115
.. _savepoint : https://www.postgresql.org/docs/current/static/sql-savepoint.html
153
116
154
117
@@ -233,15 +196,15 @@ It's also possible to create cursors from prepared statements:
233
196
.. note ::
234
197
235
198
Cursors created by a call to
236
- :meth: `Conection .cursor() <asyncpg.connection.Connection.cursor> ` or
199
+ :meth: `Connection .cursor() <asyncpg.connection.Connection.cursor> ` or
237
200
:meth: `PreparedStatement.cursor() <asyncpg.prepared_stmt.PreparedStatement.cursor> `
238
201
are *non-scrollable *: they can only be read forwards. To create a scrollable
239
202
cursor, use the ``DECLARE ... SCROLL CURSOR `` SQL statement directly.
240
203
241
204
.. warning ::
242
205
243
206
Cursors created by a call to
244
- :meth: `Conection .cursor() <asyncpg.connection.Connection.cursor> ` or
207
+ :meth: `Connection .cursor() <asyncpg.connection.Connection.cursor> ` or
245
208
:meth: `PreparedStatement.cursor() <asyncpg.prepared_stmt.PreparedStatement.cursor> `
246
209
cannot be used outside of a transaction. Any such attempt will result in
247
210
:exc: `~asyncpg.exceptions.InterfaceError `.
@@ -268,6 +231,18 @@ It's also possible to create cursors from prepared statements:
268
231
:members:
269
232
270
233
234
+ .. _asyncpg-api-pool :
235
+
236
+ Connection Pool
237
+ ===============
238
+
239
+ .. autofunction :: asyncpg.pool.create_pool
240
+
241
+
242
+ .. autoclass :: asyncpg.pool.Pool()
243
+ :members:
244
+
245
+
271
246
.. _asyncpg-api-record :
272
247
273
248
Record Objects
@@ -284,9 +259,14 @@ of values either by a numeric index or by a field name:
284
259
>>> import asyncio
285
260
>>> loop = asyncio.get_event_loop()
286
261
>>> conn = loop.run_until_complete(asyncpg.connect())
287
- >>> loop.run_until_complete(conn.fetchrow('''
262
+ >>> r = loop.run_until_complete(conn.fetchrow('''
288
263
... SELECT oid, rolname, rolsuper FROM pg_roles WHERE rolname = user'''))
264
+ >>> r
289
265
<Record oid=16388 rolname='elvis' rolsuper=True>
266
+ >>> r['oid']
267
+ 16388
268
+ >>> r[0]
269
+ 16388
290
270
291
271
292
272
.. class :: Record()
0 commit comments