]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
introduce "autobegin" concept for Connection
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 26 Mar 2020 21:26:57 +0000 (17:26 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 26 Mar 2020 21:26:57 +0000 (17:26 -0400)
because engine.connect() and engine.begin() should feature
identical internal behavior, with the sole exception that
one rolls back and the end and the other commits at the end,
while also supporting execution options like transaction isolation level
at the connection level, include that engine.connect() will
return a connection that uses autobegin in the same way as the
session will.   This is solely to support the "begin" event
noting that a transaction is begun which is tracked on the
connection.    Behavior and design should be very similar to that
of the ORM session and "Transaction" should no longer be a very
explicit object.

Change-Id: I9c317d242ca7a435de0f17b1618355e29a10d1bc

doc/build/changelog/migration_20.rst

index f5910ae5e74ff94477888542d310e9beec407fe5..e61c63bf995c3292202dc227ad80eda8fff21fc7 100644 (file)
@@ -210,7 +210,13 @@ method::
         conn.execute(text("some other SQL"))
         conn.rollback()
 
-For the ORM, the above two patterns are already more or less how the
+Above, the ``engine.connect()`` method will return a :class:`.Connection` that
+features **autobegin**, meaning the ``begin()`` event is emitted when the
+execute method is first used (note however that there is no actual "BEGIN" in
+the Python DBAPI).   This is the same as how the ORM :class:`.Session` will
+work also and is not too dissimilar from how things work now.
+
+For the ORM, the above patterns are already more or less how the
 :class:`.Session` is used already::
 
     session = sessionmaker()
@@ -279,7 +285,8 @@ driver.
 To use a connection in autocommit mode::
 
    with engine.connect().execution_options(isolation_level="AUTOCOMMIT") as conn:
-       result = conn.execute(stmt)
+       conn.execute(text("CREATE DATABASE foobar"))
+
 
 The above code is already available in current SQLAlchemy releases.   Driver
 support is available for PostgreSQL, MySQL, SQL Server, and newer releases