MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _operation_context

Method _operation_context

lib/sqlalchemy/engine/reflection.py:321–339  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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]:

Callers 15

_inspection_contextMethod · 0.95
get_schema_namesMethod · 0.95
get_table_namesMethod · 0.95
has_tableMethod · 0.95
has_sequenceMethod · 0.95
has_indexMethod · 0.95
has_schemaMethod · 0.95
get_temp_table_namesMethod · 0.95
get_temp_view_namesMethod · 0.95
get_table_optionsMethod · 0.95
get_view_namesMethod · 0.95

Calls 2

connectMethod · 0.45
closeMethod · 0.45

Tested by 1

check_usageMethod · 0.64