I'm attempting to use a wrapper around chrono::DateTime<Utc> in a struct that I'm using as a model for a database row. I am using a wrapper so that I can implement other traits on it. However, I get the following error:

error[E0277]: the trait bound `DateTimeUtcForm: diesel::Expression` is not satisfied
  --> domain/src/models/post.rs:20:9
   |
20 |     pub time_taken: DateTimeUtcForm,
   |         ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `DateTimeUtcForm`, which is required by `DateTimeUtcForm: AsExpression<diesel::sql_types::Timestamptz>`
   |
   = help: the following other types implement trait `diesel::Expression`:
             &'a T
             (T0, T1)
             (T0, T1, T2)
             (T0, T1, T2, T3)
             (T0, T1, T2, T3, T4)
             (T0, T1, T2, T3, T4, T5)
             (T0, T1, T2, T3, T4, T5, T6)
             (T0, T1, T2, T3, T4, T5, T6, T7)
           and 144 others
   = note: required for `DateTimeUtcForm` to implement `AsExpression<diesel::sql_types::Timestamptz>`

Here's what the wrapper looks like:

#[derive(Queryable, QueryableByName, Insertable, Selectable, Ord, Eq, PartialEq, PartialOrd, Debug)]
#[diesel(table_name = crate::schema::photos)]
#[diesel(sql_type = Timestamptz)]
pub struct DateTimeUtcForm {
   pub time_taken: DateTime<Utc>, 
}

And here's the Photo struct:


#[(Queryable, Insertable, Selectable, Serialize, Deserialize, Ord, Eq, PartialEq, PartialOrd, Debug)]
#[diesel(table_name = crate::schema::photos)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct Photo {
    pub description: Option<String>,
    pub photographer: Option<String>,
    pub photo_path: String,
    #[serde(with = "date_format")]
    pub time_taken: DateTimeUtcForm,
}

Finally, the diesel schema:


diesel::table! {
    posts (post_id) {
        post_id -> Int4,
        #[max_length = 2048]
        description -> Nullable<Varchar>,
        like_count -> Nullable<Int4>,
        #[max_length = 128]
        song -> Nullable<Varchar>,
        time_taken -> Timestamptz,
    }
}

I have serialize and deserialize methods in the date_format module I'm using for serde serialization.

I've tried using the macro #[diesel(sql_type = diesel::sql_types::Timestamptz)] on both the Photo struct and the field (time_taken) within both structs. However, it did not change the error output. I'm unable to otherwise determine how to implement diesel::Expression for the DateTimeUtcForm type.

Source: View source