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

Missing impls for Timestamptz => NaiveDateTime #539

Closed
fluxxu opened this Issue Dec 9, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@fluxxu
Contributor

fluxxu commented Dec 9, 2016

Compile error:

error[E0277]: the trait bound `chrono::NaiveDateTime: diesel::types::FromSqlRow<diesel::types::Timestamptz, _>` is not satisfied
  --> src\auth/mod.rs:38:8
   |
38 |       .load::<UserEntry>(self.db.get())
   |        ^^^^ the trait `diesel::types::FromSqlRow<diesel::types::Timestamptz, _>` is not implemented for `chrono::NaiveDateTime`
   |
   = help: the following implementations were found:
   = help:   <chrono::NaiveDateTime as diesel::types::FromSqlRow<diesel::types::Timestamp, DB>>
   = note: required because of the requirements on the impl of `diesel::types::FromSqlRow<(diesel::types::Integer, diesel::types::Text, diesel::types::Text, diesel::types::Timestamptz, diesel::types::Timestamptz), _>` for `(i32, std::string::String, std::string::String, chrono::NaiveDateTime, chrono::NaiveDateTime)`
   = note: required because of the requirements on the impl of `diesel::Queryable<(diesel::types::Integer, diesel::types::Text, diesel::types::Text, diesel::types::Timestamptz, diesel::types::Timestamptz), _>` for `auth::UserEntry`

If I change NaiveDateTime to DateTime then it compiles.
I found there is an impl here:
https://github.com/diesel-rs/diesel/blob/master/diesel/src/pg/types/date_and_time/chrono.rs#L61
Don't know why rustc can't find it...

rustc 1.13.0 (2c6933acc 2016-11-07)

Thanks.

Function:

  pub fn get_all_users(&self) -> Result<Vec<UserEntry>> {
    use self::user::dsl::*;
    user.select((id, name, email, created_at, updated_at))
      .load::<UserEntry>(self.conn)
      .map_err(|err| err.into())
  }

Table:

CREATE TABLE "user" (
  "id" serial4 NOT NULL,
  "name" varchar(255) NOT NULL,
  "email" varchar(255) NOT NULL,
  "password" varchar(255) NOT NULL,
  "created_at" timestamptz DEFAULT now() NOT NULL,
  "updated_at" timestamptz DEFAULT now() NOT NULL,
  PRIMARY KEY ("id"),
  CONSTRAINT "email" UNIQUE ("email")
);

Struct:

#[derive(Debug, Queryable, Identifiable)]
#[table_name = "user"]
pub struct UserEntry {
    pub id: i32,
    pub name: String,
    pub email: String,
    pub created_at: NaiveDateTime,
    pub updated_at: NaiveDateTime,
}

@fluxxu fluxxu changed the title from missing impls for NaiveDateTime to missing impls for Timestamptz => NaiveDateTime Dec 9, 2016

@fluxxu fluxxu changed the title from missing impls for Timestamptz => NaiveDateTime to Missing impls for Timestamptz => NaiveDateTime Dec 9, 2016

@killercup

This comment has been minimized.

Member

killercup commented Dec 9, 2016

Did you enable the "chrono" feature in your Cargo.toml for the diesel dependency? The docs say the impl is only available when it's enabled.

@fluxxu

This comment has been minimized.

Contributor

fluxxu commented Dec 10, 2016

@killercup
Yes I did:

[dependencies]
chrono = "0.2.25"
diesel = { version = "0.9.0", features = ["chrono"] }
diesel_codegen = { version = "0.9.0", features = ["postgres"] }

And DateTime also come from chrono crate but it works.

@sgrif sgrif closed this in 47ccc5f Dec 10, 2016

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