use std::marker::PhantomData; use crate::backend::sql_dialect::on_conflict_clause; use crate::expression::{AppearsOnTable, Expression}; use crate::query_builder::*; use crate::query_source::*; #[doc(hidden)] #[derive(Debug, Clone, Copy, QueryId)] pub struct DoNothing(PhantomData); impl DoNothing { pub(crate) fn new() -> Self { Self(PhantomData) } } impl QueryFragment for DoNothing where DB: Backend, Self: QueryFragment, { fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, DB>) -> QueryResult<()> { >::walk_ast(self, pass) } } impl QueryFragment for DoNothing where DB: Backend, SD: on_conflict_clause::PgLikeOnConflictClause, { fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> { out.push_sql(" DO NOTHING"); Ok(()) } } #[doc(hidden)] #[derive(Debug, Clone, Copy, QueryId)] pub struct DoUpdate { pub(crate) changeset: T, tab: PhantomData, } impl DoUpdate { pub(crate) fn new(changeset: T) -> Self { DoUpdate { changeset, tab: PhantomData, } } } impl QueryFragment for DoUpdate where DB: Backend, Self: QueryFragment, { fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, DB>) -> QueryResult<()> { >::walk_ast(self, pass) } } impl QueryFragment for DoUpdate where DB: Backend, T: QueryFragment, SD: on_conflict_clause::PgLikeOnConflictClause, { fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> { out.unsafe_to_cache_prepared(); if self.changeset.is_noop(out.backend())? { out.push_sql(" DO NOTHING"); } else { out.push_sql(" DO UPDATE SET "); self.changeset.walk_ast(out.reborrow())?; } Ok(()) } } #[doc(hidden)] #[derive(Debug, Clone, Copy, QueryId)] pub struct Excluded(T); impl Excluded { pub(crate) fn new(t: T) -> Self { Excluded(t) } } impl QueryFragment for Excluded where DB: Backend, Self: QueryFragment, { fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, DB>) -> QueryResult<()> { >::walk_ast(self, pass) } } impl QueryFragment for Excluded where DB: Backend, T: Column, SD: on_conflict_clause::PgLikeOnConflictClause, { fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> { out.push_sql("excluded."); out.push_identifier(T::NAME)?; Ok(()) } } impl Expression for Excluded where T: Expression, { type SqlType = T::SqlType; } impl AppearsOnTable for Excluded where T: Column, Excluded: Expression, { }