MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / merge_result

Method merge_result

lib/sqlalchemy/orm/query.py:3003–3035  ·  view source on GitHub ↗

Merge a result into this :class:`_query.Query` object's Session. Given an iterator returned by a :class:`_query.Query` of the same structure as this one, return an identical iterator of results, with all mapped instances merged into the session using :meth:`.Session.

(
        self,
        iterator: Union[
            FrozenResult[Any], Iterable[Sequence[Any]], Iterable[object]
        ],
        load: bool = True,
    )

Source from the content-addressed store, hash-verified

3001 enable_warnings=False, # warnings occur via loading.merge_result
3002 )
3003 def merge_result(
3004 self,
3005 iterator: Union[
3006 FrozenResult[Any], Iterable[Sequence[Any]], Iterable[object]
3007 ],
3008 load: bool = True,
3009 ) -> Union[FrozenResult[Any], Iterable[Any]]:
3010 """Merge a result into this :class:`_query.Query` object's Session.
3011
3012 Given an iterator returned by a :class:`_query.Query`
3013 of the same structure
3014 as this one, return an identical iterator of results, with all mapped
3015 instances merged into the session using :meth:`.Session.merge`. This
3016 is an optimized method which will merge all mapped instances,
3017 preserving the structure of the result rows and unmapped columns with
3018 less method overhead than that of calling :meth:`.Session.merge`
3019 explicitly for each value.
3020
3021 The structure of the results is determined based on the column list of
3022 this :class:`_query.Query` - if these do not correspond,
3023 unchecked errors
3024 will occur.
3025
3026 The 'load' argument is the same as that of :meth:`.Session.merge`.
3027
3028 For an example of how :meth:`_query.Query.merge_result` is used, see
3029 the source code for the example :ref:`examples_caching`, where
3030 :meth:`_query.Query.merge_result` is used to efficiently restore state
3031 from a cache back into a target :class:`.Session`.
3032
3033 """
3034
3035 return loading.merge_result(self, iterator, load)
3036
3037 def exists(self) -> Exists:
3038 """A convenience method that turns a query into an EXISTS subquery

Callers 5

test_single_entityMethod · 0.80
test_single_columnMethod · 0.80
test_none_entityMethod · 0.80

Calls

no outgoing calls

Tested by 5

test_single_entityMethod · 0.64
test_single_columnMethod · 0.64
test_none_entityMethod · 0.64