pub struct RawQuery<'a, C> { /* private fields */ }Expand description
A builder for executing raw SQL queries with parameter binding.
Returned by Database::raw() or Transaction::raw(). Allows constructing safe, parameterized
SQL queries that can bypass the standard model-based QueryBuilder when
complex SQL features (CTEs, Window Functions, etc.) are needed.
Implementations§
Source§impl<'a, C> RawQuery<'a, C>where
C: Connection + Send,
impl<'a, C> RawQuery<'a, C>where
C: Connection + Send,
Sourcepub fn bind<T>(self, value: T) -> Self
pub fn bind<T>(self, value: T) -> Self
Binds a parameter to the query.
§Arguments
value- The value to bind. Must implementsqlx::Encodeandsqlx::Type.
Sourcepub async fn fetch_all<T>(self) -> Result<Vec<T>, Error>
pub async fn fetch_all<T>(self) -> Result<Vec<T>, Error>
Executes the query and returns all matching rows mapped to type T.
Sourcepub async fn fetch_one<T>(self) -> Result<T, Error>
pub async fn fetch_one<T>(self) -> Result<T, Error>
Executes the query and returns the first matching row mapped to type T.
Sourcepub async fn fetch_optional<T>(self) -> Result<Option<T>, Error>
pub async fn fetch_optional<T>(self) -> Result<Option<T>, Error>
Executes the query and returns the first matching row, or None if not found.
Sourcepub async fn fetch_scalar<O>(self) -> Result<O, Error>
pub async fn fetch_scalar<O>(self) -> Result<O, Error>
Executes the query and returns a single scalar value.
Useful for queries like SELECT count(*) ... or SELECT id ....
Sourcepub async fn fetch_scalar_optional<O>(self) -> Result<Option<O>, Error>
pub async fn fetch_scalar_optional<O>(self) -> Result<Option<O>, Error>
Executes the query and returns a single scalar value, or None if not found.
Auto Trait Implementations§
impl<'a, C> Freeze for RawQuery<'a, C>where
C: Freeze,
impl<'a, C> RefUnwindSafe for RawQuery<'a, C>where
C: RefUnwindSafe,
impl<'a, C> Send for RawQuery<'a, C>where
C: Send,
impl<'a, C> Sync for RawQuery<'a, C>where
C: Sync,
impl<'a, C> Unpin for RawQuery<'a, C>where
C: Unpin,
impl<'a, C> UnwindSafe for RawQuery<'a, C>where
C: 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
Mutably borrows from an owned value. Read more
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