callable (formally the `~psycopg3.rows.RowMaker` protocol) accepting a
`values` tuple and returning a row in the desired form.
-.. autoclass:: psycopg3.rows.RowMaker
+.. autoclass:: psycopg3.rows.RowMaker()
- .. automethod:: __call__
+ .. method:: __call__(values: Sequence[Any]) -> Row
-.. autoclass:: psycopg3.rows.RowFactory
+ Convert a sequence of values from the database to a finished object.
+
+
+.. autoclass:: psycopg3.rows.RowFactory()
+
+ .. method:: __call__(cursor: AnyCursor[Row]) -> RowMaker[Row]
+
+ Inspect the result on a cursor and return a `RowMaker` to convert rows.
+
+ `!AnyCursor` may be either a `~psycopg3.Cursor` or an
+ `~psycopg3.AsyncCursor`.
- .. automethod:: __call__
`~RowFactory` objects can be implemented as a class, for instance:
.. currentmodule:: psycopg3.rows
-.. autofunction:: tuple_row
+.. autofunction:: tuple_row(cursor: AnyCursor[TupleRow])
.. autodata:: TupleRow
-.. autofunction:: dict_row
+.. autofunction:: dict_row(cursor: AnyCursor[DictRow])
.. autodata:: DictRow
-.. autofunction:: namedtuple_row
+.. autofunction:: namedtuple_row(cursor: AnyCursor[NamedTuple])
Use with a static analyzer
program would like to receive: by default (`tuple_row()`) it is a simple
tuple, but it may be any type of object.
- Typically, `~RowMaker` functions are returned by `RowFactory`.
+ Typically, `!RowMaker` functions are returned by `RowFactory`.
"""
def __call__(self, __values: Sequence[Any]) -> Row_co:
- """
- Convert a sequence of values from the database to a finished object.
- """
...
"""
def __call__(self, __cursor: "AnyCursor[Row]") -> RowMaker[Row]:
- """
- Inspect the result on a cursor and return a `RowMaker` to convert rows.
- """
...
This is the default factory.
+ :param cursor: The cursor where the rows are read.
:rtype: `RowMaker`\ [`TupleRow`]
"""
# Implementation detail: make sure this is the tuple type itself, not an
Note that this is not compatible with the DBAPI, which expects the records
to be sequences.
+ :param cursor: The cursor where the rows are read.
:rtype: `RowMaker`\ [`DictRow`]
"""
) -> Callable[[Sequence[Any]], NamedTuple]:
r"""Row factory to represent rows as `~collections.namedtuple`.
+ :param cursor: The cursor where the rows are read.
:rtype: `RowMaker`\ [`NamedTuple`]
"""