Represent a single result row. The :class:`.Row` object represents a row of a database result. It is typically associated in the 1.x series of SQLAlchemy with the :class:`_engine.CursorResult` object, however is also used by the ORM for tuple-like results as of SQLAlchemy 1.4.
| 44 | |
| 45 | |
| 46 | class Row(BaseRow, _RowBase[Unpack[_Ts]], Generic[Unpack[_Ts]]): # type: ignore[misc] # noqa: E501 |
| 47 | """Represent a single result row. |
| 48 | |
| 49 | The :class:`.Row` object represents a row of a database result. It is |
| 50 | typically associated in the 1.x series of SQLAlchemy with the |
| 51 | :class:`_engine.CursorResult` object, however is also used by the ORM for |
| 52 | tuple-like results as of SQLAlchemy 1.4. |
| 53 | |
| 54 | The :class:`.Row` object seeks to act as much like a Python named |
| 55 | tuple as possible. For mapping (i.e. dictionary) behavior on a row, |
| 56 | such as testing for containment of keys, refer to the :attr:`.Row._mapping` |
| 57 | attribute. |
| 58 | |
| 59 | .. seealso:: |
| 60 | |
| 61 | :ref:`tutorial_selecting_data` - includes examples of selecting |
| 62 | rows from SELECT statements. |
| 63 | |
| 64 | .. versionchanged:: 1.4 |
| 65 | |
| 66 | Renamed ``RowProxy`` to :class:`.Row`. :class:`.Row` is no longer a |
| 67 | "proxy" object in that it contains the final form of data within it, |
| 68 | and now acts mostly like a named tuple. Mapping-like functionality is |
| 69 | moved to the :attr:`.Row._mapping` attribute. See |
| 70 | :ref:`change_4710_core` for background on this change. |
| 71 | |
| 72 | """ |
| 73 | |
| 74 | __slots__ = () |
| 75 | |
| 76 | @deprecated( |
| 77 | "2.1.0", |
| 78 | "The :meth:`.Row._tuple` method is deprecated, :class:`.Row` " |
| 79 | "now behaves like a tuple and can unpack types directly.", |
| 80 | ) |
| 81 | def _tuple(self) -> Tuple[Unpack[_Ts]]: |
| 82 | """Return a 'tuple' form of this :class:`.Row`. |
| 83 | |
| 84 | At runtime, this method returns "self"; the :class:`.Row` object is |
| 85 | already a named tuple. However, at the typing level, if this |
| 86 | :class:`.Row` is typed, the "tuple" return type will be a :pep:`484` |
| 87 | ``Tuple`` datatype that contains typing information about individual |
| 88 | elements, supporting typed unpacking and attribute access. |
| 89 | |
| 90 | .. versionadded:: 2.0.19 - The :meth:`.Row._tuple` method supersedes |
| 91 | the previous :meth:`.Row.tuple` method, which is now underscored |
| 92 | to avoid name conflicts with column names in the same way as other |
| 93 | named-tuple methods on :class:`.Row`. |
| 94 | |
| 95 | .. seealso:: |
| 96 | |
| 97 | :ref:`change_10635` - describes a migration path from this |
| 98 | workaround for SQLAlchemy 2.1. |
| 99 | |
| 100 | :attr:`.Row._t` - shorthand attribute notation |
| 101 | |
| 102 | :meth:`.Result.tuples` |
| 103 |
no outgoing calls