U kf#/@sdZddlmZddlmZddlZddlZddlZddlZddlm Z ddlm Z ddlm Z ddlm Z dd lm Z dd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddl!m"Z"ddl!m#Z#ddl!m$Z$dd l m%Z%dd!l m&Z&dd"l'm(Z(dd#l)m*Z*dd$l)m+Z+ejse(sdd%l,m-Z-n dd%l.m-Z-ejrdd&l/m0Z0dd'l1m2Z2ee3d(fZ4ee3d(e5fZ6e Z7ee4e7fZ8eee ee fZ9ee d)fZ:ed*e9d+Z;ed,e d+Zeee e fZ?eed.Z@e ee gee fZAe e ge fZBeee eeBfZCGd/d0d0ZDGd1d2d2ejEe ZFGd3d4d4eDZGdWd5d6d7d8d9d:ZHGd;d<dd>e$e e;ZKGd?d@d@ZLGdAdBdBeLeKee=ZMGdCdDdDeKe;ZNGdEdFdFeNe;ZOGdGdHdHeNe;e jPZQGdIdJdJeLeNeZRGdKdLdLe e=ZSGdMdNdNeMe=ZTdOdPdQdRZUGdSdTdTeTe=ZVGdUdVdVeTe=ZWdS)Xz%Define generic result set constructs.) annotations)EnumN)Any)Callable)cast)Dict)Generic)Iterable)Iterator)List)Mapping)NoReturn)Optional)overload)Sequence)Set)Tuple) TYPE_CHECKING)TypeVar)Union)Row) RowMapping)exc)util) _generative) HasMemoized)InPlaceGenerative)!HasMemoized_ro_memoized_attribute)NONE_SET)HAS_CYEXTENSION)Literal)Self) tuplegetter)Column)_ResultProcessorTypez Column[Any]._R)bound_T_TPz_ResultProcessorType[Any]c@seZdZUdZdZdZded<dZded<dZded <d ed <d ed <ded<ded<e ddddZ dddddZ ddddZ e dOddd d!d"d#d$Ze dPddd%d&d"d'd$Ze dQdddd(d"d)d$ZdRdddd(d"d+d$Zd,d!d-d.d/Zd0dd1d2d3d4Zd5d6d7d8d9Zd5d:d7d;d<Zd5dd7d=d>ZdSddd?d2d@dAZd5dBd7dCdDZdEdFddGdHdIZddd!dJdKdLZe dddMdNZdS)TResultMetaDataz$Base for metadata about result rows.NOptional[_TupleGetterType] _tuplefilterOptional[Sequence[int]]_translated_indexes(Optional[Sequence[Callable[[Any], Any]]]_unique_filters _KeyMapType_keymap Sequence[str]_keysOptional[_ProcessorsType] _processorsMapping[_KeyType, int] _key_to_index RMKeyViewreturncCst|SN)r;selfr,r,H/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/engine/result.pykeysjszResultMetaData.keysobjectboolkeyr=cCs tdSr>NotImplementedErrorr@rFr,r,rA_has_keynszResultMetaData._has_keycCs tdSr>rGr?r,r,rA _for_freezeqszResultMetaData._for_freeze.rzOptional[Exception] Literal[True]r )rFerrraiseerrr=cCsdSr>r,r@rFrMrNr,r,rA _key_fallbacktszResultMetaData._key_fallbackzLiteral[False]NonecCsdSr>r,rOr,r,rArPyszOptional[NoReturn]cCsdSr>r,rOr,r,rArPsTcCs|stt||dSr>)AssertionErrorKeyErrorrOr,r,rArPs_KeyMapRecType)recr=cCs tddS)NzCambiguous column name logic is implemented for CursorResultMetaDatarG)r@rUr,r,rA _raise_for_ambiguous_column_namesz/ResultMetaData._raise_for_ambiguous_column_name _KeyIndexType Optional[int]rFrNr=cCs tdSr>rGr@rFrNr,r,rA_index_for_keyszResultMetaData._index_for_keySequence[_KeyIndexType] Sequence[int]rBr=cCs tdSr>rGr@rBr,r,rA_indexes_for_keyssz ResultMetaData._indexes_for_keysIterator[_KeyMapRecType]cCs tdSr>rGr_r,r,rA_metadata_for_keyssz!ResultMetaData._metadata_for_keyscCs tdSr>rGr_r,r,rA_reduceszResultMetaData._reduce#Optional[Callable[[Row[Any]], Any]]cCs&|||}|dk rt|SdSdSr>)r[operator itemgetter)r@rFrNindexr,r,rA_getters  zResultMetaData._getter_TupleGetterTypecCs||}t|Sr>)r`r$)r@rBindexesr,r,rA_row_as_tuple_getters z#ResultMetaData._row_as_tuple_getterz Mapping[_KeyType, Sequence[Any]]int)keymaprgr=csfdd|DS)Ncs&i|]\}}|dk r||qSr>r,).0rFrUrgr,rA s z5ResultMetaData._make_key_to_index..)items)r@rmrgr,rorA_make_key_to_indexs z!ResultMetaData._make_key_to_index)rF attr_errorr=c Csv||jkr||j|nV|rfz||dWqrtk rb}zt|jd|W5d}~XYqrXn ||ddSNr)r4rVrPrSAttributeErrorargs)r@rFrsker,r,rA_key_not_founds $zResultMetaData._key_not_foundcCs |jrt|jrdS|jSdSr>)r8r issupersetr?r,r,rA_effective_processorssz$ResultMetaData._effective_processors).).).)T)T)__name__ __module__ __qualname____doc__ __slots__r.__annotations__r0r2propertyrBrJrKrrPrVr[r`rbrcrhrkrrrxrzr,r,r,rAr+]sH      r+c@seZdZUdZded<ded<ddddZd d d d Zd d ddZdd ddZdddddZ dddddZ dddddZ dS)r;_parentr6r+rr5r6)parentcCs||_dd|jD|_dS)NcSsg|]}|dk r|qSr>r,)rnkr,r,rA sz&RMKeyView.__init__..r)r@rr,r,rA__init__szRMKeyView.__init__rlr<cCs t|jSr>)lenr6r?r,r,rA__len__szRMKeyView.__len__strcCs d|S)Nz#{0.__class__.__name__}({0._keys!r}))formatr?r,r,rA__repr__szRMKeyView.__repr__z Iterator[str]cCs t|jSr>)iterr6r?r,r,rA__iter__szRMKeyView.__iter__rrD)itemr=cCst|trdS|j|S)NF) isinstancerlrrJ)r@rr,r,rA __contains__s zRMKeyView.__contains__)otherr=cCst|t|kSr>listr@rr,r,rA__eq__szRMKeyView.__eq__cCst|t|kSr>rrr,r,rA__ne__szRMKeyView.__ne__N) r{r|r}rrrrrrrrrr,r,r,rAr;s r;c@seZdZUdZdZded<d.ddddd d d d d ZdddddZddddZddddZ dddddZ d/ddd d!d"d#Z d$d%d&d'd(Z d$d)d&d*d+Z d$dd&d,d-ZdS)0SimpleResultMetaDataz*result metadata for in-memory collections.)r6r4r8r.r0r2r:r5r6NzOptional[Sequence[Any]]r7r-r/r1)rBextrar8r.r0r2cCszt||_||_||_||_|r.cSs g|]\}}|f||dffqSrr,)rnrgrr,r,rArscSs i|]\}}|D] }||qqSr,r,)rnrBrUrFr,r,rArp!s z1SimpleResultMetaData.__init__..r) rr6r.r0r2 enumeratezipr4r8rrr:)r@rBrr8r.r0r2Z recs_namesr,r,rArs zSimpleResultMetaData.__init__rCrDrEcCs ||jkSr>r4rIr,r,rArJ'szSimpleResultMetaData._has_keyr+r<cs:j}|rjr|}tjfddjD|dS)Ncsg|]}j|dqS)rrrnrFr?r,rAr3sz4SimpleResultMetaData._for_freeze..)rr2)r2r.rr6)r@Zunique_filtersr,r?rArK*s  z SimpleResultMetaData._for_freezezDict[str, Any]cCs|j|jdS)Nr6r0rr?r,r,rA __getstate__7sz!SimpleResultMetaData.__getstate__rQ)stater=cCs:|dr|d}t|}nd}}|j|d||ddS)Nr0r6)r0r.)r$r)r@rr0r.r,r,rA __setstate__=s z!SimpleResultMetaData.__setstate__TrrlrYc Cs^t|jjkr|j|}z|j|}Wn0tk rT}z||||}W5d}~XYnX|dSrtrl __class____mro__r6r4rSrP)r@rFrNrUrwr,r,rAr[Is   z#SimpleResultMetaData._index_for_key Sequence[Any]r]r^csfdd|DS)Ncsg|]}j|dqSrrrr?r,rArTsz:SimpleResultMetaData._indexes_for_keys..r,r_r,r?rAr`Ssz&SimpleResultMetaData._indexes_for_keysrac csj|D]`}t|jjkr|j|}z|j|}Wn0tk r\}z|||d}W5d}~XYnX|VqdS)NTr)r@rBrFrUrwr,r,rArbVs   z'SimpleResultMetaData._metadata_for_keysc szfdd|D}Wn6tk rL}z|jd|dW5d}~XYnXt|\}}}jrtfdd|D}t|}t||||jjd}|S)Ncs,g|]$}jt|jjkr"j|n|qSr,)r4rlrrr6rr?r,rArfsz0SimpleResultMetaData._reduce..rTcsg|]}j|qSr,)r0)rnidxr?r,rArus)rr.r0r8r2) rSrPrvrr0r$rr8r2) r@rBZmetadata_for_keysrwrjZnew_keysrtupZ new_metadatar,r?rArcds&  & zSimpleResultMetaData._reduce)NNNNN)T)r{r|r}r~rrrrJrKrrr[r`rbrcr,r,r,rArs"  !   rr5 Optional[Any]z#Callable[[Iterable[Any]], Row[Any]])fieldsrr=cCst||}tt||j|jSr>)r functoolspartialrrzr:)rrrr,r,rA result_tuples rc@seZdZdZdS)_NoRowrN)r{r|r}_NO_ROWr,r,r,rArsrc@seZdZUdZdZded<dZded<ded <dZd ed <dZded <d Z ded<ded<ddddZ dJdddddZ dKdddddZ ddddZ dLdd d!d"d#Zed$dd%d&Zed'dd(d)Zd*dd+d,Zd*dd-d.Zed/dd0d1Zed2dd3d4Zedd5dd6d7d8d9Zedddd:d7d;d9Zdddd:d7dd?Zd6dd@dAZedBdCdDdEdFZejdGddHdIZdS)MResultInternalr,NOptional[Result[Any]] _real_resultTrD_generate_rowsOptional[Callable[[Any], Any]]_row_logging_fnz Optional[_UniqueFilterStateType]_unique_filter_state_post_creational_filterFr+ _metadata_source_supports_scalars#Iterator[_InterimRowType[Row[Any]]]r<cCs tdSr>rGr?r,r,rA_fetchiter_implszResultInternal._fetchiter_impl#Optional[_InterimRowType[Row[Any]]] hard_closer=cCs tdSr>rGr@rr,r,rA_fetchone_implszResultInternal._fetchone_implrXList[_InterimRowType[Row[Any]]]sizer=cCs tdSr>rGr@rr,r,rA_fetchmany_implszResultInternal._fetchmany_implcCs tdSr>rGr?r,r,rA_fetchall_implszResultInternal._fetchall_implrQhardr=cCs tdSr>rGr@rr,r,rA _soft_closeszResultInternal._soft_closeOptional[Callable[..., _R]]cs|jr |jntd|}|jrF|js&dStddddddfdd }nt}|j}|j}|j}|j}|r|js|rx||}t |||||d d d fd d }nt ||||}|j r|j |d d d fdd }|S)N Result[Any]r+r7r9rzRow[Any])metadata processors key_to_index scalar_objr=cs||||fSr>r,)rrrr)_procr,rA process_rows z/ResultInternal._row_getter..process_rowz_InterimRowType[Row[Any]]r')rowr=cs |Sr>r,r)_make_row_origfixed_tfr,rAmake_rowsz,ResultInternal._row_getter..make_rowcs |Sr>r,r)_log_row _make_rowr,rArs) rrrrrrr:rzr.rrr)r@ real_resultrrrrtfrr,)rrrrrrA _row_gettersH  zResultInternal._row_getterzCallable[..., Iterator[_R]]csR|j|j|jr8|j\dddfdd }ndddfdd }|S)Nr Iterator[_R]r@r=c3sX|D]J}r|n|}r(|n|}|kr6q|rL|}|VqdSr>)radd)r@raw_rowobjhashedrpost_creational_filterstrategyuniquesr,rAiterrowss  z1ResultInternal._iterator_getter..iterrowsc3s4|D]&}r|n|}r(|}|VqdSr>)r)r@rrrrr,rArs  rrr_unique_strategy)r@rr,rrA_iterator_getters  zResultInternal._iterator_getterList[_R]cs,|jdk st|}fdd|DS)Ncsg|] }|qSr,r,rnrrr,rArsz0ResultInternal._raw_all_rows..)rrRr)r@rowsr,rrA _raw_all_rowss zResultInternal._raw_all_rowscs|j|j|}r,fdd|D}n|}|jrb|j\fddfdd|DD}n|}r|fdd|D}|S)Ncsg|] }|qSr,r,rrr,rAr'sz+ResultInternal._allrows..cs&g|]\}}|kr|s|qSr,rrnmade_rowZsig_rowrr,rAr0s cs g|]}|r|n|fqSr,r,rnrrr,rAr2scsg|] }|qSr,r,rrr,rAr?s)rrrrr)r@r made_rowsZ interim_rowsr,rrA_allrowss&     zResultInternal._allrowsz1Callable[..., Union[Literal[_NoRow._NO_ROW], _R]]csR|j|j|jr8|j\dddfdd }ndddfdd }|S)NrzUnion[_NoRow, _R]rcsd|j}|}|dkrtSr$|n|}r4|n|}|krDqn |rZ|}|SqdSr>)rrr)r@Z_onerowrrrrr,rAonerowOs z-ResultInternal._onerow_getter..onerowcs8|}|dkrtSr |n|}r0|}|SdSr>)rr)r@rZ interim_rowrr,rArdsr)r@rr,rrA_onerow_getterDs  zResultInternal._onerow_getterzCallable[..., List[_R]]csn|j|j|jrR|j\ddddddddd d dd fd d }nd d dd fdd }|S)Nrz List[Any]z$Optional[Callable[[List[Any]], Any]]zSet[Any]r)rrrrr=csNrfdd|D}r.fdd|D}ndd|D}fdd|DS)Ncsg|] }|qSr,r,rrr,rArszFResultInternal._manyrow_getter..filterrows..c3s|]}||fVqdSr>r,rrr,rA szEResultInternal._manyrow_getter..filterrows..css|]}||fVqdSr>r,rr,r,rArscs&g|]\}}|kr|s|qSr,rrrr,rArs r,)rrrrrr,)rrrrA filterrows{s  z2ResultInternal._manyrow_getter..filterrowszResultInternal[_R]rX)r@numr=csg}|j}|dkrx|jr|jntd|}|jr:|j}}q|||}t|}dk sVt|||t|}n|}|dk st|r||}|sq|||t|}qr҇fdd|D}|S)Nrcsg|] }|qSr,r,rrr,rArsDResultInternal._manyrow_getter..manyrows..)rrr _yield_perrrRextend)r@rZcollectZ _manyrowsrZ num_requiredrrrrrrr,rAmanyrowss:     z0ResultInternal._manyrow_getter..manyrowscs^|dkr$|jr|jntd|}|j}||}rDfdd|D}rZfdd|D}|S)Nrcsg|] }|qSr,r,rrr,rArsrcsg|] }|qSr,r,rrr,rArs)rrrr)r@rrrrr,rArs r)r@rr,rrA_manyrow_getterrs  1zResultInternal._manyrow_getterrLr')raise_for_second_rowraise_for_nonescalarr=cCsdSr>r,r@rr r r,r,rA _only_one_rowszResultInternal._only_one_row Optional[_R]cCsdSr>r,r r,r,rAr sc Cs|j}|dd}|dkr,|r(tdndS|rB|jrBd|_d}n|j}z|rV||n|}Wn|jddYnX|rf|jr"|j\}}|r||n|} |dd} | dkrt } q:zH|r|| n| } |r| t k st | || krWqn || krWqWq:Wq|jddYqXqn|dd} | dkr:t } | t k rv|jddt |r^dndnt } |jdd|s|j } | r| |}|r|r|dS|SdS) NTrz&No row was found when one was requiredFrz6Multiple rows were found when exactly one was requiredz6Multiple rows were found when one or none was requiredr) rrZ NoResultFoundrrrrrrrrRZMultipleResultsFoundr) r@rr r rrrrrZexisting_row_hashZnext_rowrr,r,rAr sp                rcCs ||Sr>)rr?r,r,rA _iter_impl;szResultInternal._iter_implcCs"||}|tkrtn|SdSr>)rr StopIterationr@rr,r,rA _next_impl>s zResultInternal._next_implr\r#)rjr=cCsD|jr |jntd|}|jr(t|dkr6|j||_|js@t|S)Nrr)rrrrrrcrrR)r@rjrr,r,rA_column_slicesEs zResultInternal._column_slices_UniqueFilterStateTypecCs|jdk st|j\}}|jdk r(|jntd|}|s|jjr|jrX|jsX|jjd}n(|jj}|jjrt|j|}t d|}||fS)NrrZ_filter_on_values) rrRrrrr2rrr.re methodcaller)r@rrrfiltersr,r,rArTs"    zResultInternal._unique_strategy)F)N)F)r{r|r}rrrrrrZ _is_cursorrrrrrrrrrrrrrr rrrrrZmemoized_attributerr,r,r,rArsJ     ;"%-bVrc@s(eZdZUdZded<ddddZdS) _WithKeysr,r+rr;r<cCs|jjS)akReturn an iterable view which yields the string keys that would be represented by each :class:`_engine.Row`. The keys can represent the labels of the columns returned by a core statement or the names of the orm classes returned by an orm execution. The view also can be tested for key containment using the Python ``in`` operator, which will test both for the string keys represented in the view, as well as for alternate keys such as column objects. .. versionchanged:: 1.4 a key view object is returned rather than a plain list. )rrBr?r,r,rArBtsz_WithKeys.keysN)r{r|r}rrrBr,r,r,rArns rc@seZdZUdZdZdZded<dZded<dZd ed <e Z d ed <d dddZ ddddZ dddddddZddddZeddddZeddddZed dd!d"d#Zedd$dd%d&d'Zd(dd)d*d+Zed,d-d.d/d0Zed,d1d-d2d3d0Zedd(d5d6d7d0Zdd(d5d6d8d0Zdd(dd:d;dd?d@dAdBZdCddDdEZedFddGdHZdFddIdJZdKddLdMZdNddOdPZdQddRdSZ dd dTdUdVdWZ!dXddYdZZ"d[dd\d]Z#dd dXdUd^d_Z$dXdd`daZ%d[ddbdcZ&d[ddddeZ'ed,dfd.dgdhZ(edddidhZ(dddjdhZ(ed,dkd.dldmZ)ednddodmZ)dnddpdmZ)dQddqdrZ*ed,dkd.dsdtZ+edddudtZ+dddvdtZ+dwddxdyZ,dzd{d|d}d~Z-dS)Resulta\Represent a set of database results. .. versionadded:: 1.4 The :class:`_engine.Result` object provides a completely updated usage model and calling facade for SQLAlchemy Core and SQLAlchemy ORM. In Core, it forms the basis of the :class:`_engine.CursorResult` object which replaces the previous :class:`_engine.ResultProxy` interface. When using the ORM, a higher level object called :class:`_engine.ChunkedIteratorResult` is normally used. .. note:: In SQLAlchemy 1.4 and above, this object is used for ORM results returned by :meth:`_orm.Session.execute`, which can yield instances of ORM mapped objects either individually or within tuple-like rows. Note that the :class:`_engine.Result` object does 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:`_engine.Result.unique` modifier method. .. seealso:: :ref:`tutorial_fetching_rows` - in the :doc:`/tutorial/index` )r__dict__Nz(Optional[Callable[[Row[Any]], Row[Any]]]rFrDrrXrzutil.immutabledict[Any, Any] _attributesr+)cursor_metadatacCs ||_dSr>)r)r@rr,r,rArszResult.__init__r#r<cCs|Sr>r,r?r,r,rA __enter__szResult.__enter__rrQtype_value tracebackr=cCs |dSr>)closer@rr r!r,r,rA__exit__szResult.__exit__cCs|jdddS)aclose this :class:`_engine.Result`. The behavior of this method is implementation specific, and is not implemented by default. The method should generally end the resources in use by the result object and also cause any subsequent iteration or row fetching to raise :class:`.ResourceClosedError`. .. versionadded:: 1.4.27 - ``.close()`` was previously not generally available for all :class:`_engine.Result` classes, instead only being available on the :class:`_engine.CursorResult` returned for Core statement executions. As most other result objects, namely the ones used by the ORM, are proxying a :class:`_engine.CursorResult` in any case, this allows the underlying cursor result to be closed from the outside facade for the case when the ORM query is using the ``yield_per`` execution option where it does not immediately exhaust and autoclose the database cursor. TrN)rr?r,r,rAr"sz Result.closecCs tdSr>rGr?r,r,rA _soft_closedszResult._soft_closedcCs tdS)zkreturn ``True`` if this :class:`_engine.Result` reports .closed .. versionadded:: 1.4.43 NrGr?r,r,rAclosedsz Result.closedrlrr=cCs ||_|S)aConfigure the row-fetching strategy to fetch ``num`` rows at a time. This impacts the underlying behavior of the result when iterating over the result object, or otherwise making use of methods such as :meth:`_engine.Result.fetchone` that return one row at a time. Data from the underlying cursor or other data source will be buffered up to this many rows in memory, and the buffered collection will then be yielded out one row at a time or as many rows are requested. Each time the buffer clears, it will be refreshed to this many rows or as many rows remain if fewer remain. The :meth:`_engine.Result.yield_per` method is generally used in conjunction with the :paramref:`_engine.Connection.execution_options.stream_results` execution option, which will allow the database dialect in use to make use of a server side cursor, if the DBAPI supports a specific "server side cursor" mode separate from its default mode of operation. .. tip:: Consider using the :paramref:`_engine.Connection.execution_options.yield_per` execution option, which will simultaneously set :paramref:`_engine.Connection.execution_options.stream_results` to ensure the use of server side cursors, as well as automatically invoke the :meth:`_engine.Result.yield_per` method to establish a fixed row buffer size at once. The :paramref:`_engine.Connection.execution_options.yield_per` execution option is available for ORM operations, with :class:`_orm.Session`-oriented use described at :ref:`orm_queryguide_yield_per`. The Core-only version which works with :class:`_engine.Connection` is new as of SQLAlchemy 1.4.40. .. versionadded:: 1.4 :param num: number of rows to fetch each time the buffer is refilled. If set to a value below 1, fetches all rows for the next buffer. .. seealso:: :ref:`engine_stream_results` - describes Core behavior for :meth:`_engine.Result.yield_per` :ref:`orm_queryguide_yield_per` - in the :ref:`queryguide_toplevel` )rr@rr,r,rA yield_pers1zResult.yield_perOptional[_UniqueFilterType]rr=cCst|f|_|S)aApply unique filtering to the objects returned by this :class:`_engine.Result`. When this filter is applied with no arguments, the rows or objects returned will filtered such that each row is returned uniquely. The algorithm used to determine this uniqueness is by default the Python hashing identity of the whole tuple. In some cases a specialized per-entity hashing scheme may be used, such as when using the ORM, a scheme is applied which works against the primary key identity of returned objects. The unique filter is applied **after all other filters**, which means if the columns returned have been refined using a method such as the :meth:`_engine.Result.columns` or :meth:`_engine.Result.scalars` method, the uniquing is applied to **only the column or columns returned**. This occurs regardless of the order in which these methods have been called upon the :class:`_engine.Result` object. The unique filter also changes the calculus used for methods like :meth:`_engine.Result.fetchmany` and :meth:`_engine.Result.partitions`. When using :meth:`_engine.Result.unique`, these methods will continue to yield the number of rows or objects requested, after uniquing has been applied. However, this necessarily impacts the buffering behavior of the underlying cursor or datasource, such that multiple underlying calls to ``cursor.fetchmany()`` may be necessary in order to accumulate enough objects in order to provide a unique collection of the requested size. :param strategy: a callable that will be applied to rows or objects being iterated, which should return an object that represents the unique value of the row. A Python ``set()`` is used to store these identities. If not passed, a default uniqueness strategy is used which may have been assembled by the source of this :class:`_engine.Result` object. setrr@rr,r,rAunique s& z Result.uniquerWcol_expressionsr=cGs ||S)a9Establish the columns that should be returned in each row. This method may be used to limit the columns returned as well as to reorder them. The given list of expressions are normally a series of integers or string key names. They may also be appropriate :class:`.ColumnElement` objects which correspond to a given statement construct. .. versionchanged:: 2.0 Due to a bug in 1.4, the :meth:`_engine.Result.columns` method had an incorrect behavior where calling upon the method with just one index would cause the :class:`_engine.Result` object to yield scalar values rather than :class:`_engine.Row` objects. In version 2.0, this behavior has been corrected such that calling upon :meth:`_engine.Result.columns` with a single index will produce a :class:`_engine.Result` object that continues to yield :class:`_engine.Row` objects, which include only a single column. E.g.:: statement = select(table.c.x, table.c.y, table.c.z) result = connection.execute(statement) for z, y in result.columns('z', 'y'): # ... Example of using the column objects from the statement itself:: for z, y in result.columns( statement.selected_columns.c.z, statement.selected_columns.c.y ): # ... .. versionadded:: 1.4 :param \*col_expressions: indicates columns to be returned. Elements may be integer row indexes, string column names, or appropriate :class:`.ColumnElement` objects corresponding to a select construct. :return: this :class:`_engine.Result` object with the modifications given. rr@r1r,r,rAcolumns5s/zResult.columnszResult[Tuple[_T]]zScalarResult[_T]rcCsdSr>r,r?r,r,rAscalarsfszResult.scalarsz Literal[0])r@rgr=cCsdSr>r,r@rgr,r,rAr5isrzScalarResult[Any])rgr=cCsdSr>r,r6r,r,rAr5nscCs t||S)a@Return a :class:`_engine.ScalarResult` filtering object which will return single elements rather than :class:`_row.Row` objects. E.g.:: >>> result = conn.execute(text("select int_id from table")) >>> result.scalars().all() [1, 2, 3] When results are fetched from the :class:`_engine.ScalarResult` filtering object, the single column-row that would be returned by the :class:`_engine.Result` is instead returned as the column's value. .. versionadded:: 1.4 :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:`_engine.ScalarResult` filtering object referring to this :class:`_engine.Result` object. ) ScalarResultr6r,r,rAr5qsTrdrYcCs|jrtd|j||S)zareturn a callable that will retrieve the given key from a :class:`_engine.Row`. .can't use this function in 'only scalars' mode)rrHrrhrZr,r,rArhs zResult._getterr\rir^cCs|jrtd|j|S)zbreturn a callable that will retrieve the given keys from a :class:`_engine.Row`. r8)rrHrrkr_r,r,rA _tuple_getters zResult._tuple_getter MappingResultcCst|S)aApply a mappings filter to returned rows, returning an instance of :class:`_engine.MappingResult`. When this filter is applied, fetching rows will return :class:`_engine.RowMapping` objects instead of :class:`_engine.Row` objects. .. versionadded:: 1.4 :return: a new :class:`_engine.MappingResult` filtering object referring to this :class:`_engine.Result` object. )r:r?r,r,rAmappingsszResult.mappingszTupleResult[_TP]cCs|S)zApply a "typed tuple" typing filter to returned rows. The :attr:`_engine.Result.t` attribute is a synonym for calling the :meth:`_engine.Result.tuples` method. .. versionadded:: 2.0 r,r?r,r,rAts zResult.tcCs|S)a,Apply a "typed tuple" typing filter to returned rows. This method returns the same :class:`_engine.Result` object at runtime, however annotates as returning a :class:`_engine.TupleResult` 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:`_engine.TupleResult` type at typing time. .. seealso:: :attr:`_engine.Result.t` - shorter synonym :attr:`_engine.Row._t` - :class:`_engine.Row` version r,r?r,r,rAtuplessz Result.tuplesIterator[_RowData]cCs tdS)zReturn a safe iterator that yields raw row data. This is used by the :meth:`_engine.Result.merge` method to merge multiple compatible results together. NrGr?r,r,rA_raw_row_iteratorszResult._raw_row_iteratorzIterator[Row[_TP]]cCs|Sr>rr?r,r,rArszResult.__iter__zRow[_TP]cCs|Sr>rr?r,r,rA__next__szResult.__next__zIterator[Sequence[Row[_TP]]]rccs$|j}|||}|r |Vqq qdS)aIterate through sub-lists of rows of the size given. Each list will be of the size given, excluding the last list to be yielded, which may have a small number of rows. No empty lists will be yielded. The result object is automatically closed when the iterator is fully consumed. Note that the backend driver will usually buffer the entire result ahead of time unless the :paramref:`.Connection.execution_options.stream_results` execution option is used indicating that the driver should not pre-buffer results, if possible. Not all drivers support this option and the option is silently ignored for those who do not. When using the ORM, the :meth:`_engine.Result.partitions` method is typically more effective from a memory perspective when it is combined with use of the :ref:`yield_per execution option `, which instructs both the DBAPI driver to use server side cursors, if available, as well as instructs the ORM loading internals to only build a certain amount of ORM objects from a result at a time before yielding them out. .. versionadded:: 1.4 :param size: indicate the maximum number of rows to be present in each list yielded. If None, makes use of the value set by the :meth:`_engine.Result.yield_per`, method, if it were called, or the :paramref:`_engine.Connection.execution_options.yield_per` execution option, which is equivalent in this regard. If yield_per weren't set, it makes use of the :meth:`_engine.Result.fetchmany` default, which may be backend specific and not well defined. :return: iterator of lists .. seealso:: :ref:`engine_stream_results` :ref:`orm_queryguide_yield_per` - in the :ref:`queryguide_toplevel` Nrr@rgetter partitionr,r,rA partitionss 1 zResult.partitionsSequence[Row[_TP]]cCs|S)z4A synonym for the :meth:`_engine.Result.all` method.rr?r,r,rAfetchall"szResult.fetchallzOptional[Row[_TP]]cCs||}|tkrdS|SdS)aFetch 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:`_engine.Result.first` method. To iterate through all rows, iterate the :class:`_engine.Result` object directly. :return: a :class:`_engine.Row` object if no filters are applied, or ``None`` if no rows remain. Nrrrr,r,rAfetchone's zResult.fetchonecCs |||S)aFetch many rows. When all rows are exhausted, returns an empty sequence. This method is provided for backwards compatibility with SQLAlchemy 1.x.x. To fetch rows in groups, use the :meth:`_engine.Result.partitions` method. :return: a sequence of :class:`_engine.Row` objects. .. seealso:: :meth:`_engine.Result.partitions` rCrr,r,rA fetchmany=szResult.fetchmanycCs|S)aReturn all rows in a sequence. Closes the result set after invocation. Subsequent invocations will return an empty sequence. .. versionadded:: 1.4 :return: a sequence of :class:`_engine.Row` objects. .. seealso:: :ref:`engine_stream_results` - How to stream a large result set without loading it completely in python. rIr?r,r,rAallRsz Result.allcCs|jddddS)aFetch 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:`_engine.Result.scalar` method, or combine :meth:`_engine.Result.scalars` and :meth:`_engine.Result.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:`_engine.Result`; 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:`_engine.Result.scalar` :meth:`_engine.Result.one` Frr r r r?r,r,rAfirstes #z Result.firstcCs|jddddS)aReturn 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:`_engine.Result.first` :meth:`_engine.Result.one` TFrOrPr?r,r,rA one_or_nones zResult.one_or_noner)cCsdSr>r,r?r,r,rA scalar_oneszResult.scalar_onecCsdSr>r,r?r,r,rArSscCs|jddddS)aReturn exactly one scalar result or raise an exception. This is equivalent to calling :meth:`_engine.Result.scalars` and then :meth:`_engine.Result.one`. .. seealso:: :meth:`_engine.Result.one` :meth:`_engine.Result.scalars` TrOrPr?r,r,rArSs  Optional[_T]cCsdSr>r,r?r,r,rAscalar_one_or_noneszResult.scalar_one_or_nonercCsdSr>r,r?r,r,rArUscCs|jddddS)a$Return exactly one scalar result or ``None``. This is equivalent to calling :meth:`_engine.Result.scalars` and then :meth:`_engine.Result.one_or_none`. .. seealso:: :meth:`_engine.Result.one_or_none` :meth:`_engine.Result.scalars` TFrOrPr?r,r,rArUs cCs|jddddS)aeReturn 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:`_engine.Result.scalar_one` method, or combine :meth:`_engine.Result.scalars` and :meth:`_engine.Result.one`. .. versionadded:: 1.4 :return: The first :class:`_engine.Row`. :raises: :class:`.MultipleResultsFound`, :class:`.NoResultFound` .. seealso:: :meth:`_engine.Result.first` :meth:`_engine.Result.one_or_none` :meth:`_engine.Result.scalar_one` TFrOrPr?r,r,rAones z Result.onecCsdSr>r,r?r,r,rAr sz Result.scalarcCsdSr>r,r?r,r,rAr scCs|jddddS)aFetch 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. FTrOrPr?r,r,rAr s FrozenResult[_TP]cCst|S)aReturn a callable object that will produce copies of this :class:`_engine.Result` 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. ) FrozenResultr?r,r,rAfreeze sz Result.freezerzMergedResult[_TP])othersr=cGst|j|f|S)aMerge this :class:`_engine.Result` with other compatible result objects. The object returned is an instance of :class:`_engine.MergedResult`, which will be composed of iterators from the given result objects. The new result will use the metadata from this result object. The subsequent result objects must be against an identical set of result / cursor metadata, otherwise the behavior is undefined. ) MergedResultr)r@rZr,r,rAmerge#sz Result.merge)N)r)r)T)N)N).r{r|r}r~rrrrrrZ immutabledictrrrr$r"rr%r&rr)r/r4rr5rhr9r;r<r=r?rrBrGrJrLrMrNrQrRrSrUrVr rYr\r,r,r,rArs|    3(1    :'!rc@seZdZUdZdZded<ded<ddd d Zd d d d d ddZedddddZ d1dd dddZ e ddddZ e ddddZ d dddZe ddd d!Zd"dd#d$Zd2dd%d&d'd(Zd)dd*d+Zd3d-d)d.d/d0Zd,S)4 FilterResultaZA wrapper for a :class:`_engine.Result` that returns objects other than :class:`_engine.Row` objects, such as dictionaries or scalar objects. :class:`_engine.FilterResult` is the common base for additional result APIs including :class:`_engine.MappingResult`, :class:`_engine.ScalarResult` and :class:`_engine.AsyncResult`. )rrrrrrrrrr#r<cCs|Sr>r,r?r,r,rArJszFilterResult.__enter__rrQrcCs|j|||dSr>)rr$r#r,r,rAr$MszFilterResult.__exit__rlr'cCs|j||_|S)aConfigure the row-fetching strategy to fetch ``num`` rows at a time. The :meth:`_engine.FilterResult.yield_per` method is a pass through to the :meth:`_engine.Result.yield_per` method. See that method's documentation for usage notes. .. versionadded:: 1.4.40 - added :meth:`_engine.FilterResult.yield_per` so that the method is available on all result set implementations .. seealso:: :ref:`engine_stream_results` - describes Core behavior for :meth:`_engine.Result.yield_per` :ref:`orm_queryguide_yield_per` - in the :ref:`queryguide_toplevel` )rr)r(r,r,rAr)PszFilterResult.yield_perFrDrcCs|jj|ddSNr)rrrr,r,rArfszFilterResult._soft_closecCs|jjSr>)rr%r?r,r,rAr%iszFilterResult._soft_closedcCs|jjS)z|Return ``True`` if the underlying :class:`_engine.Result` reports closed .. versionadded:: 1.4.43 )rr&r?r,r,rAr&mszFilterResult.closedcCs|jdS)zUClose this :class:`_engine.FilterResult`. .. versionadded:: 1.4.43 N)rr"r?r,r,rAr"wszFilterResult.closezDict[Any, Any]cCs|jjSr>)rrr?r,r,rArszFilterResult._attributesrcCs |jSr>)rrr?r,r,rArszFilterResult._fetchiter_implrrcCs|jj|dS)Nr)rrrr,r,rArszFilterResult._fetchone_implrcCs |jSr>)rrr?r,r,rArszFilterResult._fetchall_implNrXrcCs|jj|dSNr)rrrr,r,rArszFilterResult._fetchmany_impl)F)F)N)r{r|r}r~rrrr$rr)rrr%r&r"rrrrrr,r,r,rAr]4s,   r]c@seZdZUdZdZdZded<dddd d Zd+d d dddZd,dddddZ ddddZ d-dddddZ ddddZ dddd Z d!dd"d#Zd$dd%d&Zd$dd'd(Zd!dd)d*Zd S).r7aA wrapper for a :class:`_engine.Result` that returns scalar values rather than :class:`_row.Row` values. The :class:`_engine.ScalarResult` object is acquired by calling the :meth:`_engine.Result.scalars` method. A special limitation of :class:`_engine.ScalarResult` is that it has no ``fetchone()`` method; since the semantics of ``fetchone()`` are that the ``None`` value indicates no more results, this is not compatible with :class:`_engine.ScalarResult` since there is no way to distinguish between ``None`` as a row value versus ``None`` as an indicator. Use ``next(result)`` to receive values individually. r,FrrrrW)rrgcCsD||_|jr|j|_d|_n|j|g|_td|_|j|_dSrt)rrrrrcrerfr)r@rrgr,r,rArs zScalarResult.__init__Nr*r#r+cCst|f|_|S)zApply unique filtering to the objects returned by this :class:`_engine.ScalarResult`. See :meth:`_engine.Result.unique` for usage details. r,r.r,r,rAr/s zScalarResult.uniquerXIterator[Sequence[_R]]rccs$|j}|||}|r |Vqq qdS)zIterate through sub-lists of elements of the size given. Equivalent to :meth:`_engine.Result.partitions` except that scalar values, rather than :class:`_engine.Row` objects, are returned. NrCrDr,r,rArGs  zScalarResult.partitions Sequence[_R]r<cCs|S):A synonym for the :meth:`_engine.ScalarResult.all` method.rIr?r,r,rArJszScalarResult.fetchallcCs |||S)zFetch many objects. Equivalent to :meth:`_engine.Result.fetchmany` except that scalar values, rather than :class:`_engine.Row` objects, are returned. rCrr,r,rArMszScalarResult.fetchmanycCs|S)zReturn all scalar values in a sequence. Equivalent to :meth:`_engine.Result.all` except that scalar values, rather than :class:`_engine.Row` objects, are returned. rIr?r,r,rArNszScalarResult.allrcCs|Sr>r@r?r,r,rArszScalarResult.__iter__r'cCs|Sr>rAr?r,r,rArBszScalarResult.__next__r cCs|jddddS)zFetch the first object or ``None`` if no object is present. Equivalent to :meth:`_engine.Result.first` except that scalar values, rather than :class:`_engine.Row` objects, are returned. FrOrPr?r,r,rArQs zScalarResult.firstcCs|jddddS)zReturn at most one object or raise an exception. Equivalent to :meth:`_engine.Result.one_or_none` except that scalar values, rather than :class:`_engine.Row` objects, are returned. TFrOrPr?r,r,rArRs zScalarResult.one_or_nonecCs|jddddS)zReturn exactly one object or raise an exception. Equivalent to :meth:`_engine.Result.one` except that scalar values, rather than :class:`_engine.Row` objects, are returned. TFrOrPr?r,r,rArV s zScalarResult.one)N)N)N)r{r|r}r~rrrrr/rGrJrMrNrrBrQrRrVr,r,r,rAr7s       r7c@sJeZdZdZdZerFd2dddddZd d d d Zd d ddZd3dd dddZ d d ddZ dd ddZ dd ddZ d d ddZ d d ddZdd ddZed d!d"d#d$Zed%d d&d$Zd%d d'd$Zed d(d"d)d*Zed+d d,d*Zd+d d-d*Zed d(d"d.d/Zed%d d0d/Zd%d d1d/ZdS)4 TupleResultaA :class:`_engine.Result` that's typed as returning plain Python tuples instead of rows. Since :class:`_engine.Row` acts like a tuple in every way already, this class is a typing only class, regular :class:`_engine.Result` is still used at runtime. r,NrXrarcCsdS)zIterate through sub-lists of elements of the size given. Equivalent to :meth:`_engine.Result.partitions` except that tuple values, rather than :class:`_engine.Row` objects, are returned. Nr,rr,r,rArG%s zTupleResult.partitionsr r<cCsdS)zFetch one tuple. Equivalent to :meth:`_engine.Result.fetchone` except that tuple values, rather than :class:`_engine.Row` objects, are returned. Nr,r?r,r,rArL1szTupleResult.fetchonerbcCsdS)rcNr,r?r,r,rArJ;szTupleResult.fetchallcCsdS)zFetch many objects. Equivalent to :meth:`_engine.Result.fetchmany` except that tuple values, rather than :class:`_engine.Row` objects, are returned. Nr,rr,r,rArM?szTupleResult.fetchmanycCsdS)zReturn all scalar values in a sequence. Equivalent to :meth:`_engine.Result.all` except that tuple values, rather than :class:`_engine.Row` objects, are returned. Nr,r?r,r,rArNIszTupleResult.allrcCsdSr>r,r?r,r,rArSzTupleResult.__iter__r'cCsdSr>r,r?r,r,rArBUrezTupleResult.__next__cCsdS)zFetch the first object or ``None`` if no object is present. Equivalent to :meth:`_engine.Result.first` except that tuple values, rather than :class:`_engine.Row` objects, are returned. Nr,r?r,r,rArQWs zTupleResult.firstcCsdS)zReturn at most one object or raise an exception. Equivalent to :meth:`_engine.Result.one_or_none` except that tuple values, rather than :class:`_engine.Row` objects, are returned. Nr,r?r,r,rArRbszTupleResult.one_or_nonecCsdS)zReturn exactly one object or raise an exception. Equivalent to :meth:`_engine.Result.one` except that tuple values, rather than :class:`_engine.Row` objects, are returned. Nr,r?r,r,rArVlszTupleResult.onezTupleResult[Tuple[_T]]r)rcCsdSr>r,r?r,r,rArSvszTupleResult.scalar_onercCsdSr>r,r?r,r,rArSyscCsdS)a6Return exactly one scalar result or raise an exception. This is equivalent to calling :meth:`_engine.Result.scalars` and then :meth:`_engine.Result.one`. .. seealso:: :meth:`_engine.Result.one` :meth:`_engine.Result.scalars` Nr,r?r,r,rArS|s rTcCsdSr>r,r?r,r,rArUszTupleResult.scalar_one_or_nonercCsdSr>r,r?r,r,rArUscCsdS)a6Return exactly one or no scalar result. This is equivalent to calling :meth:`_engine.Result.scalars` and then :meth:`_engine.Result.one_or_none`. .. seealso:: :meth:`_engine.Result.one_or_none` :meth:`_engine.Result.scalars` Nr,r?r,r,rArUs cCsdSr>r,r?r,r,rAr szTupleResult.scalarcCsdSr>r,r?r,r,rAr scCsdS)aFetch 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. Nr,r?r,r,rAr s)N)N)r{r|r}r~rrrGrLrJrMrNrrBrQrRrVrrSrUr r,r,r,rArds:        rdc@seZdZdZdZdZedZddddZ d/d d d d dZ dd dddZ d0dddddZ ddddZ ddddZd1ddddd Zddd!d"Zd#dd$d%Zd&dd'd(Zddd)d*Zddd+d,Zd&dd-d.Zd S)2r:zA wrapper for a :class:`_engine.Result` that returns dictionary values rather than :class:`_engine.Row` values. The :class:`_engine.MappingResult` object is acquired by calling the :meth:`_engine.Result.mappings` method. r,T_mappingrresultcCs0||_|j|_|j|_|jr,|jdg|_dSrt)rrrrrcr@rhr,r,rArs zMappingResult.__init__Nr*r#r+cCst|f|_|S)zApply unique filtering to the objects returned by this :class:`_engine.MappingResult`. See :meth:`_engine.Result.unique` for usage details. r,r.r,r,rAr/s zMappingResult.uniquerWr0cGs ||S)z:Establish the columns that should be returned in each row.r2r3r,r,rAr4szMappingResult.columnsrXzIterator[Sequence[RowMapping]]rccs$|j}|||}|r |Vqq qdS)zIterate through sub-lists of elements of the size given. Equivalent to :meth:`_engine.Result.partitions` except that :class:`_engine.RowMapping` values, rather than :class:`_engine.Row` objects, are returned. NrCrDr,r,rArGs  zMappingResult.partitionszSequence[RowMapping]r<cCs|S)z;A synonym for the :meth:`_engine.MappingResult.all` method.rIr?r,r,rArJszMappingResult.fetchallzOptional[RowMapping]cCs||}|tkrdS|SdS)zFetch one object. Equivalent to :meth:`_engine.Result.fetchone` except that :class:`_engine.RowMapping` values, rather than :class:`_engine.Row` objects, are returned. NrKrr,r,rArLs zMappingResult.fetchonecCs |||S)zFetch many objects. Equivalent to :meth:`_engine.Result.fetchmany` except that :class:`_engine.RowMapping` values, rather than :class:`_engine.Row` objects, are returned. rCrr,r,rArMs zMappingResult.fetchmanycCs|S)zReturn all scalar values in a sequence. Equivalent to :meth:`_engine.Result.all` except that :class:`_engine.RowMapping` values, rather than :class:`_engine.Row` objects, are returned. rIr?r,r,rArNs zMappingResult.allzIterator[RowMapping]cCs|Sr>r@r?r,r,rArszMappingResult.__iter__rcCs|Sr>rAr?r,r,rArBszMappingResult.__next__cCs|jddddS)zFetch the first object or ``None`` if no object is present. Equivalent to :meth:`_engine.Result.first` except that :class:`_engine.RowMapping` values, rather than :class:`_engine.Row` objects, are returned. FrOrPr?r,r,rArQ"s zMappingResult.firstcCs|jddddS)zReturn at most one object or raise an exception. Equivalent to :meth:`_engine.Result.one_or_none` except that :class:`_engine.RowMapping` values, rather than :class:`_engine.Row` objects, are returned. TFrOrPr?r,r,rArR/s zMappingResult.one_or_nonecCs|jddddS)zReturn exactly one object or raise an exception. Equivalent to :meth:`_engine.Result.one` except that :class:`_engine.RowMapping` values, rather than :class:`_engine.Row` objects, are returned. TFrOrPr?r,r,rArV;s zMappingResult.one)N)N)N)r{r|r}r~rrre attrgetterrrr/r4rGrJrLrMrNrrBrQrRrVr,r,r,rAr:s$      r:c@sTeZdZUdZded<ddddZdd d d Zd d dddZdd ddZdS)rXaRepresents a :class:`_engine.Result` object in a "frozen" state suitable for caching. The :class:`_engine.FrozenResult` object is returned from the :meth:`_engine.Result.freeze` method of any :class:`_engine.Result` object. A new iterable :class:`_engine.Result` object is generated from a fixed set of data each time the :class:`_engine.FrozenResult` is invoked as a callable:: result = connection.execute(query) frozen = result.freeze() unfrozen_result_one = frozen() for row in unfrozen_result_one: print(row) unfrozen_result_two = frozen() rows = unfrozen_result_two.all() # ... etc .. versionadded:: 1.4 .. seealso:: :ref:`do_orm_execute_re_executing` - example usage within the ORM to implement a result-set cache. :func:`_orm.loading.merge_frozen_result` - ORM function to merge a frozen result back into a :class:`_orm.Session`. rdataz Result[_TP]rgcCs@|j|_|j|_|j|_|jr2t||_n ||_dSr>) rrKrrrrr?rkrJrir,r,rArqs  zFrozenResult.__init__zSequence[Sequence[Any]]r<cCs*|jrdd|jDSdd|jDSdS)NcSsg|] }|gqSr,r,)rnelemr,r,rAr}sz-FrozenResult.rewrite_rows..cSsg|] }t|qSr,rrr,r,rArs)rrkr?r,r,rA rewrite_rows{szFrozenResult.rewrite_rowsrHrW) tuple_datar=cCsDtt}|j|_|j|_|j|_|jr:dd|D|_n||_|S)NcSsg|] }|dqSrr,)rndr,r,rArsz.FrozenResult.with_new_rows..)rX__new__rrrrk)r@rnfrr,r,rA with_new_rowss zFrozenResult.with_new_rowscCs&t|jt|j}|j|_|j|_|Sr>)IteratorResultrrrkrrrir,r,rA__call__szFrozenResult.__call__N) r{r|r}r~rrrmrrrtr,r,r,rArXHs & rXc@seZdZdZdZdZd&dddddd d Zedd d d Zd'ddddddZ dd ddZ dd ddZ dd ddZ d(dddddZ dd d d!Zd)d"dd#d$d%ZdS)*rszA :class:`_engine.Result` that gets data from a Python iterator of :class:`_engine.Row` objects or similar row-like data. .. versionadded:: 1.4 FNr+z(Iterator[_InterimSupportsScalarsRowType]rrD)riteratorrawrcCs||_||_||_||_dSr>)rrurvr)r@rrurvrr,r,rArszIteratorResult.__init__r<cCs|jS)z{Return ``True`` if this :class:`_engine.IteratorResult` has been closed .. versionadded:: 1.4.43 ) _hard_closedr?r,r,rAr&szIteratorResult.closedrrQrkwr=cKsF|r d|_|jdk r*|jjfd|i|tg|_|d|_dS)NTr)rwrvrrruZ_reset_memoizationsr%r@rryr,r,rArs  zIteratorResult._soft_closer cCstddS)NzThis result object is closed.)rZResourceClosedErrorr?r,r,rA_raise_hard_closedsz!IteratorResult._raise_hard_closedr>cCs|jSr>)rur?r,r,rAr?sz IteratorResult._raw_row_iteratorcCs|jr||jSr>)rwr{rur?r,r,rArszIteratorResult._fetchiter_implrrcCs:|jr|t|jt}|tkr2|j|ddS|SdSr^)rwr{nextrurr)r@rrr,r,rArs  zIteratorResult._fetchone_implrcCs,|jr|zt|jWS|XdSr>)rwr{rrrur?r,r,rArs zIteratorResult._fetchall_implrXrcCs"|jr|tt|jd|Srt)rwr{r itertoolsislicerurr,r,rArszIteratorResult._fetchmany_impl)NF)F)F)N)r{r|r}r~rwr%rrr&rr{r?rrrrr,r,r,rArss"     rszIteratorResult[Any]r<cCsttgtgSr>)rsrrr,r,r,rA null_resultsrcsneZdZdZdddddddd d Zed d d ddZdddddfdd Zddddfdd ZZ S)ChunkedIteratorResultaAn :class:`_engine.IteratorResult` that works from an iterator-producing callable. The given ``chunks`` argument is a function that is given a number of rows to return in each chunk, or ``None`` for all rows. The function should then return an un-consumed iterator of lists, each list of the requested size. The function can be called at any time again, in which case it should continue from the same result set but adjust the chunk size as given. .. versionadded:: 1.4 FNr+zBCallable[[Optional[int]], Iterator[Sequence[_InterimRowType[_R]]]]rDr)rchunkssource_supports_scalarsrvdynamic_yield_percCs6||_||_||_||_tj|d|_||_dSr>) rrrrvr}chain from_iterablerur)r@rrrrvrr,r,rArs zChunkedIteratorResult.__init__rlr#r'cCs||_tj|||_|Sr>)rr}rrrrur(r,r,rAr) szChunkedIteratorResult.yield_perrrQrxc s$tjfd|i|dd|_dS)NrcSsgSr>r,r`r,r,rA rez3ChunkedIteratorResult._soft_close..)superrrrzrr,rAr sz!ChunkedIteratorResult._soft_closerXrrcs(|jrtj|||_tj|dSr_)rr}rrrrurrrrr,rAr sz%ChunkedIteratorResult._fetchmany_impl)FNF)F)N) r{r|r}r~rrr)rr __classcell__r,r,rrArs rcsJeZdZUdZdZded<dddfdd Zdd d d d ddZZS)r[zA :class:`_engine.Result` that is merged from any number of :class:`_engine.Result` objects. Returned by the :meth:`_engine.Result.merge` method. .. versionadded:: 1.4 FrXZrowcountr+zSequence[Result[_TP]])rresultscsf||_t|tjdd|D|dj|_|dj|_|dj|_|j j dd|D|_ dS)Ncss|]}|VqdSr>)r?rnrr,r,rAr; sz(MergedResult.__init__..rcSsg|] }|jqSr,)rrr,r,rArG sz)MergedResult.__init__..) _resultsrrr}rrrrrrZ merge_with)r@rrrr,rAr5 s     zMergedResult.__init__rDrrQrxcKs.|jD]}|jfd|i|q|r*d|_dS)NrT)rrr&)r@rryrr,r,rArJ s zMergedResult._soft_close)F) r{r|r}r~r&rrrrr,r,rrAr[( s  r[)N)Xr~ __future__renumrrr}retypingrrrrrr r r r r rrrrrrrrrrrrrZsql.baserrrrr Z util._has_cyr!Z util.typingr"r#Z_py_rowr$Z"sqlalchemy.cyextension.resultproxyZ sql.schemar%Z sql.type_apir&rZ_KeyTyperlrWrTr3Z_RowDataZ _RawRowTyper'r)r*Z_InterimRowTypeZ_InterimSupportsScalarsRowTypeZ_ProcessorsTyperiZ_UniqueFilterTyperr+KeysViewr;rrrrrrrr]r7Z TypingOnlyrdr:rXrsrrr[r,r,r,rAs                                          x" Y1`$PS9