pub struct QueryScalar<T> { /* private fields */ }Expand description
A compiled single-column query. Created by the query_scalar! macro.
Returns values of a single column (e.g. COUNT(*), MAX(score), etc.).
The type T must implement RowValue.
§Example
ⓘ
let count: i64 = query_scalar!(i64, "SELECT COUNT(*) FROM users").fetch_one(&conn)?;
let names: Vec<String> = query_scalar!(String, "SELECT name FROM users").fetch_all(&conn)?;Implementations§
Source§impl<T: RowValue> QueryScalar<T>
impl<T: RowValue> QueryScalar<T>
Sourcepub fn new(sql: &str, params: &[&dyn Debug]) -> Self
pub fn new(sql: &str, params: &[&dyn Debug]) -> Self
Construct a new QueryScalar. Called by the query_scalar! macro.
Sourcepub fn fetch_all(self, conn: &Connection) -> Result<Vec<T>>
pub fn fetch_all(self, conn: &Connection) -> Result<Vec<T>>
Execute and return all scalar values as a Vec<T>.
§Errors
Returns a hyperdb_api::Error on connection failure, SQL error, or
type conversion failure.
Sourcepub fn fetch_one(self, conn: &Connection) -> Result<T>
pub fn fetch_one(self, conn: &Connection) -> Result<T>
Execute and return exactly one scalar value.
§Errors
Returns Error::Conversion if the query returns zero rows.
Sourcepub fn fetch_optional(self, conn: &Connection) -> Result<Option<T>>
pub fn fetch_optional(self, conn: &Connection) -> Result<Option<T>>
Execute and return Some(value) for the first row, or None.
§Errors
Returns a hyperdb_api::Error on connection or SQL failure.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for QueryScalar<T>
impl<T> RefUnwindSafe for QueryScalar<T>
impl<T> Send for QueryScalar<T>
impl<T> Sync for QueryScalar<T>
impl<T> Unpin for QueryScalar<T>
impl<T> UnsafeUnpin for QueryScalar<T>
impl<T> UnwindSafe for QueryScalar<T>
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request