From: Daniele Varrazzo Date: Sun, 23 Jun 2024 09:55:57 +0000 (+0200) Subject: docs(rows): add examples showing the rows returned by basic factories X-Git-Tag: 3.2.0~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f9546a217bf257feb6c7a3c4eed115d3e73171a;p=thirdparty%2Fpsycopg.git docs(rows): add examples showing the rows returned by basic factories --- diff --git a/docs/api/rows.rst b/docs/api/rows.rst index 15dfd3cad..0c9d1fb37 100644 --- a/docs/api/rows.rst +++ b/docs/api/rows.rst @@ -12,11 +12,38 @@ the basic tuples. Check out :ref:`row-factory-create` for information about how to use these objects. .. autofunction:: tuple_row + + Example:: + + >>> cur = conn.cursor(row_factory=tuple_row) + >>> cur.execute("SELECT 10 AS foo, 'hello' AS bar").fetchone() + (10, 'hello') + .. autofunction:: dict_row + + Example:: + + >>> cur = conn.cursor(row_factory=dict_row) + >>> cur.execute("SELECT 10 AS foo, 'hello' AS bar").fetchone() + {'foo': 10, 'bar': 'hello'} + .. autofunction:: namedtuple_row + + Example:: + + >>> cur = conn.cursor(row_factory=namedtuple_row) + >>> cur.execute("SELECT 10 AS foo, 'hello' AS bar").fetchone() + Row(foo=10, bar='hello') + .. autofunction:: scalar_row - .. versionadded:: 3.2 + Example:: + + >>> cur = conn.cursor(row_factory=scalar_row) + >>> cur.execute("SELECT 10 AS foo, 'hello' AS bar").fetchone() + 10 + + .. versionadded:: 3.2 .. autofunction:: class_row