:connectstring: mysql+aiomysql://user:password@host:port/dbname[?key=value&key=value...]
:url: https://github.com/aio-libs/aiomysql
-.. warning:: The aiomysql dialect is not currently tested as part of
- SQLAlchemy’s continuous integration. As of September, 2021 the driver
- appears to be unmaintained and no longer functions for Python version 3.10,
- and additionally depends on a significantly outdated version of PyMySQL.
- Please refer to the :ref:`asyncmy` dialect for current MySQL/MariaDB asyncio
- functionality.
-
The aiomysql dialect is SQLAlchemy's second Python asyncio dialect.
Using a special asyncio mediation layer, the aiomysql dialect is usable
self._connection = adapt_connection._connection
self.await_ = adapt_connection.await_
- cursor = self._connection.cursor()
+ cursor = self._connection.cursor(adapt_connection.dbapi.Cursor)
# see https://github.com/aio-libs/aiomysql/issues/543
self._cursor = self.await_(cursor.__aenter__())
async def _execute_async(self, operation, parameters):
async with self._adapt_connection._execute_mutex:
- if parameters is None:
- result = await self._cursor.execute(operation)
- else:
- result = await self._cursor.execute(operation, parameters)
+ result = await self._cursor.execute(operation, parameters)
if not self.server_side:
# aiomysql has a "fake" async result, so we have to pull it out
self._connection = adapt_connection._connection
self.await_ = adapt_connection.await_
- cursor = self._connection.cursor(
- adapt_connection.dbapi.aiomysql.SSCursor
- )
+ cursor = self._connection.cursor(adapt_connection.dbapi.SSCursor)
self._cursor = self.await_(cursor.__aenter__())
self.pymysql = pymysql
self.paramstyle = "format"
self._init_dbapi_attributes()
+ self.Cursor, self.SSCursor = self._init_cursors_subclasses()
def _init_dbapi_attributes(self):
for name in (
await_only(creator_fn(*arg, **kw)),
)
+ def _init_cursors_subclasses(self):
+ # suppress unconditional warning emitted by aiomysql
+ class Cursor(self.aiomysql.Cursor):
+ async def _show_warnings(self, conn):
+ pass
+
+ class SSCursor(self.aiomysql.SSCursor):
+ async def _show_warnings(self, conn):
+ pass
+
+ return Cursor, SSCursor
+
class MySQLDialect_aiomysql(MySQLDialect_pymysql):
driver = "aiomysql"
:connectstring: mysql+asyncmy://user:password@host:port/dbname[?key=value&key=value...]
:url: https://github.com/long2ice/asyncmy
-.. note:: The asyncmy dialect as of September, 2021 was added to provide
- MySQL/MariaDB asyncio compatibility given that the :ref:`aiomysql` database
- driver has become unmaintained, however asyncmy is itself very new.
-
Using a special asyncio mediation layer, the asyncmy dialect is usable
as the backend for the :ref:`SQLAlchemy asyncio <asyncio_toplevel>`
extension package.
mysql: mysql
mysql: pymysql
mysql: asyncmy
+ mysql: aiomysql
oracle: oracle
oracle: oracle_oracledb
mysql: MYSQL={env:TOX_MYSQL:--db mysql}
mysql: EXTRA_MYSQL_DRIVERS={env:EXTRA_MYSQL_DRIVERS:--dbdriver mysqldb --dbdriver pymysql}
- py{3,37,38,39,310,311}-mysql: EXTRA_MYSQL_DRIVERS={env:EXTRA_MYSQL_DRIVERS:--dbdriver mysqldb --dbdriver pymysql --dbdriver asyncmy}
+ py{3,37,38,39,310,311}-mysql: EXTRA_MYSQL_DRIVERS={env:EXTRA_MYSQL_DRIVERS:--dbdriver mysqldb --dbdriver pymysql --dbdriver asyncmy --dbdriver aiomysql}
mssql: MSSQL={env:TOX_MSSQL:--db mssql}
py{3,37,38,39,310,311}-mssql: EXTRA_MSSQL_DRIVERS={env:EXTRA_MSSQL_DRIVERS:--dbdriver pyodbc --dbdriver pymssql}