pub struct Query<'q, DB, A>where
DB: Database,{ /* private fields */ }
Expand description
Raw SQL query with bind parameters. Returned by query
.
Implementations§
Source§impl<'q, DB> Query<'q, DB, <DB as HasArguments<'q>>::Arguments>where
DB: Database,
impl<'q, DB> Query<'q, DB, <DB as HasArguments<'q>>::Arguments>where
DB: Database,
Sourcepub fn bind<T>(
self,
value: T,
) -> Query<'q, DB, <DB as HasArguments<'q>>::Arguments>
pub fn bind<T>( self, value: T, ) -> Query<'q, DB, <DB as HasArguments<'q>>::Arguments>
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).
Source§impl<'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) -> Query<'q, DB, A>
pub fn persistent(self, value: bool) -> Query<'q, DB, A>
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
.
Source§impl<'q, DB, A> Query<'q, DB, A>
impl<'q, DB, A> Query<'q, DB, A>
Sourcepub async fn execute<'e, 'c, E>(
self,
executor: E,
) -> Result<<DB as Database>::QueryResult, Error>where
'c: 'e,
'q: 'e,
A: 'e,
E: Executor<'c, Database = DB>,
pub async fn execute<'e, 'c, E>(
self,
executor: E,
) -> Result<<DB as Database>::QueryResult, Error>where
'c: 'e,
'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>(
self,
executor: E,
) -> Pin<Box<dyn Stream<Item = Result<<DB as Database>::QueryResult, Error>> + Send + 'e>>where
'c: 'e,
'q: 'e,
A: 'e,
E: Executor<'c, Database = DB>,
pub async fn execute_many<'e, 'c, E>(
self,
executor: E,
) -> Pin<Box<dyn Stream<Item = Result<<DB as Database>::QueryResult, Error>> + Send + 'e>>where
'c: 'e,
'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>(
self,
executor: E,
) -> Pin<Box<dyn Stream<Item = Result<<DB as Database>::Row, Error>> + Send + 'e>>where
'c: 'e,
'q: 'e,
A: 'e,
E: Executor<'c, Database = DB>,
pub fn fetch<'e, 'c, E>(
self,
executor: E,
) -> Pin<Box<dyn Stream<Item = Result<<DB as Database>::Row, Error>> + Send + 'e>>where
'c: 'e,
'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>(
self,
executor: E,
) -> Pin<Box<dyn Stream<Item = Result<Either<<DB as Database>::QueryResult, <DB as Database>::Row>, Error>> + Send + 'e>>where
'c: 'e,
'q: 'e,
A: 'e,
E: Executor<'c, Database = DB>,
pub fn fetch_many<'e, 'c, E>(
self,
executor: E,
) -> Pin<Box<dyn Stream<Item = Result<Either<<DB as Database>::QueryResult, <DB as Database>::Row>, Error>> + Send + 'e>>where
'c: 'e,
'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>(
self,
executor: E,
) -> Result<Vec<<DB as Database>::Row>, Error>where
'c: 'e,
'q: 'e,
A: 'e,
E: Executor<'c, Database = DB>,
pub async fn fetch_all<'e, 'c, E>(
self,
executor: E,
) -> Result<Vec<<DB as Database>::Row>, Error>where
'c: 'e,
'q: 'e,
A: 'e,
E: Executor<'c, Database = DB>,
Execute the query and return all the generated results, collected into a Vec
.
Trait Implementations§
Source§impl<'q, DB, A> Execute<'q, DB> for Query<'q, DB, A>
impl<'q, DB, A> Execute<'q, DB> for Query<'q, DB, A>
Source§fn statement(&self) -> Option<&<DB as HasStatement<'q>>::Statement>
fn statement(&self) -> Option<&<DB as HasStatement<'q>>::Statement>
Source§fn take_arguments(&mut self) -> Option<<DB as HasArguments<'q>>::Arguments>
fn take_arguments(&mut self) -> Option<<DB as HasArguments<'q>>::Arguments>
Source§fn persistent(&self) -> bool
fn persistent(&self) -> bool
true
if the statement should be cached.Auto Trait Implementations§
impl<'q, DB, A> Freeze for Query<'q, DB, A>where
A: Freeze,
impl<'q, DB, A> RefUnwindSafe for Query<'q, DB, A>
impl<'q, DB, A> Send for Query<'q, DB, A>where
A: Send,
impl<'q, DB, A> Sync for Query<'q, DB, A>
impl<'q, DB, A> Unpin for Query<'q, DB, A>
impl<'q, DB, A> UnwindSafe for Query<'q, DB, A>
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
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