class Engine(_LegacyEngine):
Known subclasses: sqlalchemy.future.engine.OptionEngine
Connects a _pool.Pool
and
_engine.Dialect
together to provide a
source of database connectivity and behavior.
This is the SQLAlchemy 2.0 version of the ~.engine.Engine
.
An .future.Engine
object is instantiated publicly using the
~sqlalchemy.future.create_engine
function.
Class Method | _future_facade |
Undocumented |
Method | _not_implemented |
Undocumented |
Method | _run_ddl_visitor |
Undocumented |
Method | begin |
Return a _future.Connection object with a transaction begun. |
Method | connect |
Return a new _future.Connection object. |
Class Variable | _is_future |
Undocumented |
Return a _future.Connection
object with a transaction
begun.
Use of this method is similar to that of
_future.Engine.connect
, typically as a context manager, which
will automatically maintain the state of the transaction when the block
ends, either by calling _future.Connection.commit
when the
block succeeds normally, or _future.Connection.rollback
when an
exception is raised, before propagating the exception outwards:
with engine.begin() as connection: connection.execute(text("insert into table values ('foo')"))
See Also
_future.Engine.connect
_future.Connection.begin
Return a new _future.Connection
object.
The _future.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')")) connection.commit()
Where above, after the block is completed, the connection is "closed"
and its underlying DBAPI resources are returned to the connection pool.
This also has the effect of rolling back any transaction that
was explicitly begun or was begun via autobegin, and will
emit the _events.ConnectionEvents.rollback
event if one was
started and is still in progress.
See Also
_future.Engine.begin