MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / begin

Method begin

lib/sqlalchemy/engine/base.py:3200–3226  ·  view source on GitHub ↗

Return a context manager delivering a :class:`_engine.Connection` with a :class:`.Transaction` established. E.g.:: with engine.begin() as conn: conn.execute(text("insert into table (x, y, z) values (1, 2, 3)")) conn.execute(text("my_speci

(self)

Source from the content-addressed store, hash-verified

3198
3199 @contextlib.contextmanager
3200 def begin(self) -> Iterator[Connection]:
3201 """Return a context manager delivering a :class:`_engine.Connection`
3202 with a :class:`.Transaction` established.
3203
3204 E.g.::
3205
3206 with engine.begin() as conn:
3207 conn.execute(text("insert into table (x, y, z) values (1, 2, 3)"))
3208 conn.execute(text("my_special_procedure(5)"))
3209
3210 Upon successful operation, the :class:`.Transaction`
3211 is committed. If an error is raised, the :class:`.Transaction`
3212 is rolled back.
3213
3214 .. seealso::
3215
3216 :meth:`_engine.Engine.connect` - procure a
3217 :class:`_engine.Connection` from
3218 an :class:`_engine.Engine`.
3219
3220 :meth:`_engine.Connection.begin` - start a :class:`.Transaction`
3221 for a particular :class:`_engine.Connection`.
3222
3223 """ # noqa: E501
3224 with self.connect() as conn:
3225 with conn.begin():
3226 yield conn
3227
3228 def _run_ddl_visitor(
3229 self,

Callers 15

_run_ddl_visitorMethod · 0.95
_pg_create_dbFunction · 0.45
_pg_drop_dbFunction · 0.45
do_begin_twophaseMethod · 0.45
_oracle_create_dbFunction · 0.45
_oracle_drop_dbFunction · 0.45
_purge_recyclebinFunction · 0.45
_reap_oracle_dbsFunction · 0.45
_mysql_create_dbFunction · 0.45
_mysql_drop_dbFunction · 0.45

Calls 1

connectMethod · 0.95

Tested by 15

test_ss_cursor_statusMethod · 0.36
test_aliases_and_ssMethod · 0.36
test_integrity_errorMethod · 0.36
test_all_levelsMethod · 0.36
_simple_roundtripMethod · 0.36
test_has_tableMethod · 0.36
test_has_table_schemaMethod · 0.36