use super::field_alias_mapper::FieldAliasMapper; use super::{Alias, AliasSource}; use crate::dsl; #[cfg(feature = "postgres_backend")] use crate::expression::SelectableExpression; use crate::expression::{Expression, TypedExpressionType, ValidGrouping}; use crate::expression_methods::EqAll; use crate::query_builder::{combination_clause, AsQuery, FromClause, Query, SelectStatement}; use crate::query_dsl::methods::*; use crate::query_dsl::{CombineDsl, QueryDsl, RunQueryDsl}; use crate::query_source::{QuerySource, Table}; impl QueryDsl for Alias {} impl FilterDsl for Alias where Self: AsQuery, ::Query: FilterDsl, { type Output = dsl::Filter<::Query, Predicate>; fn filter(self, predicate: Predicate) -> Self::Output { self.as_query().filter(predicate) } } impl SelectDsl for Alias where Selection: Expression, Self: AsQuery, ::Query: SelectDsl, { type Output = dsl::Select<::Query, Selection>; fn select(self, selection: Selection) -> Self::Output { self.as_query().select(selection) } } impl FindDsl for Alias where S: AliasSource, S::Target: Table, ::PrimaryKey: FieldAliasMapper, <::PrimaryKey as FieldAliasMapper>::Out: EqAll, Self: FilterDsl< <<::PrimaryKey as FieldAliasMapper>::Out as EqAll>::Output, >, { type Output = dsl::Filter< Self, <<::PrimaryKey as FieldAliasMapper>::Out as EqAll>::Output, >; fn find(self, id: PK) -> Self::Output { let primary_key = self.source.target().primary_key(); let predicate = self.fields(primary_key).eq_all(id); QueryDsl::filter(self, predicate) } } impl<'a, S, DB> BoxedDsl<'a, DB> for Alias where Alias: QuerySource + AsQuery>>>, SelectStatement>>: BoxedDsl<'a, DB>, as QuerySource>::DefaultSelection: Expression as AsQuery>::SqlType> + ValidGrouping<()>, as AsQuery>::SqlType: TypedExpressionType, { type Output = dsl::IntoBoxed<'a, SelectStatement>>, DB>; fn internal_into_boxed(self) -> Self::Output { self.as_query().internal_into_boxed() } } impl CombineDsl for Alias where S: AliasSource, S::Target: Table, Self: AsQuery, { type Query = ::Query; fn union(self, rhs: Rhs) -> dsl::Union where Rhs: AsQuery::Query as Query>::SqlType>, { combination_clause::CombinationClause::new( combination_clause::Union, combination_clause::Distinct, self.as_query(), rhs.as_query(), ) } fn union_all(self, rhs: Rhs) -> dsl::UnionAll where Rhs: AsQuery::Query as Query>::SqlType>, { combination_clause::CombinationClause::new( combination_clause::Union, combination_clause::All, self.as_query(), rhs.as_query(), ) } fn intersect(self, rhs: Rhs) -> dsl::Intersect where Rhs: AsQuery::Query as Query>::SqlType>, { combination_clause::CombinationClause::new( combination_clause::Intersect, combination_clause::Distinct, self.as_query(), rhs.as_query(), ) } fn intersect_all(self, rhs: Rhs) -> dsl::IntersectAll where Rhs: AsQuery::Query as Query>::SqlType>, { combination_clause::CombinationClause::new( combination_clause::Intersect, combination_clause::All, self.as_query(), rhs.as_query(), ) } fn except(self, rhs: Rhs) -> dsl::Except where Rhs: AsQuery::Query as Query>::SqlType>, { combination_clause::CombinationClause::new( combination_clause::Except, combination_clause::Distinct, self.as_query(), rhs.as_query(), ) } fn except_all(self, rhs: Rhs) -> dsl::ExceptAll where Rhs: AsQuery::Query as Query>::SqlType>, { combination_clause::CombinationClause::new( combination_clause::Except, combination_clause::All, self.as_query(), rhs.as_query(), ) } } #[cfg(feature = "postgres_backend")] impl DistinctOnDsl for Alias where S: AliasSource, Selection: SelectableExpression, Self: QuerySource + AsQuery>>, SelectStatement>: DistinctOnDsl, ::DefaultSelection: Expression::SqlType> + ValidGrouping<()>, ::SqlType: TypedExpressionType, { type Output = dsl::DistinctOn>, Selection>; fn distinct_on(self, selection: Selection) -> dsl::DistinctOn { DistinctOnDsl::distinct_on(self.as_query(), selection) } } impl OrFilterDsl for Alias where Self: AsQuery, ::Query: OrFilterDsl, { type Output = dsl::OrFilter<::Query, Predicate>; fn or_filter(self, predicate: Predicate) -> Self::Output { self.as_query().or_filter(predicate) } } impl GroupByDsl for Alias where Expr: Expression, Self: QuerySource + AsQuery>>, ::DefaultSelection: Expression::SqlType> + ValidGrouping<()>, ::SqlType: TypedExpressionType, ::Query: GroupByDsl, { type Output = dsl::GroupBy>, Expr>; fn group_by(self, expr: Expr) -> dsl::GroupBy { GroupByDsl::group_by(self.as_query(), expr) } } impl LimitDsl for Alias where Self: AsQuery, ::Query: LimitDsl, { type Output = <::Query as LimitDsl>::Output; fn limit(self, limit: i64) -> Self::Output { self.as_query().limit(limit) } } impl LockingDsl for Alias where Self: QuerySource + AsQuery>>, ::DefaultSelection: Expression::SqlType> + ValidGrouping<()>, ::SqlType: TypedExpressionType, { type Output = > as LockingDsl>::Output; fn with_lock(self, lock: Lock) -> Self::Output { self.as_query().with_lock(lock) } } impl RunQueryDsl for Alias {} impl OffsetDsl for Alias where Self: AsQuery, ::Query: OffsetDsl, { type Output = <::Query as OffsetDsl>::Output; fn offset(self, offset: i64) -> Self::Output { self.as_query().offset(offset) } } impl OrderDsl for Alias where Expr: Expression, Self: AsQuery, ::Query: OrderDsl, { type Output = <::Query as OrderDsl>::Output; fn order(self, expr: Expr) -> Self::Output { self.as_query().order(expr) } } impl ThenOrderDsl for Alias where Expr: Expression, Self: AsQuery, ::Query: ThenOrderDsl, { type Output = <::Query as ThenOrderDsl>::Output; fn then_order_by(self, expr: Expr) -> Self::Output { self.as_query().then_order_by(expr) } }