1use std::ops::Add;
2
3use crate::deserialize::{self, Defaultable, FromSql, FromSqlRow};
4use crate::expression::AsExpression;
5use crate::pg::{Pg, PgValue};
6use crate::serialize::{self, IsNull, Output, ToSql};
7use crate::sql_types::{self, Date, Interval, Time, Timestamp, Timestamptz};
8
9#[cfg(feature = "chrono")]
10mod chrono;
11#[cfg(feature = "quickcheck")]
12mod quickcheck_impls;
13mod std_time;
14#[cfg(feature = "time")]
15mod time;
16
17#[cfg(feature = "postgres_backend")]
18#[derive(#[automatically_derived]
impl ::core::fmt::Debug for PgTimestamp {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "PgTimestamp",
&&self.0)
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for PgTimestamp {
#[inline]
fn clone(&self) -> PgTimestamp {
let _: ::core::clone::AssertParamIsClone<i64>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for PgTimestamp { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for PgTimestamp {
#[inline]
fn eq(&self, other: &PgTimestamp) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for PgTimestamp {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<i64>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for PgTimestamp {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
::core::hash::Hash::hash(&self.0, state)
}
}Hash, #[automatically_derived]
impl ::core::cmp::PartialOrd for PgTimestamp {
#[inline]
fn partial_cmp(&self, other: &PgTimestamp)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for PgTimestamp {
#[inline]
fn cmp(&self, other: &PgTimestamp) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}Ord, const _: () =
{
use diesel;
impl<'__expr> diesel::expression::AsExpression<Timestamp> for
&'__expr PgTimestamp {
type Expression =
diesel::internal::derives::as_expression::Bound<Timestamp,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Timestamp>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamp>>
for &'__expr PgTimestamp {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Timestamp>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamp>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2> diesel::expression::AsExpression<Timestamp>
for &'__expr2 &'__expr PgTimestamp {
type Expression =
diesel::internal::derives::as_expression::Bound<Timestamp,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Timestamp>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamp>>
for &'__expr2 &'__expr PgTimestamp {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Timestamp>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamp>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<__DB>
diesel::serialize::ToSql<diesel::sql_types::Nullable<Timestamp>,
__DB> for PgTimestamp where __DB: diesel::backend::Backend,
Self: diesel::serialize::ToSql<Timestamp, __DB> {
fn to_sql<'__b>(&'__b self,
out: &mut diesel::serialize::Output<'__b, '_, __DB>)
-> diesel::serialize::Result {
diesel::serialize::ToSql::<Timestamp, __DB>::to_sql(self, out)
}
}
impl diesel::expression::AsExpression<Timestamp> for PgTimestamp {
type Expression =
diesel::internal::derives::as_expression::Bound<Timestamp,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Timestamp>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamp>>
for PgTimestamp {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Timestamp>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamp>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr> diesel::expression::AsExpression<Timestamptz> for
&'__expr PgTimestamp {
type Expression =
diesel::internal::derives::as_expression::Bound<Timestamptz,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Timestamptz>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamptz>>
for &'__expr PgTimestamp {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Timestamptz>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamptz>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2> diesel::expression::AsExpression<Timestamptz>
for &'__expr2 &'__expr PgTimestamp {
type Expression =
diesel::internal::derives::as_expression::Bound<Timestamptz,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Timestamptz>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamptz>>
for &'__expr2 &'__expr PgTimestamp {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Timestamptz>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamptz>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<__DB>
diesel::serialize::ToSql<diesel::sql_types::Nullable<Timestamptz>,
__DB> for PgTimestamp where __DB: diesel::backend::Backend,
Self: diesel::serialize::ToSql<Timestamptz, __DB> {
fn to_sql<'__b>(&'__b self,
out: &mut diesel::serialize::Output<'__b, '_, __DB>)
-> diesel::serialize::Result {
diesel::serialize::ToSql::<Timestamptz,
__DB>::to_sql(self, out)
}
}
impl diesel::expression::AsExpression<Timestamptz> for PgTimestamp {
type Expression =
diesel::internal::derives::as_expression::Bound<Timestamptz,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Timestamptz>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamptz>>
for PgTimestamp {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Timestamptz>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Timestamptz>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
};AsExpression, const _: () =
{
use diesel;
impl<__DB, __ST> diesel::deserialize::Queryable<__ST, __DB> for
PgTimestamp where __DB: diesel::backend::Backend,
__ST: diesel::sql_types::SingleValue,
Self: diesel::deserialize::FromSql<__ST, __DB> {
type Row = Self;
fn build(row: Self) -> diesel::deserialize::Result<Self> {
diesel::deserialize::Result::Ok(row)
}
}
};FromSqlRow)]
19#[diesel(sql_type = Timestamp)]
20#[diesel(sql_type = Timestamptz)]
21pub struct PgTimestamp(pub i64);
25
26impl Defaultable for PgTimestamp {
27 fn default_value() -> Self {
28 PgTimestamp(0)
29 }
30}
31
32#[cfg(feature = "postgres_backend")]
33#[derive(#[automatically_derived]
impl ::core::fmt::Debug for PgDate {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "PgDate",
&&self.0)
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for PgDate {
#[inline]
fn clone(&self) -> PgDate {
let _: ::core::clone::AssertParamIsClone<i32>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for PgDate { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for PgDate {
#[inline]
fn eq(&self, other: &PgDate) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for PgDate {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<i32>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for PgDate {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
::core::hash::Hash::hash(&self.0, state)
}
}Hash, #[automatically_derived]
impl ::core::cmp::PartialOrd for PgDate {
#[inline]
fn partial_cmp(&self, other: &PgDate)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for PgDate {
#[inline]
fn cmp(&self, other: &PgDate) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}Ord, const _: () =
{
use diesel;
impl<'__expr> diesel::expression::AsExpression<Date> for
&'__expr PgDate {
type Expression =
diesel::internal::derives::as_expression::Bound<Date, Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Date>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Date>>
for &'__expr PgDate {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Date>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Date>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2> diesel::expression::AsExpression<Date> for
&'__expr2 &'__expr PgDate {
type Expression =
diesel::internal::derives::as_expression::Bound<Date, Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Date>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Date>>
for &'__expr2 &'__expr PgDate {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Date>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Date>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<__DB>
diesel::serialize::ToSql<diesel::sql_types::Nullable<Date>, __DB>
for PgDate where __DB: diesel::backend::Backend,
Self: diesel::serialize::ToSql<Date, __DB> {
fn to_sql<'__b>(&'__b self,
out: &mut diesel::serialize::Output<'__b, '_, __DB>)
-> diesel::serialize::Result {
diesel::serialize::ToSql::<Date, __DB>::to_sql(self, out)
}
}
impl diesel::expression::AsExpression<Date> for PgDate {
type Expression =
diesel::internal::derives::as_expression::Bound<Date, Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Date>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl diesel::expression::AsExpression<diesel::sql_types::Nullable<Date>>
for PgDate {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Date>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Date>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
};AsExpression, const _: () =
{
use diesel;
impl<__DB, __ST> diesel::deserialize::Queryable<__ST, __DB> for PgDate
where __DB: diesel::backend::Backend,
__ST: diesel::sql_types::SingleValue,
Self: diesel::deserialize::FromSql<__ST, __DB> {
type Row = Self;
fn build(row: Self) -> diesel::deserialize::Result<Self> {
diesel::deserialize::Result::Ok(row)
}
}
};FromSqlRow)]
34#[diesel(sql_type = Date)]
35pub struct PgDate(pub i32);
39
40impl Defaultable for PgDate {
41 fn default_value() -> Self {
42 PgDate(0)
43 }
44}
45
46#[cfg(feature = "postgres_backend")]
50#[derive(#[automatically_derived]
impl ::core::fmt::Debug for PgTime {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "PgTime",
&&self.0)
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for PgTime {
#[inline]
fn clone(&self) -> PgTime {
let _: ::core::clone::AssertParamIsClone<i64>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for PgTime { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for PgTime {
#[inline]
fn eq(&self, other: &PgTime) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for PgTime {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<i64>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for PgTime {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
::core::hash::Hash::hash(&self.0, state)
}
}Hash, #[automatically_derived]
impl ::core::cmp::PartialOrd for PgTime {
#[inline]
fn partial_cmp(&self, other: &PgTime)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for PgTime {
#[inline]
fn cmp(&self, other: &PgTime) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}Ord, const _: () =
{
use diesel;
impl<'__expr> diesel::expression::AsExpression<Time> for
&'__expr PgTime {
type Expression =
diesel::internal::derives::as_expression::Bound<Time, Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Time>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Time>>
for &'__expr PgTime {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Time>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Time>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2> diesel::expression::AsExpression<Time> for
&'__expr2 &'__expr PgTime {
type Expression =
diesel::internal::derives::as_expression::Bound<Time, Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Time>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Time>>
for &'__expr2 &'__expr PgTime {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Time>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Time>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<__DB>
diesel::serialize::ToSql<diesel::sql_types::Nullable<Time>, __DB>
for PgTime where __DB: diesel::backend::Backend,
Self: diesel::serialize::ToSql<Time, __DB> {
fn to_sql<'__b>(&'__b self,
out: &mut diesel::serialize::Output<'__b, '_, __DB>)
-> diesel::serialize::Result {
diesel::serialize::ToSql::<Time, __DB>::to_sql(self, out)
}
}
impl diesel::expression::AsExpression<Time> for PgTime {
type Expression =
diesel::internal::derives::as_expression::Bound<Time, Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Time>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl diesel::expression::AsExpression<diesel::sql_types::Nullable<Time>>
for PgTime {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Time>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Time>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
};AsExpression, const _: () =
{
use diesel;
impl<__DB, __ST> diesel::deserialize::Queryable<__ST, __DB> for PgTime
where __DB: diesel::backend::Backend,
__ST: diesel::sql_types::SingleValue,
Self: diesel::deserialize::FromSql<__ST, __DB> {
type Row = Self;
fn build(row: Self) -> diesel::deserialize::Result<Self> {
diesel::deserialize::Result::Ok(row)
}
}
};FromSqlRow)]
51#[diesel(sql_type = Time)]
52pub struct PgTime(pub i64);
53
54impl Defaultable for PgTime {
55 fn default_value() -> Self {
56 PgTime(0)
57 }
58}
59
60#[cfg(feature = "postgres_backend")]
65#[derive(#[automatically_derived]
impl ::core::fmt::Debug for PgInterval {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f, "PgInterval",
"microseconds", &self.microseconds, "days", &self.days, "months",
&&self.months)
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for PgInterval {
#[inline]
fn clone(&self) -> PgInterval {
let _: ::core::clone::AssertParamIsClone<i64>;
let _: ::core::clone::AssertParamIsClone<i32>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for PgInterval { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for PgInterval {
#[inline]
fn eq(&self, other: &PgInterval) -> bool {
self.microseconds == other.microseconds && self.days == other.days &&
self.months == other.months
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for PgInterval {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<i64>;
let _: ::core::cmp::AssertParamIsEq<i32>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for PgInterval {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
::core::hash::Hash::hash(&self.microseconds, state);
::core::hash::Hash::hash(&self.days, state);
::core::hash::Hash::hash(&self.months, state)
}
}Hash, const _: () =
{
use diesel;
impl<'__expr> diesel::expression::AsExpression<Interval> for
&'__expr PgInterval {
type Expression =
diesel::internal::derives::as_expression::Bound<Interval,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Interval>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Interval>>
for &'__expr PgInterval {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Interval>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Interval>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2> diesel::expression::AsExpression<Interval> for
&'__expr2 &'__expr PgInterval {
type Expression =
diesel::internal::derives::as_expression::Bound<Interval,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Interval>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<'__expr, '__expr2>
diesel::expression::AsExpression<diesel::sql_types::Nullable<Interval>>
for &'__expr2 &'__expr PgInterval {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Interval>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Interval>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl<__DB>
diesel::serialize::ToSql<diesel::sql_types::Nullable<Interval>,
__DB> for PgInterval where __DB: diesel::backend::Backend,
Self: diesel::serialize::ToSql<Interval, __DB> {
fn to_sql<'__b>(&'__b self,
out: &mut diesel::serialize::Output<'__b, '_, __DB>)
-> diesel::serialize::Result {
diesel::serialize::ToSql::<Interval, __DB>::to_sql(self, out)
}
}
impl diesel::expression::AsExpression<Interval> for PgInterval {
type Expression =
diesel::internal::derives::as_expression::Bound<Interval,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<Interval>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
impl diesel::expression::AsExpression<diesel::sql_types::Nullable<Interval>>
for PgInterval {
type Expression =
diesel::internal::derives::as_expression::Bound<diesel::sql_types::Nullable<Interval>,
Self>;
fn as_expression(self)
->
<Self as
diesel::expression::AsExpression<diesel::sql_types::Nullable<Interval>>>::Expression {
diesel::internal::derives::as_expression::Bound::new(self)
}
}
};AsExpression, const _: () =
{
use diesel;
impl<__DB, __ST> diesel::deserialize::Queryable<__ST, __DB> for
PgInterval where __DB: diesel::backend::Backend,
__ST: diesel::sql_types::SingleValue,
Self: diesel::deserialize::FromSql<__ST, __DB> {
type Row = Self;
fn build(row: Self) -> diesel::deserialize::Result<Self> {
diesel::deserialize::Result::Ok(row)
}
}
};FromSqlRow)]
66#[diesel(sql_type = Interval)]
67pub struct PgInterval {
68 pub microseconds: i64,
70 pub days: i32,
72 pub months: i32,
74}
75
76impl PgInterval {
77 pub fn new(microseconds: i64, days: i32, months: i32) -> Self {
84 PgInterval {
85 microseconds,
86 days,
87 months,
88 }
89 }
90
91 pub fn from_microseconds(microseconds: i64) -> Self {
93 Self::new(microseconds, 0, 0)
94 }
95
96 pub fn from_days(days: i32) -> Self {
98 Self::new(0, days, 0)
99 }
100
101 pub fn from_months(months: i32) -> Self {
103 Self::new(0, 0, months)
104 }
105}
106
107#[cfg(feature = "postgres_backend")]
108impl ToSql<sql_types::Timestamp, Pg> for PgTimestamp {
109 fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Pg>) -> serialize::Result {
110 ToSql::<sql_types::BigInt, Pg>::to_sql(&self.0, out)
111 }
112}
113
114#[cfg(feature = "postgres_backend")]
115impl FromSql<sql_types::Timestamp, Pg> for PgTimestamp {
116 fn from_sql(bytes: PgValue<'_>) -> deserialize::Result<Self> {
117 FromSql::<sql_types::BigInt, Pg>::from_sql(bytes).map(PgTimestamp)
118 }
119}
120
121#[cfg(feature = "postgres_backend")]
122impl ToSql<sql_types::Timestamptz, Pg> for PgTimestamp {
123 fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Pg>) -> serialize::Result {
124 ToSql::<sql_types::Timestamp, Pg>::to_sql(self, out)
125 }
126}
127
128#[cfg(feature = "postgres_backend")]
129impl FromSql<sql_types::Timestamptz, Pg> for PgTimestamp {
130 fn from_sql(bytes: PgValue<'_>) -> deserialize::Result<Self> {
131 FromSql::<sql_types::Timestamp, Pg>::from_sql(bytes)
132 }
133}
134
135#[cfg(feature = "postgres_backend")]
136impl ToSql<sql_types::Date, Pg> for PgDate {
137 fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Pg>) -> serialize::Result {
138 ToSql::<sql_types::Integer, Pg>::to_sql(&self.0, out)
139 }
140}
141
142#[cfg(feature = "postgres_backend")]
143impl FromSql<sql_types::Date, Pg> for PgDate {
144 fn from_sql(bytes: PgValue<'_>) -> deserialize::Result<Self> {
145 FromSql::<sql_types::Integer, Pg>::from_sql(bytes).map(PgDate)
146 }
147}
148
149#[cfg(feature = "postgres_backend")]
150impl ToSql<sql_types::Time, Pg> for PgTime {
151 fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Pg>) -> serialize::Result {
152 ToSql::<sql_types::BigInt, Pg>::to_sql(&self.0, out)
153 }
154}
155
156#[cfg(feature = "postgres_backend")]
157impl FromSql<sql_types::Time, Pg> for PgTime {
158 fn from_sql(bytes: PgValue<'_>) -> deserialize::Result<Self> {
159 FromSql::<sql_types::BigInt, Pg>::from_sql(bytes).map(PgTime)
160 }
161}
162
163#[cfg(feature = "postgres_backend")]
164impl ToSql<sql_types::Interval, Pg> for PgInterval {
165 fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Pg>) -> serialize::Result {
166 ToSql::<sql_types::BigInt, Pg>::to_sql(&self.microseconds, out)?;
167 ToSql::<sql_types::Integer, Pg>::to_sql(&self.days, out)?;
168 ToSql::<sql_types::Integer, Pg>::to_sql(&self.months, out)?;
169 Ok(IsNull::No)
170 }
171}
172
173#[cfg(feature = "postgres_backend")]
174impl FromSql<sql_types::Interval, Pg> for PgInterval {
175 fn from_sql(value: PgValue<'_>) -> deserialize::Result<Self> {
176 Ok(PgInterval {
177 microseconds: FromSql::<sql_types::BigInt, Pg>::from_sql(value.subslice(0..8))?,
178 days: FromSql::<sql_types::Integer, Pg>::from_sql(value.subslice(8..12))?,
179 months: FromSql::<sql_types::Integer, Pg>::from_sql(value.subslice(12..16))?,
180 })
181 }
182}
183
184impl Add<PgInterval> for PgInterval {
185 type Output = PgInterval;
186
187 fn add(self, other: PgInterval) -> Self::Output {
188 PgInterval {
189 microseconds: self.microseconds + other.microseconds,
190 days: self.days + other.days,
191 months: self.months + other.months,
192 }
193 }
194}