use crate::backend::{Backend, DieselReserveSpecialization}; use crate::dsl::SqlTypeOf; use crate::expression::{ AppearsOnTable, Expression, QueryMetadata, Selectable, SelectableExpression, TypedExpressionType, ValidGrouping, }; use crate::query_builder::*; use crate::result::QueryResult; #[derive(Debug)] pub struct SelectBy, DB: Backend> { selection: T::SelectExpression, p: std::marker::PhantomData<(T, DB)>, } impl Clone for SelectBy where DB: Backend, T: Selectable, { fn clone(&self) -> Self { Self { selection: T::construct_selection(), p: std::marker::PhantomData, } } } impl Copy for SelectBy where T: Selectable, DB: Backend, T::SelectExpression: Copy, { } impl QueryId for SelectBy where DB: Backend, T: Selectable, E: QueryId + Expression, { type QueryId = E::QueryId; const HAS_STATIC_QUERY_ID: bool = E::HAS_STATIC_QUERY_ID; } impl SelectBy where T: Selectable, DB: Backend, { pub(crate) fn new() -> Self { Self { selection: T::construct_selection(), p: std::marker::PhantomData, } } } impl Expression for SelectBy where DB: Backend, T: Selectable, E: QueryId + Expression, { type SqlType = SelectBy; } impl TypedExpressionType for SelectBy where T: Selectable, DB: Backend, { } impl ValidGrouping for SelectBy where DB: Backend, T: Selectable, E: Expression + ValidGrouping, { type IsAggregate = E::IsAggregate; } impl QueryMetadata> for DB where DB: Backend, T: Selectable, DB: QueryMetadata>, { fn row_metadata(lookup: &mut Self::MetadataLookup, out: &mut Vec>) { >::SelectExpression>>>::row_metadata( lookup, out, ) } } impl QueryFragment for SelectBy where T: Selectable, T::SelectExpression: QueryFragment, DB: Backend + DieselReserveSpecialization, { fn walk_ast<'b>(&'b self, out: AstPass<'_, 'b, DB>) -> QueryResult<()> { self.selection.walk_ast(out) } } impl SelectableExpression for SelectBy where DB: Backend, T: Selectable, T::SelectExpression: SelectableExpression, Self: AppearsOnTable, { } impl AppearsOnTable for SelectBy where DB: Backend, T: Selectable, T::SelectExpression: AppearsOnTable, Self: Expression, { }