diesel/pg/expression/
date_and_time.rs1use crate::expression::{Expression, ValidGrouping};
2use crate::pg::Pg;
3use crate::query_builder::*;
4use crate::result::QueryResult;
5use crate::sql_types::{is_nullable, Date, Nullable, SqlType, Timestamp, Timestamptz, VarChar};
6
7pub trait DateTimeLike {}
9impl DateTimeLike for Date {}
10impl DateTimeLike for Timestamp {}
11impl DateTimeLike for Timestamptz {}
12impl<T> DateTimeLike for Nullable<T> where T: SqlType<IsNull = is_nullable::NotNull> + DateTimeLike {}
13#[derive(#[automatically_derived]
impl<Ts: ::core::fmt::Debug, Tz: ::core::fmt::Debug> ::core::fmt::Debug for
AtTimeZone<Ts, Tz> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "AtTimeZone",
"timestamp", &self.timestamp, "timezone", &&self.timezone)
}
}Debug, #[automatically_derived]
impl<Ts: ::core::marker::Copy, Tz: ::core::marker::Copy> ::core::marker::Copy
for AtTimeZone<Ts, Tz> {
}Copy, #[automatically_derived]
impl<Ts: ::core::clone::Clone, Tz: ::core::clone::Clone> ::core::clone::Clone
for AtTimeZone<Ts, Tz> {
#[inline]
fn clone(&self) -> AtTimeZone<Ts, Tz> {
AtTimeZone {
timestamp: ::core::clone::Clone::clone(&self.timestamp),
timezone: ::core::clone::Clone::clone(&self.timezone),
}
}
}Clone, const _: () =
{
use diesel;
#[allow(non_camel_case_types)]
impl<Ts: diesel::query_builder::QueryId,
Tz: diesel::query_builder::QueryId> diesel::query_builder::QueryId
for AtTimeZone<Ts, Tz> {
type QueryId =
AtTimeZone<<Ts as diesel::query_builder::QueryId>::QueryId,
<Tz as diesel::query_builder::QueryId>::QueryId>;
const HAS_STATIC_QUERY_ID: bool =
<Ts as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
<Tz as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID
&& true;
const IS_WINDOW_FUNCTION: bool =
<Ts as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
<Tz as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION
|| false;
}
};QueryId, const _: () =
{
use diesel;
impl<Ts, Tz, __GroupByClause>
diesel::expression::ValidGrouping<__GroupByClause> for
AtTimeZone<Ts, Tz> where
Ts: diesel::expression::ValidGrouping<__GroupByClause>,
Tz: diesel::expression::ValidGrouping<__GroupByClause>,
<Ts as
diesel::expression::ValidGrouping<__GroupByClause>>::IsAggregate: diesel::expression::MixedAggregates<<Tz
as
diesel::expression::ValidGrouping<__GroupByClause>>::IsAggregate>
{
type IsAggregate =
<<Ts as
diesel::expression::ValidGrouping<__GroupByClause>>::IsAggregate
as
diesel::expression::MixedAggregates<<Tz as
diesel::expression::ValidGrouping<__GroupByClause>>::IsAggregate>>::Output;
}
};ValidGrouping)]
14pub struct AtTimeZone<Ts, Tz> {
15 timestamp: Ts,
16 timezone: Tz,
17}
18
19impl<Ts, Tz> AtTimeZone<Ts, Tz> {
20 pub fn new(timestamp: Ts, timezone: Tz) -> Self {
21 AtTimeZone {
22 timestamp: timestamp,
23 timezone: timezone,
24 }
25 }
26}
27
28impl<Ts, Tz> Expression for AtTimeZone<Ts, Tz>
29where
30 Ts: Expression,
31 Ts::SqlType: DateTimeLike,
32 Tz: Expression<SqlType = VarChar>,
33{
34 type SqlType = Timestamp;
35}
36
37impl<Ts, Tz> QueryFragment<Pg> for AtTimeZone<Ts, Tz>
38where
39 Ts: QueryFragment<Pg>,
40 Tz: QueryFragment<Pg>,
41{
42 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> {
43 self.timestamp.walk_ast(out.reborrow())?;
44 out.push_sql(" AT TIME ZONE ");
45 self.timezone.walk_ast(out.reborrow())?;
46 Ok(())
47 }
48}
49
50impl<Ts, Tz, QS> crate::expression::SelectableExpression<QS> for
AtTimeZone<Ts, Tz> where
AtTimeZone<Ts, Tz>: crate::expression::AppearsOnTable<QS>,
Ts: crate::expression::SelectableExpression<QS>,
Tz: crate::expression::SelectableExpression<QS> {}
impl<Ts, Tz, QS> crate::expression::AppearsOnTable<QS> for AtTimeZone<Ts, Tz>
where AtTimeZone<Ts, Tz>: crate::expression::Expression,
Ts: crate::expression::AppearsOnTable<QS>,
Tz: crate::expression::AppearsOnTable<QS> {}impl_selectable_expression!(AtTimeZone<Ts, Tz>);