use crate::expression::{Expression, ValidGrouping}; use crate::pg::Pg; use crate::query_builder::*; use crate::result::QueryResult; use crate::sql_types::{is_nullable, Date, Nullable, SqlType, Timestamp, Timestamptz, VarChar}; /// Marker trait for types which are valid in `AT TIME ZONE` expressions pub trait DateTimeLike {} impl DateTimeLike for Date {} impl DateTimeLike for Timestamp {} impl DateTimeLike for Timestamptz {} impl DateTimeLike for Nullable where T: SqlType + DateTimeLike {} #[derive(Debug, Copy, Clone, QueryId, ValidGrouping)] pub struct AtTimeZone { timestamp: Ts, timezone: Tz, } impl AtTimeZone { pub fn new(timestamp: Ts, timezone: Tz) -> Self { AtTimeZone { timestamp: timestamp, timezone: timezone, } } } impl Expression for AtTimeZone where Ts: Expression, Ts::SqlType: DateTimeLike, Tz: Expression, { type SqlType = Timestamp; } impl QueryFragment for AtTimeZone where Ts: QueryFragment, Tz: QueryFragment, { fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> { self.timestamp.walk_ast(out.reborrow())?; out.push_sql(" AT TIME ZONE "); self.timezone.walk_ast(out.reborrow())?; Ok(()) } } impl_selectable_expression!(AtTimeZone);