@@ -756,6 +756,44 @@ async def fetchrow(
756756 return None
757757 return data [0 ]
758758
759+ async def fetchmany (
760+ self , query , args , * , timeout : float = None , record_class = None
761+ ):
762+ """Run a query for each sequence of arguments in *args*
763+ and return the results as a list of :class:`Record`.
764+
765+ :param query:
766+ Query to execute.
767+ :param args:
768+ An iterable containing sequences of arguments for the query.
769+ :param float timeout:
770+ Optional timeout value in seconds.
771+ :param type record_class:
772+ If specified, the class to use for records returned by this method.
773+ Must be a subclass of :class:`~asyncpg.Record`. If not specified,
774+ a per-connection *record_class* is used.
775+
776+ :return list:
777+ A list of :class:`~asyncpg.Record` instances. If specified, the
778+ actual type of list elements would be *record_class*.
779+
780+ Example:
781+
782+ .. code-block:: pycon
783+
784+ >>> rows = await con.fetchmany('''
785+ ... INSERT INTO mytab (a, b) VALUES ($1, $2) RETURNING a;
786+ ... ''', [('x', 1), ('y', 2), ('z', 3)])
787+ >>> rows
788+ [<Record row=('x',)>, <Record row=('y',)>, <Record row=('z',)>]
789+
790+ .. versionadded:: 0.30.0
791+ """
792+ self ._check_open ()
793+ return await self ._executemany (
794+ query , args , timeout , return_rows = True , record_class = record_class
795+ )
796+
759797 async def copy_from_table (self , table_name , * , output ,
760798 columns = None , schema_name = None , timeout = None ,
761799 format = None , oids = None , delimiter = None ,
@@ -1896,17 +1934,27 @@ async def __execute(
18961934 )
18971935 return result , stmt
18981936
1899- async def _executemany (self , query , args , timeout ):
1937+ async def _executemany (
1938+ self ,
1939+ query ,
1940+ args ,
1941+ timeout ,
1942+ return_rows = False ,
1943+ record_class = None ,
1944+ ):
19001945 executor = lambda stmt , timeout : self ._protocol .bind_execute_many (
19011946 state = stmt ,
19021947 args = args ,
19031948 portal_name = '' ,
19041949 timeout = timeout ,
1950+ return_rows = return_rows ,
19051951 )
19061952 timeout = self ._protocol ._get_timeout (timeout )
19071953 with self ._stmt_exclusive_section :
19081954 with self ._time_and_log (query , args , timeout ):
1909- result , _ = await self ._do_execute (query , executor , timeout )
1955+ result , _ = await self ._do_execute (
1956+ query , executor , timeout , record_class = record_class
1957+ )
19101958 return result
19111959
19121960 async def _do_execute (
0 commit comments