diff options
| author | Federico Caselli <cfederico87@gmail.com> | 2021-08-31 23:03:18 +0200 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-09-17 18:08:42 -0400 |
| commit | 26140c08111da9833dd2eff0b5091494f253db46 (patch) | |
| tree | 61a64b7361ab0890521771a5d185db787482eaaf /lib/sqlalchemy/dialects/sqlite | |
| parent | 204fe7ea206a1b0ab4ae248006f99afd15fa7f72 (diff) | |
| download | sqlalchemy-26140c08111da9833dd2eff0b5091494f253db46.tar.gz | |
Surface driver connection object when using a proxied dialect
Improve the interface used by adapted drivers, like the asyncio ones,
to access the actual connection object returned by the driver.
The :class:`_engine._ConnectionRecord` and
:class:`_engine._ConnectionFairy` now have two new attributes:
* ``dbapi_connection`` always represents a DBAPI compatible
object. For pep-249 drivers, this is the DBAPI connection as it always
has been, previously accessed under the ``.connection`` attribute.
For asyncio drivers that SQLAlchemy adapts into a pep-249 interface,
the returned object will normally be a SQLAlchemy adaption object
called :class:`_engine.AdaptedConnection`.
* ``driver_connection`` always represents the actual connection object
maintained by the third party pep-249 DBAPI or async driver in use.
For standard pep-249 DBAPIs, this will always be the same object
as that of the ``dbapi_connection``. For an asyncio driver, it will be
the underlying asyncio-only connection object.
The ``.connection`` attribute remains available and is now a legacy alias
of ``.dbapi_connection``.
Fixes: #6832
Change-Id: Ib72f97deefca96dce4e61e7c38ba430068d6a82e
Diffstat (limited to 'lib/sqlalchemy/dialects/sqlite')
| -rw-r--r-- | lib/sqlalchemy/dialects/sqlite/aiosqlite.py | 6 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/sqlite/pysqlite.py | 8 |
2 files changed, 9 insertions, 5 deletions
diff --git a/lib/sqlalchemy/dialects/sqlite/aiosqlite.py b/lib/sqlalchemy/dialects/sqlite/aiosqlite.py index eb750b0e7..4319e2661 100644 --- a/lib/sqlalchemy/dialects/sqlite/aiosqlite.py +++ b/lib/sqlalchemy/dialects/sqlite/aiosqlite.py @@ -41,6 +41,7 @@ from .base import SQLiteExecutionContext from .pysqlite import SQLiteDialect_pysqlite from ... import pool from ... import util +from ...engine import AdaptedConnection from ...util.concurrency import await_fallback from ...util.concurrency import await_only @@ -162,7 +163,7 @@ class AsyncAdapt_aiosqlite_ss_cursor(AsyncAdapt_aiosqlite_cursor): return self.await_(self._cursor.fetchall()) -class AsyncAdapt_aiosqlite_connection: +class AsyncAdapt_aiosqlite_connection(AdaptedConnection): await_ = staticmethod(await_only) __slots__ = ("dbapi", "_connection") @@ -328,5 +329,8 @@ class SQLiteDialect_aiosqlite(SQLiteDialect_pysqlite): return super().is_disconnect(e, connection, cursor) + def get_driver_connection(self, connection): + return connection._connection + dialect = SQLiteDialect_aiosqlite diff --git a/lib/sqlalchemy/dialects/sqlite/pysqlite.py b/lib/sqlalchemy/dialects/sqlite/pysqlite.py index 0f96e8830..e9d5d9682 100644 --- a/lib/sqlalchemy/dialects/sqlite/pysqlite.py +++ b/lib/sqlalchemy/dialects/sqlite/pysqlite.py @@ -499,8 +499,8 @@ class SQLiteDialect_pysqlite(SQLiteDialect): ) def set_isolation_level(self, connection, level): - if hasattr(connection, "connection"): - dbapi_connection = connection.connection + if hasattr(connection, "dbapi_connection"): + dbapi_connection = connection.dbapi_connection else: dbapi_connection = connection @@ -521,8 +521,8 @@ class SQLiteDialect_pysqlite(SQLiteDialect): return re.search(a, b) is not None def set_regexp(connection): - if hasattr(connection, "connection"): - dbapi_connection = connection.connection + if hasattr(connection, "dbapi_connection"): + dbapi_connection = connection.dbapi_connection else: dbapi_connection = connection dbapi_connection.create_function( |
