@@ -40,8 +40,7 @@ async def disconnect(self) -> None:
4040 self ._pool = None
4141
4242 def connection (self ) -> "MySQLConnection" :
43- assert self ._pool is not None , "DatabaseBackend is not running"
44- return MySQLConnection (self ._pool , self ._dialect )
43+ return MySQLConnection (self , self ._dialect )
4544
4645
4746class CompilationContext :
@@ -50,18 +49,20 @@ def __init__(self, context: ExecutionContext):
5049
5150
5251class MySQLConnection (ConnectionBackend ):
53- def __init__ (self , pool : aiomysql . pool . Pool , dialect : Dialect ):
54- self ._pool = pool
52+ def __init__ (self , database : MySQLBackend , dialect : Dialect ):
53+ self ._database = database
5554 self ._dialect = dialect
5655 self ._connection = None # type: typing.Optional[aiomysql.Connection]
5756
5857 async def acquire (self ) -> None :
5958 assert self ._connection is None , "Connection is already acquired"
60- self ._connection = await self ._pool .acquire ()
59+ assert self ._database ._pool is not None , "DatabaseBackend is not running"
60+ self ._connection = await self ._database ._pool .acquire ()
6161
6262 async def release (self ) -> None :
6363 assert self ._connection is not None , "Connection is not acquired"
64- await self ._pool .release (self ._connection )
64+ assert self ._database ._pool is not None , "DatabaseBackend is not running"
65+ await self ._database ._pool .release (self ._connection )
6566 self ._connection = None
6667
6768 async def fetch_all (self , query : ClauseElement ) -> typing .List [RowProxy ]:
0 commit comments