@@ -104,16 +104,40 @@ def cursor(self, query, *args, prefetch=None, timeout=None):
104104 return cursor .CursorFactory (self , query , None , args , prefetch , timeout )
105105
106106 async def prepare (self , query , * , timeout = None ):
107+ """Create a *prepared statement* for the specified query.
108+
109+ :param str query: Text of the query to create a prepared statement for.
110+ :param int timeout: Optional timeout value in seconds.
111+
112+ :return: A :class:`PreparedStatement` instance.
113+ """
107114 stmt = await self ._get_statement (query , timeout )
108115 return prepared_stmt .PreparedStatement (self , query , stmt )
109116
110117 async def fetch (self , query , * args , timeout = None ):
118+ """Run a query and return the results as a list of :class:`Record`.
119+
120+ :param str query: Query text
121+ :param args: Query arguments
122+ :param int timeout: Optional timeout value in seconds.
123+
124+ :return: A list of :class:`Record` instances.
125+ """
111126 stmt = await self ._get_statement (query , timeout )
112127 protocol = self ._protocol
113128 data = await protocol .bind_execute (stmt , args , '' , 0 , False , timeout )
114129 return data
115130
116131 async def fetchval (self , query , * args , column = 0 , timeout = None ):
132+ """Run a query and return the value of the specified column of the first row.
133+
134+ :param str query: Query text
135+ :param args: Query arguments
136+ :param int timeout: Optional column index (defaults to 0).
137+ :param int timeout: Optional timeout value in seconds.
138+
139+ :return: The value of the specified column of the first record.
140+ """
117141 stmt = await self ._get_statement (query , timeout )
118142 protocol = self ._protocol
119143 data = await protocol .bind_execute (stmt , args , '' , 1 , False , timeout )
@@ -122,6 +146,14 @@ async def fetchval(self, query, *args, column=0, timeout=None):
122146 return data [0 ][column ]
123147
124148 async def fetchrow (self , query , * args , timeout = None ):
149+ """Run a query and return the first row.
150+
151+ :param str query: Query text
152+ :param args: Query arguments
153+ :param int timeout: Optional timeout value in seconds.
154+
155+ :return: The first row as a :class:`Record` instance.
156+ """
125157 stmt = await self ._get_statement (query , timeout )
126158 protocol = self ._protocol
127159 data = await protocol .bind_execute (stmt , args , '' , 1 , False , timeout )
@@ -191,9 +223,15 @@ async def set_builtin_type_codec(self, typename, *,
191223 oid , typename , schema , 'scalar' , codec_name )
192224
193225 def is_closed (self ):
226+ """Return ``True`` if the connection is closed, ``False`` otherwise.
227+
228+ :return bool: ``True`` if the connection is closed, ``False``
229+ otherwise.
230+ """
194231 return not self ._protocol .is_connected () or self ._aborted
195232
196233 async def close (self ):
234+ """Close the connection gracefully."""
197235 if self .is_closed ():
198236 return
199237 self ._close_stmts ()
@@ -202,6 +240,7 @@ async def close(self):
202240 await protocol .close ()
203241
204242 def terminate (self ):
243+ """Terminate the connection without waiting for pending data."""
205244 self ._close_stmts ()
206245 self ._aborted = True
207246 self ._protocol .abort ()
0 commit comments