Skip to content

Commit 8d8cdf8

Browse files
committed
fix: RawSql lifetime issues
1 parent 51e8026 commit 8d8cdf8

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

sqlx-core/src/raw_sql.rs

+31-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use either::Either;
2+
use futures_core::future::BoxFuture;
23
use futures_core::stream::BoxStream;
34

45
use crate::database::Database;
@@ -139,26 +140,28 @@ impl<'q, DB: Database> Execute<'q, DB> for RawSql<'q> {
139140
impl<'q> RawSql<'q> {
140141
/// Execute the SQL string and return the total number of rows affected.
141142
#[inline]
142-
pub async fn execute<'e, E>(
143+
pub async fn execute<'e, 'c: 'e, E, DB>(
143144
self,
144145
executor: E,
145-
) -> crate::Result<<E::Database as Database>::QueryResult>
146+
) -> crate::Result<DB::QueryResult>
146147
where
147148
'q: 'e,
148-
E: Executor<'e>,
149+
DB: Database,
150+
E: Executor<'c, Database = DB>,
149151
{
150152
executor.execute(self).await
151153
}
152154

153155
/// Execute the SQL string. Returns a stream which gives the number of rows affected for each statement in the string.
154156
#[inline]
155-
pub fn execute_many<'e, E>(
157+
pub fn execute_many<'e, 'c: 'e, E, DB>(
156158
self,
157159
executor: E,
158-
) -> BoxStream<'e, crate::Result<<E::Database as Database>::QueryResult>>
160+
) -> BoxStream<'e, crate::Result<DB::QueryResult>>
159161
where
160162
'q: 'e,
161-
E: Executor<'e>,
163+
DB: Database,
164+
E: Executor<'c, Database = DB>,
162165
{
163166
executor.execute_many(self)
164167
}
@@ -167,13 +170,14 @@ impl<'q> RawSql<'q> {
167170
///
168171
/// If the string contains multiple statements, their results will be concatenated together.
169172
#[inline]
170-
pub fn fetch<'e, E>(
173+
pub fn fetch<'e, 'c: 'e, E, DB>(
171174
self,
172175
executor: E,
173-
) -> BoxStream<'e, Result<<E::Database as Database>::Row, Error>>
176+
) -> BoxStream<'e, Result<DB::Row, Error>>
174177
where
175178
'q: 'e,
176-
E: Executor<'e>,
179+
DB: Database,
180+
E: Executor<'c, Database = DB>,
177181
{
178182
executor.fetch(self)
179183
}
@@ -183,19 +187,20 @@ impl<'q> RawSql<'q> {
183187
/// For each query in the stream, any generated rows are returned first,
184188
/// then the `QueryResult` with the number of rows affected.
185189
#[inline]
186-
pub fn fetch_many<'e, E>(
190+
pub fn fetch_many<'e, 'c: 'e, E, DB>(
187191
self,
188192
executor: E,
189193
) -> BoxStream<
190194
'e,
191195
Result<
192-
Either<<E::Database as Database>::QueryResult, <E::Database as Database>::Row>,
196+
Either<DB::QueryResult, DB::Row>,
193197
Error,
194198
>,
195199
>
196200
where
197201
'q: 'e,
198-
E: Executor<'e>,
202+
DB: Database,
203+
E: Executor<'c, Database = DB>,
199204
{
200205
executor.fetch_many(self)
201206
}
@@ -208,15 +213,16 @@ impl<'q> RawSql<'q> {
208213
/// To avoid exhausting available memory, ensure the result set has a known upper bound,
209214
/// e.g. using `LIMIT`.
210215
#[inline]
211-
pub async fn fetch_all<'e, E>(
216+
pub fn fetch_all<'e, 'c: 'e, E, DB>(
212217
self,
213218
executor: E,
214-
) -> crate::Result<Vec<<E::Database as Database>::Row>>
219+
) -> BoxFuture<'e, crate::Result<Vec<DB::Row>>>
215220
where
216221
'q: 'e,
217-
E: Executor<'e>,
222+
DB: Database,
223+
E: Executor<'c, Database = DB>,
218224
{
219-
executor.fetch_all(self).await
225+
executor.fetch_all(self)
220226
}
221227

222228
/// Execute the SQL string, returning the first row or [`Error::RowNotFound`] otherwise.
@@ -232,15 +238,16 @@ impl<'q> RawSql<'q> {
232238
///
233239
/// Otherwise, you might want to add `LIMIT 1` to your query.
234240
#[inline]
235-
pub async fn fetch_one<'e, E>(
241+
pub fn fetch_one<'e, 'c: 'e, E, DB>(
236242
self,
237243
executor: E,
238-
) -> crate::Result<<E::Database as Database>::Row>
244+
) -> BoxFuture<'e, crate::Result<DB::Row>>
239245
where
240246
'q: 'e,
241-
E: Executor<'e>,
247+
DB: Database,
248+
E: Executor<'c, Database = DB>,
242249
{
243-
executor.fetch_one(self).await
250+
executor.fetch_one(self)
244251
}
245252

246253
/// Execute the SQL string, returning the first row or [`None`] otherwise.
@@ -256,13 +263,14 @@ impl<'q> RawSql<'q> {
256263
///
257264
/// Otherwise, you might want to add `LIMIT 1` to your query.
258265
#[inline]
259-
pub async fn fetch_optional<'e, E>(
266+
pub async fn fetch_optional<'e, 'c: 'e, E, DB>(
260267
self,
261268
executor: E,
262-
) -> crate::Result<<E::Database as Database>::Row>
269+
) -> crate::Result<DB::Row>
263270
where
264271
'q: 'e,
265-
E: Executor<'e>,
272+
DB: Database,
273+
E: Executor<'c, Database = DB>,
266274
{
267275
executor.fetch_one(self).await
268276
}

0 commit comments

Comments
 (0)