Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using raw_sql gives lifetime error #38

Open
SimenB opened this issue Nov 5, 2024 · 4 comments
Open

Using raw_sql gives lifetime error #38

SimenB opened this issue Nov 5, 2024 · 4 comments

Comments

@SimenB
Copy link

SimenB commented Nov 5, 2024

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

@SimenB
Copy link
Author

SimenB commented Nov 5, 2024

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?

@iamsauravsharma
Copy link
Owner

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

@iamsauravsharma iamsauravsharma changed the title Using raw_sql gives lifetime warnings Using raw_sql gives lifetime error Nov 5, 2024
@iamsauravsharma
Copy link
Owner

looks like this is upstream issue of sqlx i have created issue launchbadge/sqlx#3591 at upstream

@SimenB
Copy link
Author

SimenB commented Nov 5, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants