MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / instances

Function instances

lib/sqlalchemy/orm/loading.py:80–309  ·  view source on GitHub ↗

Return a :class:`.Result` given an ORM query context. :param cursor: a :class:`.CursorResult`, generated by a statement which came from :class:`.ORMCompileState` :param context: a :class:`.QueryContext` object :return: a :class:`.Result` object representing ORM results .. ve

(
    cursor: CursorResult[Unpack[TupleAny]], context: QueryContext
)

Source from the content-addressed store, hash-verified

78
79
80def instances(
81 cursor: CursorResult[Unpack[TupleAny]], context: QueryContext
82) -> Result[Unpack[TupleAny]]:
83 """Return a :class:`.Result` given an ORM query context.
84
85 :param cursor: a :class:`.CursorResult`, generated by a statement
86 which came from :class:`.ORMCompileState`
87
88 :param context: a :class:`.QueryContext` object
89
90 :return: a :class:`.Result` object representing ORM results
91
92 .. versionchanged:: 1.4 The instances() function now uses
93 :class:`.Result` objects and has an all new interface.
94
95 """
96
97 context.runid = _new_runid()
98
99 if context.top_level_context:
100 is_top_level = False
101 context.post_load_paths = context.top_level_context.post_load_paths
102 else:
103 is_top_level = True
104 context.post_load_paths = {}
105
106 compile_state = context.compile_state
107 filtered = compile_state._has_mapper_entities
108 single_entity = (
109 not context.load_options._only_return_tuples
110 and len(compile_state._entities) == 1
111 and compile_state._entities[0].supports_single_entity
112 )
113
114 try:
115 process, labels, extra = list(
116 zip(
117 *[
118 query_entity.row_processor(context, cursor)
119 for query_entity in context.compile_state._entities
120 ]
121 )
122 )
123
124 if context.yield_per and (
125 context.loaders_require_buffering
126 or context.loaders_require_uniquing
127 ):
128 raise sa_exc.InvalidRequestError(
129 "Can't use yield_per with eager loaders that require uniquing "
130 "or row buffering, e.g. joinedload() against collections "
131 "or subqueryload(). Consider the selectinload() strategy "
132 "for better flexibility in loading objects."
133 )
134
135 except Exception:
136 with util.safe_reraise():
137 cursor.close()

Callers

nothing calls this directly

Calls 8

yield_perMethod · 0.95
chunksFunction · 0.85
row_processorMethod · 0.45
closeMethod · 0.45
getMethod · 0.45
unionMethod · 0.45

Tested by

no test coverage detected