SqlTemplateExecute

Struct SqlTemplateExecute 

Source
pub struct SqlTemplateExecute<'q, DB: Database> { /* private fields */ }
Expand description

Internal executor for SQL templates

Implementations§

Source§

impl<'q, DB: Database> SqlTemplateExecute<'q, DB>

Source

pub fn new(sql: &'q str, arguments: Option<DB::Arguments<'q>>) -> Self

Creates a new SQL template executor

Source

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>
where DB: Database + HasStatementCache, DB::Arguments<'q>: IntoArguments<'q, DB>,

Source

pub fn to_query_as<O>(self) -> QueryAs<'q, DB, O, DB::Arguments<'q>>
where O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,

to sqlx_core::QueryAs Converts the SQL template to a QueryAs object, which can be executed to fetch rows

Source

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

pub fn map<F, O>( self, f: F, ) -> Map<'q, DB, impl FnMut(DB::Row) -> Result<O, Error> + Send, DB::Arguments<'q>>
where F: FnMut(DB::Row) -> O + Send, O: Unpin,

like sqlx_core::Query::map Map each row in the result to another type.

Source

pub fn try_map<F, O>(self, f: F) -> Map<'q, DB, F, DB::Arguments<'q>>
where F: FnMut(DB::Row) -> Result<O, Error> + Send, O: Unpin,

like sqlx_core::Query::try_map Map each row in the result to another type, returning an error if the mapping fails.

Source§

impl<'q, DB> SqlTemplateExecute<'q, DB>
where DB: Database,

Source

pub async fn execute<'e, 'c: 'e, E>( self, executor: E, ) -> Result<DB::QueryResult, Error>
where DB::Arguments<'q>: 'e, E: Executor<'c, Database = DB>, 'q: 'e,

like sqlx_core::Query::execute Execute the query and return the number of rows affected.

Source

pub fn execute_many<'e, 'c: 'e, E>( self, executor: E, ) -> BoxStream<'e, Result<DB::QueryResult, Error>>
where DB::Arguments<'q>: 'e, E: Executor<'c, Database = DB>, 'q: 'e,

like sqlx_core::Query::execute_many Execute multiple queries and return the rows affected from each query, in a stream.

Source

pub fn fetch<'e, 'c: 'e, E>( self, executor: E, ) -> BoxStream<'e, Result<DB::Row, Error>>
where DB::Arguments<'q>: 'e, E: Executor<'c, Database = DB>, 'q: 'e,

like sqlx_core::Query::fetch Execute the query and return the generated results as a stream.

Source

pub fn fetch_many<'e, 'c: 'e, E>( self, executor: E, ) -> BoxStream<'e, Result<Either<DB::QueryResult, DB::Row>, Error>>
where DB::Arguments<'q>: 'e, E: Executor<'c, Database = DB>, 'q: 'e,

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.

Source

pub async fn fetch_all<'e, 'c: 'e, E>( self, executor: E, ) -> Result<Vec<DB::Row>, Error>
where DB::Arguments<'q>: 'e, E: Executor<'c, Database = DB>, 'q: 'e,

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.

Source

pub async fn fetch_one<'e, 'c: 'e, E>( self, executor: E, ) -> Result<DB::Row, Error>
where DB::Arguments<'q>: 'e, E: Executor<'c, Database = DB>, 'q: 'e,

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.

Source

pub async fn fetch_optional<'e, 'c: 'e, E>( self, executor: E, ) -> Result<Option<DB::Row>, Error>
where DB::Arguments<'q>: 'e, E: Executor<'c, Database = DB>, 'q: 'e,

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.

Source

pub fn fetch_as<'e, 'c: 'e, O, E>( self, executor: E, ) -> BoxStream<'e, Result<O, Error>>
where DB::Arguments<'q>: 'e, E: 'e + Executor<'c, Database = DB>, DB: 'e, O: Send + Unpin + for<'r> FromRow<'r, DB::Row> + 'e, 'q: 'e,

like sqlx_core::QueryAs::fetch Execute the query and return the generated results as a stream.

Source

pub fn fetch_many_as<'e, 'c: 'e, O, E>( self, executor: E, ) -> BoxStream<'e, Result<Either<DB::QueryResult, O>, Error>>
where DB::Arguments<'q>: 'e, E: 'e + Executor<'c, Database = DB>, DB: 'e, O: Send + Unpin + for<'r> FromRow<'r, DB::Row> + 'e, 'q: 'e,

like sqlx_core::QueryAs::fetch_many Execute multiple queries and return the generated results as a stream from each query, in a stream.

Source

pub async fn fetch_all_as<'e, 'c: 'e, O, E>( self, executor: E, ) -> Result<Vec<O>, Error>
where DB::Arguments<'q>: 'e, E: 'e + Executor<'c, Database = DB>, DB: 'e, O: Send + Unpin + for<'r> FromRow<'r, DB::Row> + 'e, 'q: 'e,

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.

Source

pub async fn fetch_one_as<'e, 'c: 'e, O, E>( self, executor: E, ) -> Result<O, Error>
where DB::Arguments<'q>: 'e, E: 'e + Executor<'c, Database = DB>, DB: 'e, O: Send + Unpin + for<'r> FromRow<'r, DB::Row> + 'e, 'q: 'e,

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.

Source

pub async fn fetch_optional_as<'e, 'c: 'e, O, E>( self, executor: E, ) -> Result<Option<O>, Error>
where DB::Arguments<'q>: 'e, E: 'e + Executor<'c, Database = DB>, DB: 'e, O: Send + Unpin + for<'r> FromRow<'r, DB::Row> + 'e, 'q: 'e,

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>
where DB::Arguments<'q>: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'q, DB: Database> Execute<'q, DB> for SqlTemplateExecute<'q, DB>

Source§

fn sql(&self) -> &'q str

Returns the SQL query string

Source§

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>

Takes ownership of the bound arguments

Source§

fn persistent(&self) -> bool

Checks if query is persistent

Auto Trait Implementations§

§

impl<'q, DB> Freeze for SqlTemplateExecute<'q, DB>
where <DB as Database>::Arguments<'q>: Freeze,

§

impl<'q, DB> RefUnwindSafe for SqlTemplateExecute<'q, DB>
where <DB as Database>::Arguments<'q>: RefUnwindSafe,

§

impl<'q, DB> Send for SqlTemplateExecute<'q, DB>

§

impl<'q, DB> Sync for SqlTemplateExecute<'q, DB>
where <DB as Database>::Arguments<'q>: Sync,

§

impl<'q, DB> Unpin for SqlTemplateExecute<'q, DB>
where <DB as Database>::Arguments<'q>: Unpin,

§

impl<'q, DB> UnwindSafe for SqlTemplateExecute<'q, DB>
where <DB as Database>::Arguments<'q>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,