pub struct Query<'q, DB: Database, A> { /* private fields */ }
Expand description
Raw SQL query with bind parameters. Returned by query
.
Implementations
sourceimpl<'q, DB: Database> Query<'q, DB, <DB as HasArguments<'q>>::Arguments>
impl<'q, DB: Database> Query<'q, DB, <DB as HasArguments<'q>>::Arguments>
sourcepub fn bind<T: 'q + Send + Encode<'q, DB> + Type<DB>>(self, value: T) -> Self
pub fn bind<T: 'q + Send + Encode<'q, DB> + Type<DB>>(self, value: T) -> Self
Bind a value for use with this SQL query.
If the number of times this is called does not match the number of bind parameters that
appear in the query (?
for most SQL flavors, $1 .. $N
for Postgres) then an error
will be returned when this query is executed.
There is no validation that the value is of the type expected by the query. Most SQL flavors will perform type coercion (Postgres will return a database error).
sourceimpl<'q, DB, A> Query<'q, DB, A> where
DB: Database + HasStatementCache,
impl<'q, DB, A> Query<'q, DB, A> where
DB: Database + HasStatementCache,
sourcepub fn persistent(self, value: bool) -> Self
pub fn persistent(self, value: bool) -> Self
If true
, the statement will get prepared once and cached to the
connection’s statement cache.
If queried once with the flag set to true
, all subsequent queries
matching the one with the flag will use the cached statement until the
cache is cleared.
Default: true
.
sourceimpl<'q, DB, A: Send> Query<'q, DB, A> where
DB: Database,
A: 'q + IntoArguments<'q, DB>,
impl<'q, DB, A: Send> Query<'q, DB, A> where
DB: Database,
A: 'q + IntoArguments<'q, DB>,
sourcepub fn map<F, O>(
self,
f: F
) -> Map<'q, DB, impl FnMut(DB::Row) -> Result<O, Error> + Send, A> where
F: FnMut(DB::Row) -> O + Send,
O: Unpin,
pub fn map<F, O>(
self,
f: F
) -> Map<'q, DB, impl FnMut(DB::Row) -> Result<O, Error> + Send, A> where
F: FnMut(DB::Row) -> O + Send,
O: Unpin,
sourcepub fn try_map<F, O>(self, f: F) -> Map<'q, DB, F, A> where
F: FnMut(DB::Row) -> Result<O, Error> + Send,
O: Unpin,
pub fn try_map<F, O>(self, f: F) -> Map<'q, DB, F, A> where
F: FnMut(DB::Row) -> Result<O, Error> + Send,
O: Unpin,
sourcepub async fn execute<'e, 'c: 'e, E>(
self,
executor: E
) -> Result<DB::QueryResult, Error> where
'q: 'e,
A: 'e,
E: Executor<'c, Database = DB>,
pub async fn execute<'e, 'c: 'e, E>(
self,
executor: E
) -> Result<DB::QueryResult, Error> where
'q: 'e,
A: 'e,
E: Executor<'c, Database = DB>,
Execute the query and return the total number of rows affected.
sourcepub async fn execute_many<'e, 'c: 'e, E>(
self,
executor: E
) -> BoxStream<'e, Result<DB::QueryResult, Error>> where
'q: 'e,
A: 'e,
E: Executor<'c, Database = DB>,
pub async fn execute_many<'e, 'c: 'e, E>(
self,
executor: E
) -> BoxStream<'e, Result<DB::QueryResult, Error>> where
'q: 'e,
A: 'e,
E: Executor<'c, Database = DB>,
Execute multiple queries and return the rows affected from each query, in a stream.
sourcepub fn fetch<'e, 'c: 'e, E>(
self,
executor: E
) -> BoxStream<'e, Result<DB::Row, Error>> where
'q: 'e,
A: 'e,
E: Executor<'c, Database = DB>,
pub fn fetch<'e, 'c: 'e, E>(
self,
executor: E
) -> BoxStream<'e, Result<DB::Row, Error>> where
'q: 'e,
A: 'e,
E: Executor<'c, Database = DB>,
Execute the query and return the generated results as a stream.
sourcepub fn fetch_many<'e, 'c: 'e, E>(
self,
executor: E
) -> BoxStream<'e, Result<Either<DB::QueryResult, DB::Row>, Error>> where
'q: 'e,
A: 'e,
E: Executor<'c, Database = DB>,
pub fn fetch_many<'e, 'c: 'e, E>(
self,
executor: E
) -> BoxStream<'e, Result<Either<DB::QueryResult, DB::Row>, Error>> where
'q: 'e,
A: 'e,
E: Executor<'c, Database = DB>,
Execute multiple queries and return the generated results as a stream from each query, in a stream.
sourcepub async fn fetch_all<'e, 'c: 'e, E>(
self,
executor: E
) -> Result<Vec<DB::Row>, Error> where
'q: 'e,
A: 'e,
E: Executor<'c, Database = DB>,
pub async fn fetch_all<'e, 'c: 'e, E>(
self,
executor: E
) -> Result<Vec<DB::Row>, Error> where
'q: 'e,
A: 'e,
E: Executor<'c, Database = DB>,
Execute the query and return all the generated results, collected into a Vec
.
Trait Implementations
sourceimpl<'q, DB, A> Execute<'q, DB> for Query<'q, DB, A> where
DB: Database,
A: Send + IntoArguments<'q, DB>,
impl<'q, DB, A> Execute<'q, DB> for Query<'q, DB, A> where
DB: Database,
A: Send + IntoArguments<'q, DB>,
sourcefn statement(&self) -> Option<&<DB as HasStatement<'q>>::Statement>
fn statement(&self) -> Option<&<DB as HasStatement<'q>>::Statement>
Gets the previously cached statement, if available.
sourcefn take_arguments(&mut self) -> Option<<DB as HasArguments<'q>>::Arguments>
fn take_arguments(&mut self) -> Option<<DB as HasArguments<'q>>::Arguments>
Returns the arguments to be bound against the query string. Read more
sourcefn persistent(&self) -> bool
fn persistent(&self) -> bool
Returns true
if the statement should be cached.
Auto Trait Implementations
impl<'q, DB, A> RefUnwindSafe for Query<'q, DB, A> where
A: RefUnwindSafe,
DB: RefUnwindSafe,
<DB as HasStatement<'q>>::Statement: RefUnwindSafe,
impl<'q, DB, A> Send for Query<'q, DB, A> where
A: Send,
impl<'q, DB, A> Sync for Query<'q, DB, A> where
A: Sync,
DB: Sync,
impl<'q, DB, A> Unpin for Query<'q, DB, A> where
A: Unpin,
DB: Unpin,
impl<'q, DB, A> UnwindSafe for Query<'q, DB, A> where
A: UnwindSafe,
DB: UnwindSafe,
<DB as HasStatement<'q>>::Statement: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more