6
6
from urllib .parse import SplitResult , parse_qsl , urlsplit
7
7
8
8
from sqlalchemy import text
9
- from sqlalchemy .engine import RowProxy
10
9
from sqlalchemy .sql import ClauseElement
11
10
12
11
from databases .importer import import_from_string
@@ -91,18 +90,21 @@ async def __aexit__(
91
90
92
91
async def fetch_all (
93
92
self , query : typing .Union [ClauseElement , str ], values : dict = None
94
- ) -> typing .List [RowProxy ]:
93
+ ) -> typing .List [typing . Mapping ]:
95
94
async with self .connection () as connection :
96
95
return await connection .fetch_all (query , values )
97
96
98
97
async def fetch_one (
99
98
self , query : typing .Union [ClauseElement , str ], values : dict = None
100
- ) -> RowProxy :
99
+ ) -> typing . Optional [ typing . Mapping ] :
101
100
async with self .connection () as connection :
102
101
return await connection .fetch_one (query , values )
103
102
104
103
async def fetch_val (
105
- self , query : typing .Union [ClauseElement , str ], values : dict = None , column : typing .Any = 0
104
+ self ,
105
+ query : typing .Union [ClauseElement , str ],
106
+ values : dict = None ,
107
+ column : typing .Any = 0 ,
106
108
) -> typing .Any :
107
109
async with self .connection () as connection :
108
110
return await connection .fetch_val (query , values , column = column )
@@ -121,7 +123,7 @@ async def execute_many(
121
123
122
124
async def iterate (
123
125
self , query : typing .Union [ClauseElement , str ], values : dict = None
124
- ) -> typing .AsyncGenerator [RowProxy , None ]:
126
+ ) -> typing .AsyncGenerator [typing . Mapping , None ]:
125
127
async with self .connection () as connection :
126
128
async for record in connection .iterate (query , values ):
127
129
yield record
@@ -173,19 +175,22 @@ async def __aexit__(
173
175
174
176
async def fetch_all (
175
177
self , query : typing .Union [ClauseElement , str ], values : dict = None
176
- ) -> typing .Any :
178
+ ) -> typing .List [ typing . Mapping ] :
177
179
return await self ._connection .fetch_all (self ._build_query (query , values ))
178
180
179
181
async def fetch_one (
180
182
self , query : typing .Union [ClauseElement , str ], values : dict = None
181
- ) -> typing .Any :
183
+ ) -> typing .Optional [ typing . Mapping ] :
182
184
return await self ._connection .fetch_one (self ._build_query (query , values ))
183
185
184
186
async def fetch_val (
185
- self , query : typing .Union [ClauseElement , str ], values : dict = None , column : typing .Any = 0
187
+ self ,
188
+ query : typing .Union [ClauseElement , str ],
189
+ values : dict = None ,
190
+ column : typing .Any = 0 ,
186
191
) -> typing .Any :
187
192
row = await self ._connection .fetch_one (self ._build_query (query , values ))
188
- return row [column ]
193
+ return None if row is None else row [column ]
189
194
190
195
async def execute (
191
196
self , query : typing .Union [ClauseElement , str ], values : dict = None
0 commit comments