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