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
)
| 3384 | return result.rowcount |
| 3385 | |
| 3386 | def _compile_state( |
| 3387 | self, for_statement: bool = False, **kw: Any |
| 3388 | ) -> _ORMCompileState: |
| 3389 | """Create an out-of-compiler ORMCompileState object. |
| 3390 | |
| 3391 | The ORMCompileState object is normally created directly as a result |
| 3392 | of the SQLCompiler.process() method being handed a Select() |
| 3393 | or FromStatement() object that uses the "orm" plugin. This method |
| 3394 | provides a means of creating this ORMCompileState object directly |
| 3395 | without using the compiler. |
| 3396 | |
| 3397 | This method is used only for deprecated cases, which include |
| 3398 | the .from_self() method for a Query that has multiple levels |
| 3399 | of .from_self() in use, as well as the instances() method. It is |
| 3400 | also used within the test suite to generate ORMCompileState objects |
| 3401 | for test purposes. |
| 3402 | |
| 3403 | """ |
| 3404 | |
| 3405 | stmt = self._statement_20(for_statement=for_statement, **kw) |
| 3406 | assert for_statement == stmt._compile_options._for_statement |
| 3407 | |
| 3408 | # this chooses between ORMFromStatementCompileState and |
| 3409 | # ORMSelectCompileState. We could also base this on |
| 3410 | # query._statement is not None as we have the ORM Query here |
| 3411 | # however this is the more general path. |
| 3412 | compile_state_cls = cast( |
| 3413 | _ORMCompileState, |
| 3414 | _ORMCompileState._get_plugin_class_for_plugin(stmt, "orm"), |
| 3415 | ) |
| 3416 | |
| 3417 | return compile_state_cls._create_orm_context( |
| 3418 | stmt, toplevel=True, compiler=None |
| 3419 | ) |
| 3420 | |
| 3421 | def _compile_context(self, for_statement: bool = False) -> QueryContext: |
| 3422 | compile_state = self._compile_state(for_statement=for_statement) |