Using `raw_sql` gives lifetime error
Apply this diff
diff --git i/examples/postgres/migrations/m0005_reference_complex.rs w/examples/postgres/migrations/m0005_reference_complex.rs
index 7ed796a..72264a4 100644
--- i/examples/postgres/migrations/m0005_reference_complex.rs
+++ w/examples/postgres/migrations/m0005_reference_complex.rs
@@ -8,7 +8,7 @@ pub(crate) struct M0005Operation;
#[async_trait::async_trait]
impl Operation<Postgres> for M0005Operation {
async fn up(&self, connection: &mut PgConnection) -> Result<(), Error> {
- sqlx::query("INSERT INTO sample (id, name) VALUES (888, 'complex')")
+ sqlx::raw_sql("INSERT INTO sample (id, name) VALUES (888, 'complex')")
.execute(connection)
.await?;
Ok(())
$ cargo run --example postgres --features="postgres cli"
error: implementation of `Executor` is not general enough
--> examples/postgres/migrations/m0005_reference_complex.rs:10:76
|
10 | async fn up(&self, connection: &mut PgConnection) -> Result<(), Error> {
| ____________________________________________________________________________^
11 | | sqlx::raw_sql("INSERT INTO sample (id, name) VALUES (888, 'complex')")
12 | | .execute(connection)
13 | | .await?;
14 | | Ok(())
15 | | }
| |_____^ implementation of `Executor` is not general enough
|
= note: `Executor<'0>` would have to be implemented for the type `&mut PgConnection`, for any lifetime `'0`...
= note: ...but `Executor<'1>` is actually implemented for the type `&'1 mut PgConnection`, for some specific lifetime `'1`
https://docs.rs/sqlx/0.8.2/sqlx/fn.raw_sql.html
Hmm, doing connection.execute(sqlx::raw_sql(&sql)).await?; rather than sqlx::raw_sql(&sql).execute(connection).await?; seems to work. Any reason not to do that?
sqlx::raw_sql(&sql).execute(connection).await?; is actually calling connection.execute(sqlx::raw_sql(&sql)).await?; internally. They are both same checking why it is actually failing. For now you can use your solution
looks like this is upstream issue of sqlx i have created issue https://github.com/launchbadge/sqlx/issues/3591 at upstream
Thanks!
Closing this PR since upstream have solved main issue according to PR as well as it is not directly related to this project