SeaQL / sea-orm

🐚 An async & dynamic ORM for Rust
https://www.sea-ql.org/SeaORM/
Apache License 2.0
6.97k stars 486 forks source link

Error during build: `std::clone::Clone` is not implemented for `sea_orm::DatabaseConnection` #410

Closed davidsmfreire closed 2 years ago

davidsmfreire commented 2 years ago

In the dependencies of Cargo.toml:

sea-orm = {version = "0.5.0-rc.1", features = ["runtime-async-std-rustls"]}

Relevant code:

use sea_orm::DatabaseConnection;

#[derive(Clone)]
struct AppState {
    conn: DatabaseConnection,
    schema: Schema<Query, EmptyMutation, EmptySubscription>,
}

...

    let conn = sea_orm::Database::connect(&db_url).await.unwrap();
    let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
    let state = AppState { conn, schema };

...

HttpServer::new(move || {
        App::new()
            .app_data(Data::new(state.clone()))
            // .service(web::resource("/").guard(guard::Post()).to(index))
            .service(web::resource("/").guard(guard::Get()).to(index_playground))
    })
    .bind("127.0.0.1:8000")?
    .run()
    .await

Any idea to why I could get this error during build? From the source code and examples I see that the Clone trait IS implemented for DatabaseConnection.

billy1624 commented 2 years ago

Hey @DavidFreire-FEUP, this error occured because you have mock feature enabled. If you don't need mock connection, then you could opt-out from mock feature.

https://github.com/SeaQL/sea-orm/blob/da21e79bb59755800153a1b8d55a1641ffc6c683/src/database/db_connection.rs#L16-L34

davidsmfreire commented 2 years ago

Thanks for the fast response. I had forgot to disable default features! Sorry for the newbie mistake and thank you so much again :)

billy1624 commented 2 years ago

Welcome :P