Return a context that optimizes for multiple operations on a single transaction. This essentially allows connect()/close() to be called if we detected that we're against an :class:`_engine.Engine` and not a :class:`_engine.Connection`.
(self)
| 319 | |
| 320 | @contextlib.contextmanager |
| 321 | def _operation_context(self) -> Generator[Connection, None, None]: |
| 322 | """Return a context that optimizes for multiple operations on a single |
| 323 | transaction. |
| 324 | |
| 325 | This essentially allows connect()/close() to be called if we detected |
| 326 | that we're against an :class:`_engine.Engine` and not a |
| 327 | :class:`_engine.Connection`. |
| 328 | |
| 329 | """ |
| 330 | conn: Connection |
| 331 | if self._op_context_requires_connect: |
| 332 | conn = self.bind.connect() # type: ignore[union-attr] |
| 333 | else: |
| 334 | conn = self.bind # type: ignore[assignment] |
| 335 | try: |
| 336 | yield conn |
| 337 | finally: |
| 338 | if self._op_context_requires_connect: |
| 339 | conn.close() |
| 340 | |
| 341 | @contextlib.contextmanager |
| 342 | def _inspection_context(self) -> Generator[Inspector, None, None]: |