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,16 +90,25 @@ 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
103
+ async def fetch_val (
104
+ self ,
105
+ query : typing .Union [ClauseElement , str ],
106
+ values : dict = None ,
107
+ column : typing .Any = 0 ,
108
+ ) -> typing .Any :
109
+ async with self .connection () as connection :
110
+ return await connection .fetch_val (query , values , column = column )
111
+
104
112
async def execute (
105
113
self , query : typing .Union [ClauseElement , str ], values : dict = None
106
114
) -> typing .Any :
@@ -115,7 +123,7 @@ async def execute_many(
115
123
116
124
async def iterate (
117
125
self , query : typing .Union [ClauseElement , str ], values : dict = None
118
- ) -> typing .AsyncGenerator [RowProxy , None ]:
126
+ ) -> typing .AsyncGenerator [typing . Mapping , None ]:
119
127
async with self .connection () as connection :
120
128
async for record in connection .iterate (query , values ):
121
129
yield record
@@ -167,14 +175,23 @@ async def __aexit__(
167
175
168
176
async def fetch_all (
169
177
self , query : typing .Union [ClauseElement , str ], values : dict = None
170
- ) -> typing .Any :
178
+ ) -> typing .List [ typing . Mapping ] :
171
179
return await self ._connection .fetch_all (self ._build_query (query , values ))
172
180
173
181
async def fetch_one (
174
182
self , query : typing .Union [ClauseElement , str ], values : dict = None
175
- ) -> typing .Any :
183
+ ) -> typing .Optional [ typing . Mapping ] :
176
184
return await self ._connection .fetch_one (self ._build_query (query , values ))
177
185
186
+ async def fetch_val (
187
+ self ,
188
+ query : typing .Union [ClauseElement , str ],
189
+ values : dict = None ,
190
+ column : typing .Any = 0 ,
191
+ ) -> typing .Any :
192
+ row = await self ._connection .fetch_one (self ._build_query (query , values ))
193
+ return None if row is None else row [column ]
194
+
178
195
async def execute (
179
196
self , query : typing .Union [ClauseElement , str ], values : dict = None
180
197
) -> typing .Any :
0 commit comments