MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / connect

Method connect

lib/sqlalchemy/engine/base.py:3237–3260  ·  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

3235 conn._run_ddl_visitor(visitorcallable, element, **kwargs)
3236
3237 def connect(self) -> Connection:
3238 """Return a new :class:`_engine.Connection` object.
3239
3240 The :class:`_engine.Connection` acts as a Python context manager, so
3241 the typical use of this method looks like::
3242
3243 with engine.connect() as connection:
3244 connection.execute(text("insert into table values ('foo')"))
3245 connection.commit()
3246
3247 Where above, after the block is completed, the connection is "closed"
3248 and its underlying DBAPI resources are returned to the connection pool.
3249 This also has the effect of rolling back any transaction that
3250 was explicitly begun or was begun via autobegin, and will
3251 emit the :meth:`_events.ConnectionEvents.rollback` event if one was
3252 started and is still in progress.
3253
3254 .. seealso::
3255
3256 :meth:`_engine.Engine.begin`
3257
3258 """
3259
3260 return self._connection_cls(self)
3261
3262 def raw_connection(self) -> PoolProxiedConnection:
3263 """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