Skip to main content

rosetta_utc/diesel_impls/
postgres.rs

1#![cfg(feature = "postgres")]
2//! Submodule proving the implementations of the traits relative to Diesel with
3//! `PostgreSQL` as the backend.
4
5impl diesel::deserialize::FromSql<crate::diesel_impls::TimestampUTC, diesel::pg::Pg>
6    for crate::TimestampUTC
7{
8    fn from_sql(value: diesel::pg::PgValue<'_>) -> diesel::deserialize::Result<Self> {
9        <chrono::DateTime<chrono::Utc> as diesel::deserialize::FromSql<
10            diesel::sql_types::Timestamptz,
11            diesel::pg::Pg,
12        >>::from_sql(value)
13        .map(Self::from)
14    }
15}
16
17impl diesel::serialize::ToSql<crate::diesel_impls::TimestampUTC, diesel::pg::Pg>
18    for crate::TimestampUTC
19{
20    fn to_sql<'b>(
21        &'b self,
22        out: &mut diesel::serialize::Output<'b, '_, diesel::pg::Pg>,
23    ) -> diesel::serialize::Result {
24        <chrono::DateTime<chrono::Utc> as diesel::serialize::ToSql<
25            diesel::sql_types::Timestamptz,
26            diesel::pg::Pg,
27        >>::to_sql(self.as_ref(), out)
28    }
29}