class AsyncResult(_WithKeys, AsyncCommon[
An asyncio wrapper around a :class:`_result.Result` object. The :class:`_asyncio.AsyncResult` only applies to statement executions that use a server-side cursor. It is returned only from the :meth:`_asyncio.AsyncConnection.stream` and :meth:`_asyncio.AsyncSession.stream` methods. .. note:: As is the case with :class:`_engine.Result`, this object is used for ORM results returned by :meth:`_asyncio.AsyncSession.execute`, which can yield instances of ORM mapped objects either individually or within tuple-like rows. Note that these result objects do not deduplicate instances or rows automatically as is the case with the legacy :class:`_orm.Query` object. For in-Python de-duplication of instances or rows, use the :meth:`_asyncio.AsyncResult.unique` modifier method. .. versionadded:: 1.4
Method | __aiter__ |
Undocumented |
Async Method | __anext__ |
Undocumented |
Method | __init__ |
Undocumented |
Async Method | all |
Return all rows in a list. |
Method | columns |
Establish the columns that should be returned in each row. |
Async Method | fetchall |
A synonym for the :meth:`_asyncio.AsyncResult.all` method. |
Async Method | fetchmany |
Fetch many rows. |
Async Method | fetchone |
Fetch one row. |
Async Method | first |
Fetch the first row or ``None`` if no row is present. |
Async Method | freeze |
Return a callable object that will produce copies of this :class:`_asyncio.AsyncResult` when invoked. |
Method | mappings |
Apply a mappings filter to returned rows, returning an instance of :class:`_asyncio.AsyncMappingResult`. |
Async Method | one |
Return exactly one row or raise an exception. |
Async Method | one |
Return at most one result or raise an exception. |
Async Method | partitions |
Iterate through sub-lists of rows of the size given. |
Async Method | scalar |
Fetch the first column of the first row, and close the result set. |
Async Method | scalar |
Return exactly one scalar result or raise an exception. |
Async Method | scalar |
Return exactly one scalar result or ``None``. |
Method | scalars |
Return an :class:`_asyncio.AsyncScalarResult` filtering object which will return single elements rather than :class:`_row.Row` objects. |
Method | tuples |
Apply a "typed tuple" typing filter to returned rows. |
Method | unique |
Apply unique filtering to the objects returned by this :class:`_asyncio.AsyncResult`. |
Class Variable | __slots__ |
Undocumented |
Property | t |
Apply a "typed tuple" typing filter to returned rows. |
Instance Variable | _metadata |
Undocumented |
Instance Variable | _post |
Undocumented |
Instance Variable | _real |
Undocumented |
Instance Variable | _unique |
Undocumented |
Inherited from _WithKeys
:
Method | keys |
Return an iterable view which yields the string keys that would be represented by each :class:`_engine.Row`. |
Inherited from AsyncCommon
(via _WithKeys
):
Async Method | close |
Close this result. |
Property | closed |
proxies the .closed attribute of the underlying result object, if any, else raises ``AttributeError``. |
Inherited from FilterResult
(via _WithKeys
, AsyncCommon
):
Method | __enter__ |
Undocumented |
Method | __exit__ |
Undocumented |
Method | yield |
Configure the row-fetching strategy to fetch ``num`` rows at a time. |
Method | _fetchall |
Undocumented |
Method | _fetchiter |
Undocumented |
Method | _fetchmany |
Undocumented |
Method | _fetchone |
Undocumented |
Method | _soft |
Undocumented |
Property | _attributes |
Undocumented |
Property | _soft |
Undocumented |
Inherited from ResultInternal
(via _WithKeys
, AsyncCommon
, FilterResult
):
Method | _allrows |
Undocumented |
Method | _column |
Undocumented |
Method | _iter |
Undocumented |
Method | _iterator |
Undocumented |
Method | _manyrow |
Undocumented |
Method | _next |
Undocumented |
Method | _onerow |
Undocumented |
Method | _only |
Undocumented |
Method | _raw |
Undocumented |
Method | _row |
Undocumented |
Method | _unique |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _row |
Undocumented |
Class Variable | _source |
Undocumented |
Instance Variable | _generate |
Undocumented |
Inherited from InPlaceGenerative
(via _WithKeys
, AsyncCommon
, FilterResult
, ResultInternal
):
Method | _generate |
Undocumented |
Return all rows in a list. Closes the result set after invocation. Subsequent invocations will return an empty list. :return: a list of :class:`_engine.Row` objects.
Establish the columns that should be returned in each row. Refer to :meth:`_engine.Result.columns` in the synchronous SQLAlchemy API for a complete behavioral description.
Fetch many rows. When all rows are exhausted, returns an empty list. This method is provided for backwards compatibility with SQLAlchemy 1.x.x. To fetch rows in groups, use the :meth:`._asyncio.AsyncResult.partitions` method. :return: a list of :class:`_engine.Row` objects. .. seealso:: :meth:`_asyncio.AsyncResult.partitions`
Fetch one row. When all rows are exhausted, returns None. This method is provided for backwards compatibility with SQLAlchemy 1.x.x. To fetch the first row of a result only, use the :meth:`_asyncio.AsyncResult.first` method. To iterate through all rows, iterate the :class:`_asyncio.AsyncResult` object directly. :return: a :class:`_engine.Row` object if no filters are applied, or ``None`` if no rows remain.
Fetch the first row or ``None`` if no row is present. Closes the result set and discards remaining rows. .. note:: This method returns one **row**, e.g. tuple, by default. To return exactly one single scalar value, that is, the first column of the first row, use the :meth:`_asyncio.AsyncResult.scalar` method, or combine :meth:`_asyncio.AsyncResult.scalars` and :meth:`_asyncio.AsyncResult.first`. Additionally, in contrast to the behavior of the legacy ORM :meth:`_orm.Query.first` method, **no limit is applied** to the SQL query which was invoked to produce this :class:`_asyncio.AsyncResult`; for a DBAPI driver that buffers results in memory before yielding rows, all rows will be sent to the Python process and all but the first row will be discarded. .. seealso:: :ref:`migration_20_unify_select` :return: a :class:`_engine.Row` object, or None if no rows remain. .. seealso:: :meth:`_asyncio.AsyncResult.scalar` :meth:`_asyncio.AsyncResult.one`
Return a callable object that will produce copies of this :class:`_asyncio.AsyncResult` when invoked. The callable object returned is an instance of :class:`_engine.FrozenResult`. This is used for result set caching. The method must be called on the result when it has been unconsumed, and calling the method will consume the result fully. When the :class:`_engine.FrozenResult` is retrieved from a cache, it can be called any number of times where it will produce a new :class:`_engine.Result` object each time against its stored set of rows. .. seealso:: :ref:`do_orm_execute_re_executing` - example usage within the ORM to implement a result-set cache.
Apply a mappings filter to returned rows, returning an instance of :class:`_asyncio.AsyncMappingResult`. When this filter is applied, fetching rows will return :class:`_engine.RowMapping` objects instead of :class:`_engine.Row` objects. :return: a new :class:`_asyncio.AsyncMappingResult` filtering object referring to the underlying :class:`_result.Result` object.
Return exactly one row or raise an exception. Raises :class:`.NoResultFound` if the result returns no rows, or :class:`.MultipleResultsFound` if multiple rows would be returned. .. note:: This method returns one **row**, e.g. tuple, by default. To return exactly one single scalar value, that is, the first column of the first row, use the :meth:`_asyncio.AsyncResult.scalar_one` method, or combine :meth:`_asyncio.AsyncResult.scalars` and :meth:`_asyncio.AsyncResult.one`. .. versionadded:: 1.4 :return: The first :class:`_engine.Row`. :raises: :class:`.MultipleResultsFound`, :class:`.NoResultFound` .. seealso:: :meth:`_asyncio.AsyncResult.first` :meth:`_asyncio.AsyncResult.one_or_none` :meth:`_asyncio.AsyncResult.scalar_one`
Return at most one result or raise an exception. Returns ``None`` if the result has no rows. Raises :class:`.MultipleResultsFound` if multiple rows are returned. .. versionadded:: 1.4 :return: The first :class:`_engine.Row` or ``None`` if no row is available. :raises: :class:`.MultipleResultsFound` .. seealso:: :meth:`_asyncio.AsyncResult.first` :meth:`_asyncio.AsyncResult.one`
Optional[ int]
= None) -> AsyncIterator[ Sequence[ Row[ _TP]]]
:
(source)
¶
Iterate through sub-lists of rows of the size given. An async iterator is returned:: async def scroll_results(connection): result = await connection.stream(select(users_table)) async for partition in result.partitions(100): print("list of rows: %s" % partition) Refer to :meth:`_engine.Result.partitions` in the synchronous SQLAlchemy API for a complete behavioral description.
Fetch the first column of the first row, and close the result set. Returns ``None`` if there are no rows to fetch. No validation is performed to test if additional rows remain. After calling this method, the object is fully closed, e.g. the :meth:`_engine.CursorResult.close` method will have been called. :return: a Python scalar value, or ``None`` if no rows remain.
Return exactly one scalar result or raise an exception. This is equivalent to calling :meth:`_asyncio.AsyncResult.scalars` and then :meth:`_asyncio.AsyncResult.one`. .. seealso:: :meth:`_asyncio.AsyncResult.one` :meth:`_asyncio.AsyncResult.scalars`
Return exactly one scalar result or ``None``. This is equivalent to calling :meth:`_asyncio.AsyncResult.scalars` and then :meth:`_asyncio.AsyncResult.one_or_none`. .. seealso:: :meth:`_asyncio.AsyncResult.one_or_none` :meth:`_asyncio.AsyncResult.scalars`
Return an :class:`_asyncio.AsyncScalarResult` filtering object which will return single elements rather than :class:`_row.Row` objects. Refer to :meth:`_result.Result.scalars` in the synchronous SQLAlchemy API for a complete behavioral description. :param index: integer or row key indicating the column to be fetched from each row, defaults to ``0`` indicating the first column. :return: a new :class:`_asyncio.AsyncScalarResult` filtering object referring to this :class:`_asyncio.AsyncResult` object.
Apply a "typed tuple" typing filter to returned rows. This method returns the same :class:`_asyncio.AsyncResult` object at runtime, however annotates as returning a :class:`_asyncio.AsyncTupleResult` object that will indicate to :pep:`484` typing tools that plain typed ``Tuple`` instances are returned rather than rows. This allows tuple unpacking and ``__getitem__`` access of :class:`_engine.Row` objects to by typed, for those cases where the statement invoked itself included typing information. .. versionadded:: 2.0 :return: the :class:`_result.AsyncTupleResult` type at typing time. .. seealso:: :attr:`_asyncio.AsyncResult.t` - shorter synonym :attr:`_engine.Row.t` - :class:`_engine.Row` version
Apply unique filtering to the objects returned by this :class:`_asyncio.AsyncResult`. Refer to :meth:`_engine.Result.unique` in the synchronous SQLAlchemy API for a complete behavioral description.
Apply a "typed tuple" typing filter to returned rows. The :attr:`_asyncio.AsyncResult.t` attribute is a synonym for calling the :meth:`_asyncio.AsyncResult.tuples` method. .. versionadded:: 2.0