pub struct Projection<M> { /* private fields */ }Expand description
A value expression of model M that can be selected: a column, an
aggregate (User::AGE.avg()), a cast or raw SQL.
Use projections with Select::select to fetch
tuples or custom row types instead of whole models, and compare them to
build HAVING conditions:
ⓘ
let per_role: Vec<(String, i64)> = User::query()
.group_by(User::ROLE)
.having(Projection::count_all().gt(10))
.select((User::ROLE, Projection::count_all()))
.fetch_all(&db)
.await?;Implementations§
Source§impl<M> Projection<M>
impl<M> Projection<M>
Sourcepub fn count_all() -> Projection<M>
pub fn count_all() -> Projection<M>
COUNT(*)
Sourcepub fn raw<V>(
sql: impl Into<String>,
params: impl IntoIterator<Item = V>,
) -> Projection<M>
pub fn raw<V>( sql: impl Into<String>, params: impl IntoIterator<Item = V>, ) -> Projection<M>
Raw SQL where each ? is bound to the next parameter.
Sourcepub fn cast(self, sql_type: &'static str) -> Projection<M>
pub fn cast(self, sql_type: &'static str) -> Projection<M>
CAST(expr AS sql_type), e.g. .cast("BIGINT") or
.cast("DOUBLE PRECISION") to decode a NUMERIC aggregate into
i64/f64.
Sourcepub fn alias(self, alias: &'static str) -> Projection<M>
pub fn alias(self, alias: &'static str) -> Projection<M>
Name the selected value (expr AS alias), for decoding into a struct
that derives sqlx::FromRow.
Trait Implementations§
Source§impl<M> Clone for Projection<M>
impl<M> Clone for Projection<M>
Source§fn clone(&self) -> Projection<M>
fn clone(&self) -> Projection<M>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<M> Debug for Projection<M>
impl<M> Debug for Projection<M>
Source§impl<M> From<Column<M>> for Projection<M>where
M: Model,
impl<M> From<Column<M>> for Projection<M>where
M: Model,
Source§fn from(column: Column<M>) -> Projection<M>
fn from(column: Column<M>) -> Projection<M>
Converts to this type from the input type.
Source§impl<M> IntoProjections<M> for Projection<M>
impl<M> IntoProjections<M> for Projection<M>
Source§fn into_projections(self) -> Vec<Projection<M>>
fn into_projections(self) -> Vec<Projection<M>>
Convert into the list of selected expressions.
Source§impl<X> ScopedItem for Projection<X>
impl<X> ScopedItem for Projection<X>
Auto Trait Implementations§
impl<M> !RefUnwindSafe for Projection<M>
impl<M> !UnwindSafe for Projection<M>
impl<M> Freeze for Projection<M>
impl<M> Send for Projection<M>
impl<M> Sync for Projection<M>
impl<M> Unpin for Projection<M>
impl<M> UnsafeUnpin for Projection<M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<M> InScope<(M, ()), Here> for M
impl<M, Rest, N> InScope<(M, (Rest, N)), Last> for N
impl<X, M, Rest, N, I> InScope<(M, (Rest, N)), There<I>> for X
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more