digital-society-coop / axum-sqlx-tx

Request-scoped sqlx transactions for axum
MIT License
51 stars 11 forks source link

trait bound `Postgres: sqlx_core::database::Database` is not satisfied #10

Closed PXNX closed 2 years ago

PXNX commented 2 years ago

When running this repo, I get the following error:

error[E0277]: the trait bound `Postgres: sqlx_core::database::Database` is not satisfied
  --> src/main.rs:51:13
   |
51 |     mut tx: Tx<Postgres>,
   |             ^^^^^^^^^^^^ the trait `sqlx_core::database::Database` is not implemented for `Postgres`
   |
   = help: the trait `sqlx_core::database::Database` is implemented for `sqlx_core::postgres::database::Postgres`
note: required by a bound in `Tx`
  --> /home/nyx/.cargo/registry/src/github.com-1ecc6299db9ec823/axum-sqlx-tx-0.3.0/src/tx.rs:75:19
   |
75 | pub struct Tx<DB: sqlx::Database, E = Error>(Lease<sqlx::Transaction<'static, DB>>, PhantomData<E>);
   |                   ^^^^^^^^^^^^^^ required by this bound in `Tx`

Is this a bug or something I can solve myself? If the latter, how may I do that?

connec commented 2 years ago

Reopening until there's a release, which should be very soon...

connec commented 2 years ago

axum-sqlx-tx@0.4.0 is now released. This will likely fix your issue.

For context, this issue occurs because the version of SQLx used in your crate was different from the one used in axum-sqlx-tx. The compiler therefore sees two different sqlx_core::database::Database traits, with the same name, hence the confusing error message.

I'm not sure if there's a better way to manage dependencies when they're part of the public API. It'll be particularly relevant if SQLx is planning to make more frequent breaking changes!