use super::from_clause::AsQuerySource; use crate::expression::{Expression, SelectableExpression}; use crate::query_builder::*; use crate::query_source::QuerySource; #[doc(hidden)] pub struct DefaultSelectClause { default_selection: ::DefaultSelection, } impl std::fmt::Debug for DefaultSelectClause where QS: AsQuerySource, ::DefaultSelection: std::fmt::Debug, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("DefaultSelectClause") .field("default_selection", &self.default_selection) .finish() } } impl Clone for DefaultSelectClause where QS: AsQuerySource, ::DefaultSelection: Clone, { fn clone(&self) -> Self { Self { default_selection: self.default_selection.clone(), } } } impl Copy for DefaultSelectClause where QS: AsQuerySource, ::DefaultSelection: Copy, { } impl DefaultSelectClause { pub(crate) fn new(qs: &QS) -> Self { Self { default_selection: qs.as_query_source().default_selection(), } } } impl QueryId for DefaultSelectClause where QS: AsQuerySource, ::DefaultSelection: QueryId, { type QueryId = <::DefaultSelection as QueryId>::QueryId; const HAS_STATIC_QUERY_ID: bool = <::DefaultSelection as QueryId>::HAS_STATIC_QUERY_ID; } #[derive(Debug, Clone, Copy, QueryId)] pub struct SelectClause(pub T); /// Specialised variant of `Expression` for select clause types /// /// The difference to the normal `Expression` trait is the query source (`QS`) /// generic type parameter. This allows to access the query source in generic code. #[cfg_attr( feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes", cfg(feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes") )] pub trait SelectClauseExpression { /// The expression represented by the given select clause type Selection; /// SQL type of the select clause type SelectClauseSqlType; } impl SelectClauseExpression> for SelectClause where QS: QuerySource, T: SelectableExpression, { type Selection = T; type SelectClauseSqlType = T::SqlType; } impl SelectClauseExpression for SelectClause where T: SelectableExpression, { type Selection = T; type SelectClauseSqlType = T::SqlType; } impl SelectClauseExpression> for DefaultSelectClause> where QS: QuerySource, { type Selection = QS::DefaultSelection; type SelectClauseSqlType = ::SqlType; } impl QueryFragment for SelectClause where DB: Backend, T: QueryFragment, { fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, DB>) -> QueryResult<()> { self.0.walk_ast(pass) } } impl QueryFragment for DefaultSelectClause where DB: Backend, QS: AsQuerySource, ::DefaultSelection: QueryFragment, { fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, DB>) -> QueryResult<()> { self.default_selection.walk_ast(pass) } }