class documentation

class Engine(_LegacyEngine):

Known subclasses: sqlalchemy.future.engine.OptionEngine

View In Hierarchy

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
@classmethod
def _future_facade(self, legacy_engine):

Undocumented

def _not_implemented(self, *arg, **kw):

Undocumented

def _run_ddl_visitor(self, visitorcallable, element, **kwargs):

Undocumented

@util.contextmanager
def begin(self):

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

def connect(self):

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

_is_future: bool =

Undocumented