pub struct SqlTemplateExecute<'q, DB: Database> { /* private fields */ }
Expand description
Internal executor for SQL templates
Implementations§
Source§impl<'q, DB: Database> SqlTemplateExecute<'q, DB>
impl<'q, DB: Database> SqlTemplateExecute<'q, DB>
Sourcepub fn new(sql: &'q str, arguments: Option<DB::Arguments<'q>>) -> Self
pub fn new(sql: &'q str, arguments: Option<DB::Arguments<'q>>) -> Self
Creates a new SQL template executor
Sourcepub fn set_persistent(self, persistent: bool) -> Self
pub fn set_persistent(self, persistent: 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.
If false
, the prepared statement will be closed after execution.
Default: true
.
Source§impl<'q, DB> SqlTemplateExecute<'q, DB>
impl<'q, DB> SqlTemplateExecute<'q, DB>
Sourcepub fn to_query_as<O>(self) -> QueryAs<'q, DB, O, DB::Arguments<'q>>
pub fn to_query_as<O>(self) -> QueryAs<'q, DB, O, DB::Arguments<'q>>
to sqlx_core::QueryAs
Converts the SQL template to a QueryAs
object, which can be executed to fetch rows
Sourcepub fn to_query(self) -> Query<'q, DB, DB::Arguments<'q>>
pub fn to_query(self) -> Query<'q, DB, DB::Arguments<'q>>
to sqlx_core::Query
Converts the SQL template to a Query
object, which can be executed to fetch rows
Source§impl<'q, DB> SqlTemplateExecute<'q, DB>where
DB: Database,
impl<'q, DB> SqlTemplateExecute<'q, DB>where
DB: Database,
Sourcepub async fn execute<'e, 'c: 'e, E>(
self,
executor: E,
) -> Result<DB::QueryResult, Error>
pub async fn execute<'e, 'c: 'e, E>( self, executor: E, ) -> Result<DB::QueryResult, Error>
like sqlx_core::Query::execute Execute the query and return the number of rows affected.
Sourcepub fn execute_many<'e, 'c: 'e, E>(
self,
executor: E,
) -> BoxStream<'e, Result<DB::QueryResult, Error>>
pub fn execute_many<'e, 'c: 'e, E>( self, executor: E, ) -> BoxStream<'e, Result<DB::QueryResult, Error>>
like sqlx_core::Query::execute_many 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>>
pub fn fetch<'e, 'c: 'e, E>( self, executor: E, ) -> BoxStream<'e, Result<DB::Row, Error>>
like sqlx_core::Query::fetch 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>>
pub fn fetch_many<'e, 'c: 'e, E>( self, executor: E, ) -> BoxStream<'e, Result<Either<DB::QueryResult, DB::Row>, Error>>
like sqlx_core::Query::fetch_many Execute multiple queries and return the generated results as a stream.
For each query in the stream, any generated rows are returned first,
then the QueryResult
with the number of rows affected.
Sourcepub async fn fetch_all<'e, 'c: 'e, E>(
self,
executor: E,
) -> Result<Vec<DB::Row>, Error>
pub async fn fetch_all<'e, 'c: 'e, E>( self, executor: E, ) -> Result<Vec<DB::Row>, Error>
like sqlx_core::Query::fetch_all
Execute the query and return all the resulting rows collected into a Vec
.
§Note: beware result set size.
This will attempt to collect the full result set of the query into memory.
To avoid exhausting available memory, ensure the result set has a known upper bound,
e.g. using LIMIT
.
Sourcepub async fn fetch_one<'e, 'c: 'e, E>(
self,
executor: E,
) -> Result<DB::Row, Error>
pub async fn fetch_one<'e, 'c: 'e, E>( self, executor: E, ) -> Result<DB::Row, Error>
like sqlx_core::Query::fetch_one
Execute the query, returning the first row or Error::RowNotFound
otherwise.
§Note: for best performance, ensure the query returns at most one row.
Depending on the driver implementation, if your query can return more than one row, it may lead to wasted CPU time and bandwidth on the database server.
Even when the driver implementation takes this into account, ensuring the query returns at most one row can result in a more optimal query plan.
If your query has a WHERE
clause filtering a unique column by a single value, you’re good.
Otherwise, you might want to add LIMIT 1
to your query.
Sourcepub async fn fetch_optional<'e, 'c: 'e, E>(
self,
executor: E,
) -> Result<Option<DB::Row>, Error>
pub async fn fetch_optional<'e, 'c: 'e, E>( self, executor: E, ) -> Result<Option<DB::Row>, Error>
like sqlx_core::Query::fetch_optional
Execute the query, returning the first row or None
otherwise.
§Note: for best performance, ensure the query returns at most one row.
Depending on the driver implementation, if your query can return more than one row, it may lead to wasted CPU time and bandwidth on the database server.
Even when the driver implementation takes this into account, ensuring the query returns at most one row can result in a more optimal query plan.
If your query has a WHERE
clause filtering a unique column by a single value, you’re good.
Otherwise, you might want to add LIMIT 1
to your query.
Sourcepub fn fetch_as<'e, 'c: 'e, O, E>(
self,
executor: E,
) -> BoxStream<'e, Result<O, Error>>
pub fn fetch_as<'e, 'c: 'e, O, E>( self, executor: E, ) -> BoxStream<'e, Result<O, Error>>
like sqlx_core::QueryAs::fetch Execute the query and return the generated results as a stream.
Sourcepub fn fetch_many_as<'e, 'c: 'e, O, E>(
self,
executor: E,
) -> BoxStream<'e, Result<Either<DB::QueryResult, O>, Error>>
pub fn fetch_many_as<'e, 'c: 'e, O, E>( self, executor: E, ) -> BoxStream<'e, Result<Either<DB::QueryResult, O>, Error>>
like sqlx_core::QueryAs::fetch_many Execute multiple queries and return the generated results as a stream from each query, in a stream.
Sourcepub async fn fetch_all_as<'e, 'c: 'e, O, E>(
self,
executor: E,
) -> Result<Vec<O>, Error>
pub async fn fetch_all_as<'e, 'c: 'e, O, E>( self, executor: E, ) -> Result<Vec<O>, Error>
like sqlx_core::QueryAs::fetch_all
Execute the query and return all the resulting rows collected into a Vec
.
§Note: beware result set size.
This will attempt to collect the full result set of the query into memory.
To avoid exhausting available memory, ensure the result set has a known upper bound,
e.g. using LIMIT
.
Sourcepub async fn fetch_one_as<'e, 'c: 'e, O, E>(
self,
executor: E,
) -> Result<O, Error>
pub async fn fetch_one_as<'e, 'c: 'e, O, E>( self, executor: E, ) -> Result<O, Error>
like sqlx_core::QueryAs::fetch_one
Execute the query, returning the first row or Error::RowNotFound
otherwise.
§Note: for best performance, ensure the query returns at most one row.
Depending on the driver implementation, if your query can return more than one row, it may lead to wasted CPU time and bandwidth on the database server.
Even when the driver implementation takes this into account, ensuring the query returns at most one row can result in a more optimal query plan.
If your query has a WHERE
clause filtering a unique column by a single value, you’re good.
Otherwise, you might want to add LIMIT 1
to your query.
Sourcepub async fn fetch_optional_as<'e, 'c: 'e, O, E>(
self,
executor: E,
) -> Result<Option<O>, Error>
pub async fn fetch_optional_as<'e, 'c: 'e, O, E>( self, executor: E, ) -> Result<Option<O>, Error>
like sqlx_core_core::QueryAs::fetch_optional
Execute the query, returning the first row or None
otherwise.
§Note: for best performance, ensure the query returns at most one row.
Depending on the driver implementation, if your query can return more than one row, it may lead to wasted CPU time and bandwidth on the database server.
Even when the driver implementation takes this into account, ensuring the query returns at most one row can result in a more optimal query plan.
If your query has a WHERE
clause filtering a unique column by a single value, you’re good.
Otherwise, you might want to add LIMIT 1
to your query.
Trait Implementations§
Source§impl<'q, DB: Database> Clone for SqlTemplateExecute<'q, DB>
impl<'q, DB: Database> Clone for SqlTemplateExecute<'q, DB>
Source§impl<'q, DB: Database> Execute<'q, DB> for SqlTemplateExecute<'q, DB>
impl<'q, DB: Database> Execute<'q, DB> for SqlTemplateExecute<'q, DB>
Source§fn statement(&self) -> Option<&DB::Statement<'q>>
fn statement(&self) -> Option<&DB::Statement<'q>>
Gets prepared statement (not supported in this implementation)
Source§fn take_arguments(&mut self) -> Result<Option<DB::Arguments<'q>>, BoxDynError>
fn take_arguments(&mut self) -> Result<Option<DB::Arguments<'q>>, BoxDynError>
Takes ownership of the bound arguments
Source§fn persistent(&self) -> bool
fn persistent(&self) -> bool
Checks if query is persistent
Auto Trait Implementations§
impl<'q, DB> Freeze for SqlTemplateExecute<'q, DB>
impl<'q, DB> RefUnwindSafe for SqlTemplateExecute<'q, DB>
impl<'q, DB> Send for SqlTemplateExecute<'q, DB>
impl<'q, DB> Sync for SqlTemplateExecute<'q, DB>
impl<'q, DB> Unpin for SqlTemplateExecute<'q, DB>
impl<'q, DB> UnwindSafe for SqlTemplateExecute<'q, DB>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more