]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
docs: add docstrings from sync cursor to async
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 19 Aug 2023 17:19:48 +0000 (18:19 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 11 Oct 2023 21:45:38 +0000 (23:45 +0200)
psycopg/psycopg/cursor_async.py

index 5289bb62a492840119ee336ec5e95c0e9ec83bbf..2589aefcabb56d044279d9d9d0121006ea030b33 100644 (file)
@@ -62,10 +62,14 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]):
         await self.close()
 
     async def close(self) -> None:
+        """
+        Close the current cursor and free associated resources.
+        """
         self._close()
 
     @property
     def row_factory(self) -> AsyncRowFactory[Row]:
+        """Writable attribute to control how result rows are formed."""
         return self._row_factory
 
     @row_factory.setter
@@ -85,6 +89,9 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]):
         prepare: Optional[bool] = None,
         binary: Optional[bool] = None,
     ) -> _Self:
+        """
+        Execute a query or command to the database.
+        """
         try:
             async with self._conn.lock:
                 await self._conn.wait(
@@ -101,6 +108,9 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]):
         *,
         returning: bool = False,
     ) -> None:
+        """
+        Execute the same command with a sequence of input data.
+        """
         try:
             if Pipeline.is_supported():
                 # If there is already a pipeline, ride it, in order to avoid
@@ -132,6 +142,9 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]):
         *,
         binary: Optional[bool] = None,
     ) -> AsyncIterator[Row]:
+        """
+        Iterate row-by-row on a result from the database.
+        """
         if self._pgconn.pipeline_status:
             raise e.ProgrammingError("stream() cannot be used in pipeline mode")
 
@@ -171,6 +184,13 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]):
                         pass
 
     async def fetchone(self) -> Optional[Row]:
+        """
+        Return the next record from the current recordset.
+
+        Return `!None` the recordset is finished.
+
+        :rtype: Optional[Row], with Row defined by `row_factory`
+        """
         await self._fetch_pipeline()
         self._check_result_for_fetch()
         record = self._tx.load_row(self._pos, self._make_row)
@@ -179,6 +199,13 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]):
         return record
 
     async def fetchmany(self, size: int = 0) -> List[Row]:
+        """
+        Return the next `!size` records from the current recordset.
+
+        `!size` default to `!self.arraysize` if not specified.
+
+        :rtype: Sequence[Row], with Row defined by `row_factory`
+        """
         await self._fetch_pipeline()
         self._check_result_for_fetch()
         assert self.pgresult
@@ -194,6 +221,11 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]):
         return records
 
     async def fetchall(self) -> List[Row]:
+        """
+        Return all the remaining records from the current recordset.
+
+        :rtype: Sequence[Row], with Row defined by `row_factory`
+        """
         await self._fetch_pipeline()
         self._check_result_for_fetch()
         assert self.pgresult
@@ -216,6 +248,16 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]):
             yield row
 
     async def scroll(self, value: int, mode: str = "relative") -> None:
+        """
+        Move the cursor in the result set to a new position according to mode.
+
+        If `!mode` is ``'relative'`` (default), `!value` is taken as offset to
+        the current position in the result set; if set to ``'absolute'``,
+        `!value` states an absolute target position.
+
+        Raise `!IndexError` in case a scroll operation would leave the result
+        set. In this case the position will not change.
+        """
         await self._fetch_pipeline()
         self._scroll(value, mode)
 
@@ -228,6 +270,8 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]):
         writer: Optional[AsyncCopyWriter] = None,
     ) -> AsyncIterator[AsyncCopy]:
         """
+        Initiate a :sql:`COPY` operation and return an object to manage it.
+
         :rtype: AsyncCopy
         """
         try:
@@ -239,6 +283,8 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]):
         except e._NO_TRACEBACK as ex:
             raise ex.with_traceback(None)
 
+        # If a fresher result has been set on the cursor by the Copy object,
+        # read its properties (especially rowcount).
         self._select_current_result(0)
 
     async def _fetch_pipeline(self) -> None: