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

Method connect

lib/sqlalchemy/engine/base.py:3272–3295  ·  view source on GitHub ↗

Return a new :class:`_engine.Connection` object. The :class:`_engine.Connection` acts as a Python context manager, so the typical use of this method looks like:: with engine.connect() as connection: connection.execute(text("insert into table values ('foo

(self)

Source from the content-addressed store, hash-verified

3270 conn._run_ddl_visitor(visitorcallable, element, **kwargs)
3271
3272 def connect(self) -> Connection:
3273 """Return a new :class:`_engine.Connection` object.
3274
3275 The :class:`_engine.Connection` acts as a Python context manager, so
3276 the typical use of this method looks like::
3277
3278 with engine.connect() as connection:
3279 connection.execute(text("insert into table values ('foo')"))
3280 connection.commit()
3281
3282 Where above, after the block is completed, the connection is "closed"
3283 and its underlying DBAPI resources are returned to the connection pool.
3284 This also has the effect of rolling back any transaction that
3285 was explicitly begun or was begun via autobegin, and will
3286 emit the :meth:`_events.ConnectionEvents.rollback` event if one was
3287 started and is still in progress.
3288
3289 .. seealso::
3290
3291 :meth:`_engine.Engine.begin`
3292
3293 """
3294
3295 return self._connection_cls(self)
3296
3297 def raw_connection(self) -> PoolProxiedConnection:
3298 """Return a "raw" DBAPI connection from the connection pool.

Callers 8

beginMethod · 0.95
test_per_engineMethod · 0.95
connectFunction · 0.45
raw_connectionMethod · 0.45
_init_engineMethod · 0.45
_operation_contextMethod · 0.45
decoratedFunction · 0.45

Calls

no outgoing calls

Tested by 1

test_per_engineMethod · 0.76