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

the trait `diesel::connection::Connection` is not implemented for `diesel::PgConnection` #1441

Closed
chillcaw opened this Issue Dec 29, 2017 · 6 comments

Comments

Projects
None yet
2 participants
@chillcaw

chillcaw commented Dec 29, 2017

My code is as follows:

extern crate diesel;
extern crate diesel_codegen;
extern crate dotenv;
extern crate r2d2;
extern crate r2d2_diesel;

use diesel::pg::PgConnection;
use r2d2::Pool;
use r2d2_diesel::ConnectionManager;
use dotenv::dotenv;
use std::env;

pub fn connect_db() -> Pool<ConnectionManager<PgConnection>> {
    dotenv().ok();

    let database_url = env::var("DATABASE_URL")
        .expect("DATABASE_URL must be set");
    let manager = ConnectionManager::<PgConnection>::new(database_url);
    Pool::new(manager).expect("Failed to create pool.");
}

I don't understand why the error is even saying diesel::PgConnection, since I'm using diesel::pg::PgConnection.

@Eijebong

This comment has been minimized.

Member

Eijebong commented Dec 29, 2017

You probably have multiple versions of diesel in your dependencies. Check that you're using the right version for r2d2 (it should be the same as the diesel one) and run cargo update.

@chillcaw

This comment has been minimized.

chillcaw commented Dec 29, 2017

Cargo.toml:

diesel = { version = "1.0.0-rc1", features = ["postgres"] }
dotenv = "0.9.0"
diesel_codegen = { version = "0.16.0", features = ["postgres"] }
r2d2-diesel = "1.0.0-rc1"
r2d2 = "0.8.2"
@Eijebong

This comment has been minimized.

Member

Eijebong commented Dec 29, 2017

You shouldn't have diesel_codegen as it was removed in 0.99, see the changelog https://github.com/diesel-rs/diesel/blob/master/CHANGELOG.md

@chillcaw

This comment has been minimized.

chillcaw commented Dec 29, 2017

Ah cool, I will have to look through diesels docs, I have been going by rocket's docs. They must be slightly out of date.

new Cargo.toml for people with the same problem:

diesel = { version = "1.0.0-rc1", features = ["postgres"] }
dotenv = "0.9.0"
r2d2-diesel = "1.0.0-rc1"
r2d2 = "0.8.2"
@Eijebong

This comment has been minimized.

Member

Eijebong commented Dec 29, 2017

I should update the rocket example...

@chillcaw chillcaw closed this Dec 29, 2017

@chillcaw

This comment has been minimized.

chillcaw commented Dec 29, 2017

I have it working with my Rocket project: Rocket Template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment