1
1
use either:: Either ;
2
+ use futures_core:: future:: BoxFuture ;
2
3
use futures_core:: stream:: BoxStream ;
3
4
4
5
use crate :: database:: Database ;
@@ -139,26 +140,25 @@ impl<'q, DB: Database> Execute<'q, DB> for RawSql<'q> {
139
140
impl < ' q > RawSql < ' q > {
140
141
/// Execute the SQL string and return the total number of rows affected.
141
142
#[ inline]
142
- pub async fn execute < ' e , E > (
143
- self ,
144
- executor : E ,
145
- ) -> crate :: Result < <E :: Database as Database >:: QueryResult >
143
+ pub async fn execute < ' e , E , DB > ( self , executor : E ) -> crate :: Result < DB :: QueryResult >
146
144
where
147
145
' q : ' e ,
148
- E : Executor < ' e > ,
146
+ DB : Database ,
147
+ E : Executor < ' e , Database = DB > ,
149
148
{
150
149
executor. execute ( self ) . await
151
150
}
152
151
153
152
/// Execute the SQL string. Returns a stream which gives the number of rows affected for each statement in the string.
154
153
#[ inline]
155
- pub fn execute_many < ' e , E > (
154
+ pub fn execute_many < ' e , E , DB > (
156
155
self ,
157
156
executor : E ,
158
- ) -> BoxStream < ' e , crate :: Result < < E :: Database as Database > :: QueryResult > >
157
+ ) -> BoxStream < ' e , crate :: Result < DB :: QueryResult > >
159
158
where
160
159
' q : ' e ,
161
- E : Executor < ' e > ,
160
+ DB : Database ,
161
+ E : Executor < ' e , Database = DB > ,
162
162
{
163
163
executor. execute_many ( self )
164
164
}
@@ -167,13 +167,11 @@ impl<'q> RawSql<'q> {
167
167
///
168
168
/// If the string contains multiple statements, their results will be concatenated together.
169
169
#[ inline]
170
- pub fn fetch < ' e , E > (
171
- self ,
172
- executor : E ,
173
- ) -> BoxStream < ' e , Result < <E :: Database as Database >:: Row , Error > >
170
+ pub fn fetch < ' e , E , DB > ( self , executor : E ) -> BoxStream < ' e , Result < DB :: Row , Error > >
174
171
where
175
172
' q : ' e ,
176
- E : Executor < ' e > ,
173
+ DB : Database ,
174
+ E : Executor < ' e , Database = DB > ,
177
175
{
178
176
executor. fetch ( self )
179
177
}
@@ -183,19 +181,14 @@ impl<'q> RawSql<'q> {
183
181
/// For each query in the stream, any generated rows are returned first,
184
182
/// then the `QueryResult` with the number of rows affected.
185
183
#[ inline]
186
- pub fn fetch_many < ' e , E > (
184
+ pub fn fetch_many < ' e , E , DB > (
187
185
self ,
188
186
executor : E ,
189
- ) -> BoxStream <
190
- ' e ,
191
- Result <
192
- Either < <E :: Database as Database >:: QueryResult , <E :: Database as Database >:: Row > ,
193
- Error ,
194
- > ,
195
- >
187
+ ) -> BoxStream < ' e , Result < Either < DB :: QueryResult , DB :: Row > , Error > >
196
188
where
197
189
' q : ' e ,
198
- E : Executor < ' e > ,
190
+ DB : Database ,
191
+ E : Executor < ' e , Database = DB > ,
199
192
{
200
193
executor. fetch_many ( self )
201
194
}
@@ -208,15 +201,13 @@ impl<'q> RawSql<'q> {
208
201
/// To avoid exhausting available memory, ensure the result set has a known upper bound,
209
202
/// e.g. using `LIMIT`.
210
203
#[ inline]
211
- pub async fn fetch_all < ' e , E > (
212
- self ,
213
- executor : E ,
214
- ) -> crate :: Result < Vec < <E :: Database as Database >:: Row > >
204
+ pub fn fetch_all < ' e , E , DB > ( self , executor : E ) -> BoxFuture < ' e , crate :: Result < Vec < DB :: Row > > >
215
205
where
216
206
' q : ' e ,
217
- E : Executor < ' e > ,
207
+ DB : Database ,
208
+ E : Executor < ' e , Database = DB > ,
218
209
{
219
- executor. fetch_all ( self ) . await
210
+ executor. fetch_all ( self )
220
211
}
221
212
222
213
/// Execute the SQL string, returning the first row or [`Error::RowNotFound`] otherwise.
@@ -232,15 +223,13 @@ impl<'q> RawSql<'q> {
232
223
///
233
224
/// Otherwise, you might want to add `LIMIT 1` to your query.
234
225
#[ inline]
235
- pub async fn fetch_one < ' e , E > (
236
- self ,
237
- executor : E ,
238
- ) -> crate :: Result < <E :: Database as Database >:: Row >
226
+ pub fn fetch_one < ' e , E , DB > ( self , executor : E ) -> BoxFuture < ' e , crate :: Result < DB :: Row > >
239
227
where
240
228
' q : ' e ,
241
- E : Executor < ' e > ,
229
+ DB : Database ,
230
+ E : Executor < ' e , Database = DB > ,
242
231
{
243
- executor. fetch_one ( self ) . await
232
+ executor. fetch_one ( self )
244
233
}
245
234
246
235
/// Execute the SQL string, returning the first row or [`None`] otherwise.
@@ -256,13 +245,11 @@ impl<'q> RawSql<'q> {
256
245
///
257
246
/// Otherwise, you might want to add `LIMIT 1` to your query.
258
247
#[ inline]
259
- pub async fn fetch_optional < ' e , E > (
260
- self ,
261
- executor : E ,
262
- ) -> crate :: Result < <E :: Database as Database >:: Row >
248
+ pub async fn fetch_optional < ' e , E , DB > ( self , executor : E ) -> crate :: Result < DB :: Row >
263
249
where
264
250
' q : ' e ,
265
- E : Executor < ' e > ,
251
+ DB : Database ,
252
+ E : Executor < ' e , Database = DB > ,
266
253
{
267
254
executor. fetch_one ( self ) . await
268
255
}
0 commit comments