pub struct Selector<M> { /* private fields */ }Expand description
A SELECT decoded into an arbitrary FromQueryResult type.
Implementations§
Source§impl<M: FromQueryResult> Selector<M>
impl<M: FromQueryResult> Selector<M>
Sourcepub fn from_query(query: Select) -> Self
pub fn from_query(query: Select) -> Self
Wraps any SQL select.
Sourcepub fn from_statement(statement: Statement) -> RawSelector<M>
pub fn from_statement(statement: Statement) -> RawSelector<M>
Wraps a raw statement.
Sourcepub async fn one<C: ConnectionTrait>(self, db: &C) -> Result<Option<M>>
pub async fn one<C: ConnectionTrait>(self, db: &C) -> Result<Option<M>>
Fetches the first row, adding LIMIT 1.
§Errors
Returns DbErr::Driver when the query fails or the row cannot be decoded.
Sourcepub async fn stream<'a, C: StreamTrait>(
self,
db: &'a C,
) -> Result<ModelStream<'a, M>>where
M: 'a,
pub async fn stream<'a, C: StreamTrait>(
self,
db: &'a C,
) -> Result<ModelStream<'a, M>>where
M: 'a,
Streams rows as they are read.
§Errors
Returns DbErr::Driver when the query cannot be started; decoding
failures surface as items of the stream.
Sourcepub async fn count<C: ConnectionTrait>(self, db: &C) -> Result<u64>
pub async fn count<C: ConnectionTrait>(self, db: &C) -> Result<u64>
Counts the rows with SELECT COUNT(*) FROM (query).
Ordering, limit and offset are stripped from the inner query because they do not affect the total and would only slow the count down.
§Errors
Returns DbErr::RecordNotFound when the count query returns no
row; DbErr::Driver when the query fails.
Sourcepub async fn exists<C: ConnectionTrait>(self, db: &C) -> Result<bool>
pub async fn exists<C: ConnectionTrait>(self, db: &C) -> Result<bool>
Whether the query returns at least one row, through SELECT EXISTS (query).
§Errors
Returns DbErr::RecordNotFound when the probe returns no row;
DbErr::Driver when the query fails.
Trait Implementations§
Auto Trait Implementations§
impl<M> Freeze for Selector<M>where
PhantomData<M>: Freeze,
impl<M> RefUnwindSafe for Selector<M>where
PhantomData<M>: RefUnwindSafe,
impl<M> Send for Selector<M>where
PhantomData<M>: Send,
impl<M> Sync for Selector<M>where
PhantomData<M>: Sync,
impl<M> Unpin for Selector<M>where
PhantomData<M>: Unpin,
impl<M> UnsafeUnpin for Selector<M>where
PhantomData<M>: UnsafeUnpin,
impl<M> UnwindSafe for Selector<M>where
PhantomData<M>: UnwindSafe,
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
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<T> ErasedDestructor for Twhere
T: 'static,
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> ⓘ
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> ⓘ
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