pub struct Query<T> { /* private fields */ }Expand description
A compile-time-checked query paired with its inferred result type T.
query! expands to one of these, carrying the already-validated query
text, the parameters bound at the call site, and a T that is the inferred
response rendered as a nameless struct.
Implementations§
Source§impl<T> Query<T>
impl<T> Query<T>
Sourcepub const fn statements(&self) -> usize
pub const fn statements(&self) -> usize
The number of top-level statements, which is also the number of result slots the server returns.
Sourcepub fn bound(&self) -> Vec<&str>
pub fn bound(&self) -> Vec<&str>
The names of the parameters bound at the call site, in bind order.
Sourcepub fn decode(&self, values: Vec<Value>) -> Result<T>
pub fn decode(&self, values: Vec<Value>) -> Result<T>
Decodes one Value per statement into the inferred result type.
This is the whole typed surface with the runtime feature off, and the
seam the fetch* methods go through — a response obtained any other way
can be decoded with it. values must hold one entry per statement, in
source order.
§Errors
Returns ErrorKind::Decode if a statement’s value does not match the
type inferred for it.
Source§impl<T> Query<T>
impl<T> Query<T>
Sourcepub async fn fetch<C: Connection>(self, db: &Surreal<C>) -> Result<T>
pub async fn fetch<C: Connection>(self, db: &Surreal<C>) -> Result<T>
Runs the query and returns exactly the type the analyzer inferred.
This is the shape-preserving verb: a SELECT gives a Vec of rows, a
RETURN gives the value, SELECT … FROM ONLY gives an Option, and a
multi-statement query gives a tuple. When the result is a row set,
fetch_all and friends read better.
§Errors
Returns ErrorKind::Database if the query failed, or
ErrorKind::Decode if the response does not match the inferred type.
Source§impl<T> Query<T>
The row-set verbs.
impl<T> Query<T>
The row-set verbs.
T: Rows is a bound on each method rather than on the impl block on
purpose: an unsatisfied method bound is an E0277, which honours the
#[diagnostic::on_unimplemented] note on Rows, whereas an unsatisfied
impl-block bound is an E0599 that reports only i64: Rows and no guidance.
Sourcepub async fn fetch_all<C: Connection>(
self,
db: &Surreal<C>,
) -> Result<Vec<T::Row>>where
T: Rows,
pub async fn fetch_all<C: Connection>(
self,
db: &Surreal<C>,
) -> Result<Vec<T::Row>>where
T: Rows,
Runs the query and returns every row.
§Errors
Returns ErrorKind::Database if the query failed, or
ErrorKind::Decode if a row does not match its inferred type.
Sourcepub async fn fetch_one<C: Connection>(self, db: &Surreal<C>) -> Result<T::Row>where
T: Rows,
pub async fn fetch_one<C: Connection>(self, db: &Surreal<C>) -> Result<T::Row>where
T: Rows,
Runs the query and returns its first row, failing if there are none.
§Errors
Returns ErrorKind::RowNotFound if the query matched nothing, plus
the errors fetch_all returns.
Sourcepub async fn fetch_optional<C: Connection>(
self,
db: &Surreal<C>,
) -> Result<Option<T::Row>>where
T: Rows,
pub async fn fetch_optional<C: Connection>(
self,
db: &Surreal<C>,
) -> Result<Option<T::Row>>where
T: Rows,
Runs the query and returns its first row, if any.
§Errors
Returns ErrorKind::Database if the query failed, or
ErrorKind::Decode if a row does not match its inferred type.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Query<T>
impl<T> RefUnwindSafe for Query<T>
impl<T> Send for Query<T>
impl<T> Sync for Query<T>
impl<T> Unpin for Query<T>
impl<T> UnsafeUnpin for Query<T>
impl<T> UnwindSafe for Query<T>
Blanket Implementations§
impl<T> AsyncFriendly for T
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<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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request