purton-tech / rust-on-nails

Full stack web architecture for Rust
https://rust-on-nails.com
MIT License
364 stars 33 forks source link

Unable to setup database connection #53

Closed anshul-raman closed 1 year ago

anshul-raman commented 1 year ago

After going through the steps shown on the website, i'm getting the following error when running cargo test:


error[E0277]: the trait bound `deadpool::managed::Object<Manager>: cornucopia_async::GenericClient` is not satisfied
  --> crates/db/src/lib.rs:62:19
   |
62 |             .bind(&client)
   |              ---- ^^^^^^^ the trait `cornucopia_async::GenericClient` is not implemented for `deadpool::managed::Object<Manager>`
   |              |
   |              required by a bound introduced by this call
   |
   = help: the following other types implement trait `cornucopia_async::GenericClient`:
             deadpool_postgres::Transaction<'_>
             tokio_postgres::Client
             deadpool::managed::Object<deadpool_postgres::Manager>
             tokio_postgres::Transaction<'_>
note: required by a bound in `queries::users::GetUsersStmt::bind`
  --> /Users/anshulraman/prog/personal/codesnip/target/debug/build/db-7008ace27bbbd20f/out/cornucopia.rs:60:38
   |
60 | GetUsersStmt { pub fn bind < 'a, C : GenericClient, >
   |                                      ^^^^^^^^^^^^^ required by this bound in `GetUsersStmt::bind`

error[E0599]: the method `all` exists for struct `UserQuery<'_, Object<Manager>, User, 0>`, but its trait bounds were not satisfied
   --> crates/db/src/lib.rs:63:14
    |
61  |           let users = crate::queries::users::get_users()
    |  _____________________-
62  | |             .bind(&client)
63  | |             .all()
    | |             -^^^ method cannot be called on `UserQuery<'_, Object<Manager>, User, 0>` due to unsatisfied trait bounds
    | |_____________|
    | 
    |
   ::: /Users/anshulraman/prog/personal/codesnip/target/debug/build/db-7008ace27bbbd20f/out/cornucopia.rs:15:2
    |
15  |   }pub struct UserQuery < 'a, C : GenericClient, T, const N : usize >
    |    ------------------------------------------------------------------ method `all` not found for this struct
    |
   ::: /Users/anshulraman/.cargo/registry/src/index.crates.io-6f17d22bba15001f/deadpool-0.10.0/src/managed/mod.rs:126:1
    |
126 |   pub struct Object<M: Manager> {
    |   ----------------------------- doesn't satisfy `_: GenericClient`
    |
note: trait bound `deadpool::managed::Object<Manager>: cornucopia_async::GenericClient` was not satisfied
   --> /Users/anshulraman/prog/personal/codesnip/target/debug/build/db-7008ace27bbbd20f/out/cornucopia.rs:22:11
    |
21  | } impl < 'a, C, T : 'a, const N : usize > UserQuery < 'a, C, T, N >
    |                                           -------------------------
22  | where C : GenericClient
    |           ^^^^^^^^^^^^^ unsatisfied trait bound introduced here```
LouisXhaferi commented 1 year ago

I stumbled upon the same issue. This is due to an incompatibility between deadpool-postgres 0.11.0 and Cornucopia.

To @anshul-raman If you adjust your deadpool-postgres version to be 0.10.5, it will work again.

To maintainers and contributors It is probably worth adding that note to the tutorials, as cargo of course installs the newest version by default.

9876691 commented 1 year ago

@LouisXhaferi Thanks will do.

9876691 commented 1 year ago

Documents updated