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

Method _compile_state

lib/sqlalchemy/orm/query.py:3324–3357  ·  view source on GitHub ↗

Create an out-of-compiler ORMCompileState object. The ORMCompileState object is normally created directly as a result of the SQLCompiler.process() method being handed a Select() or FromStatement() object that uses the "orm" plugin. This method provides a means of c

(
        self, for_statement: bool = False, **kw: Any
    )

Source from the content-addressed store, hash-verified

3322 return result.rowcount
3323
3324 def _compile_state(
3325 self, for_statement: bool = False, **kw: Any
3326 ) -> ORMCompileState:
3327 """Create an out-of-compiler ORMCompileState object.
3328
3329 The ORMCompileState object is normally created directly as a result
3330 of the SQLCompiler.process() method being handed a Select()
3331 or FromStatement() object that uses the "orm" plugin. This method
3332 provides a means of creating this ORMCompileState object directly
3333 without using the compiler.
3334
3335 This method is used only for deprecated cases, which include
3336 the .from_self() method for a Query that has multiple levels
3337 of .from_self() in use, as well as the instances() method. It is
3338 also used within the test suite to generate ORMCompileState objects
3339 for test purposes.
3340
3341 """
3342
3343 stmt = self._statement_20(for_statement=for_statement, **kw)
3344 assert for_statement == stmt._compile_options._for_statement
3345
3346 # this chooses between ORMFromStatementCompileState and
3347 # ORMSelectCompileState. We could also base this on
3348 # query._statement is not None as we have the ORM Query here
3349 # however this is the more general path.
3350 compile_state_cls = cast(
3351 ORMCompileState,
3352 ORMCompileState._get_plugin_class_for_plugin(stmt, "orm"),
3353 )
3354
3355 return compile_state_cls._create_orm_context(
3356 stmt, toplevel=True, compiler=None
3357 )
3358
3359 def _compile_context(self, for_statement: bool = False) -> QueryContext:
3360 compile_state = self._compile_state(for_statement=for_statement)

Callers 15

statementMethod · 0.95
instancesMethod · 0.95
_compile_contextMethod · 0.95
_final_statementMethod · 0.80
test_query_threeMethod · 0.80
_assertMethod · 0.80
test_entityMethod · 0.80
test_colsMethod · 0.80
_assert_path_resultMethod · 0.80

Calls 4

_statement_20Method · 0.95
castFunction · 0.85
_create_orm_contextMethod · 0.45

Tested by 15

test_query_threeMethod · 0.64
_assertMethod · 0.64
test_entityMethod · 0.64
test_colsMethod · 0.64
_assert_path_resultMethod · 0.64
_assert_optionMethod · 0.64