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

Update example/s to dereference PoolConnection #2368

Open
cycraig opened this issue Feb 22, 2023 · 3 comments · May be fixed by #3554
Open

Update example/s to dereference PoolConnection #2368

cycraig opened this issue Feb 22, 2023 · 3 comments · May be fixed by #3554
Labels

Comments

@cycraig
Copy link
Contributor

cycraig commented Feb 22, 2023

Bug Description

Edit: the one SQLite example was not updated to dereference PoolConnection, leading to this error. It should just be updated to use .execute(&mut *conn).

The execute/fetch_one/fetch_all etc. functions throw compile-time errors when using PoolConnection on main. Edit: they just need to be dereferenced.

I'm guessing this is known, and is why the examples were removed from the workspace Cargo.toml for the 0.7.0-alpha.1 merge to main.

Minimal Reproduction

The SQLite TODOs example in the repository.

let mut conn: PoolConnection<Sqlite> = pool.acquire().await?;

// Insert the task, then obtain the ID of this row
let id = sqlx::query!(
  r#"
INSERT INTO todos ( description )
VALUES ( ?1 )
  "#,
  description
)
.execute(&mut conn)
.await?
.last_insert_rowid();

Error:

error[E0277]: the trait bound `&mut sqlx::pool::PoolConnection<Sqlite>: Executor<'_>` is not satisfied
   --> examples/sqlite/todos/src/main.rs:60:14
    |
60  |     .execute(&mut conn)
    |      ------- ^^^^^^^^^ the trait `Executor<'_>` is not implemented for `&mut sqlx::pool::PoolConnection<Sqlite>`
    |      |
    |      required by a bound introduced by this call
    |
    = help: the following other types implement trait `Executor<'c>`:
              <&'c mut AnyConnection as Executor<'c>>
              <&'c mut SqliteConnection as Executor<'c>>
              <&Pool<DB> as Executor<'p>>
note: required by a bound in `Query::<'q, DB, A>::execute`
   --> /sqlx/sqlx-core/src/query.rs:151:12
    |
151 |         E: Executor<'c, Database = DB>,
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Query::<'q, DB, A>::execute`

Info

  • SQLx version: 0.7.0-alpha.1 (main branch, commit f05c884)
  • SQLx features enabled: ["sqlite", "runtime-tokio-native-tls"]
  • Database server and version: SQLite
  • Operating system: MacOS
  • rustc --version: rustc 1.67.1 (d5a82bbd2 2023-02-07)
@cycraig cycraig added the bug label Feb 22, 2023
@FSMaxB
Copy link
Contributor

FSMaxB commented Feb 22, 2023

  • The Executor impls for Transaction and PoolConnection have been deleted because they cannot exist in the new crate architecture without rewriting the Executor trait entirely.

    • To fix this breakage, simply add a dereference where an impl Executor is expected, as they both dereference to the inner connection type which will still implement it:
      • &mut transaction -> &mut *transaction
      • &mut connection -> &mut *connection

From #2039 (comment)

@cycraig cycraig changed the title Executor not implemented for PoolConnection Update example/s to dereference PoolConnection Feb 22, 2023
@cycraig
Copy link
Contributor Author

cycraig commented Feb 22, 2023

Thanks, this is merely an "update example" issue then!

@abonander
Copy link
Collaborator

Yeah, I didn't update the examples for the alpha because I just wanted to get CI passing and get the release out. I forgot how many we had, heh. That'll be part of preparing the full release which I will try to get out next week if nothing else comes up.

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

Successfully merging a pull request may close this issue.

3 participants