44
55import aiosqlite
66from sqlalchemy .dialects .sqlite import pysqlite
7+ from sqlalchemy .engine .cursor import CursorResultMetaData
78from sqlalchemy .engine .interfaces import Dialect , ExecutionContext
8- from sqlalchemy .engine .result import ResultMetaData , RowProxy
9+ from sqlalchemy .engine .result import Row
910from sqlalchemy .sql import ClauseElement
1011from sqlalchemy .sql .ddl import DDLElement
11- from sqlalchemy .types import TypeEngine
1212
1313from databases .core import LOG_EXTRA , DatabaseURL
1414from databases .interfaces import ConnectionBackend , DatabaseBackend , TransactionBackend
@@ -92,9 +92,15 @@ async def fetch_all(self, query: ClauseElement) -> typing.List[typing.Mapping]:
9292
9393 async with self ._connection .execute (query , args ) as cursor :
9494 rows = await cursor .fetchall ()
95- metadata = ResultMetaData (context , cursor .description )
95+ metadata = CursorResultMetaData (context , cursor .description )
9696 return [
97- RowProxy (metadata , row , metadata ._processors , metadata ._keymap )
97+ Row (
98+ metadata ,
99+ metadata ._processors ,
100+ metadata ._keymap ,
101+ Row ._default_key_style ,
102+ row ,
103+ )
98104 for row in rows
99105 ]
100106
@@ -106,8 +112,14 @@ async def fetch_one(self, query: ClauseElement) -> typing.Optional[typing.Mappin
106112 row = await cursor .fetchone ()
107113 if row is None :
108114 return None
109- metadata = ResultMetaData (context , cursor .description )
110- return RowProxy (metadata , row , metadata ._processors , metadata ._keymap )
115+ metadata = CursorResultMetaData (context , cursor .description )
116+ return Row (
117+ metadata ,
118+ metadata ._processors ,
119+ metadata ._keymap ,
120+ Row ._default_key_style ,
121+ row ,
122+ )
111123
112124 async def execute (self , query : ClauseElement ) -> typing .Any :
113125 assert self ._connection is not None , "Connection is not acquired"
@@ -129,9 +141,15 @@ async def iterate(
129141 assert self ._connection is not None , "Connection is not acquired"
130142 query , args , context = self ._compile (query )
131143 async with self ._connection .execute (query , args ) as cursor :
132- metadata = ResultMetaData (context , cursor .description )
144+ metadata = CursorResultMetaData (context , cursor .description )
133145 async for row in cursor :
134- yield RowProxy (metadata , row , metadata ._processors , metadata ._keymap )
146+ yield Row (
147+ metadata ,
148+ metadata ._processors ,
149+ metadata ._keymap ,
150+ Row ._default_key_style ,
151+ row ,
152+ )
135153
136154 def transaction (self ) -> TransactionBackend :
137155 return SQLiteTransaction (self )
@@ -158,6 +176,7 @@ def _compile(
158176 compiled ._result_columns ,
159177 compiled ._ordered_columns ,
160178 compiled ._textual_ordered_columns ,
179+ compiled ._loose_column_name_matching ,
161180 )
162181
163182 query_message = compiled .string .replace (" \n " , " " ).replace ("\n " , " " )
0 commit comments