MCPcopy Index your code
hub / github.com/MagicStack/asyncpg / Cursor

Class Cursor

asyncpg/cursor.py:250–323  ·  view source on GitHub ↗

An open *portal* into the results of a query.

Source from the content-addressed store, hash-verified

248
249
250class Cursor(BaseCursor):
251 """An open *portal* into the results of a query."""
252
253 __slots__ = ()
254
255 async def _init(self, timeout):
256 if self._state is None:
257 self._state = await self._connection._get_statement(
258 self._query,
259 timeout,
260 named=True,
261 record_class=self._record_class,
262 )
263 self._state.attach()
264 self._check_ready()
265 await self._bind(timeout)
266 return self
267
268 @connresource.guarded
269 async def fetch(self, n, *, timeout=None):
270 r"""Return the next *n* rows as a list of :class:`Record` objects.
271
272 :param float timeout: Optional timeout value in seconds.
273
274 :return: A list of :class:`Record` instances.
275 """
276 self._check_ready()
277 if n <= 0:
278 raise exceptions.InterfaceError('n must be greater than zero')
279 if self._exhausted:
280 return []
281 recs = await self._exec(n, timeout)
282 if len(recs) < n:
283 self._exhausted = True
284 return recs
285
286 @connresource.guarded
287 async def fetchrow(self, *, timeout=None):
288 r"""Return the next row.
289
290 :param float timeout: Optional timeout value in seconds.
291
292 :return: A :class:`Record` instance.
293 """
294 self._check_ready()
295 if self._exhausted:
296 return None
297 recs = await self._exec(1, timeout)
298 if len(recs) < 1:
299 self._exhausted = True
300 return None
301 return recs[0]
302
303 @connresource.guarded
304 async def forward(self, n, *, timeout=None) -> int:
305 r"""Skip over the next *n* rows.
306
307 :param float timeout: Optional timeout value in seconds.

Callers 1

__await__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…