Struct sqlx_core::raw_sql::RawSql

source ·
pub struct RawSql<'q>(/* private fields */);
Expand description

One or more raw SQL statements, separated by semicolons (;).

See raw_sql() for details.

Implementations§

source§

impl<'q> RawSql<'q>

source

pub async fn execute<'e, E>( self, executor: E, ) -> Result<<E::Database as Database>::QueryResult>
where E: Executor<'e>, 'q: 'e,

Execute the SQL string and return the total number of rows affected.

source

pub fn execute_many<'e, E>( self, executor: E, ) -> BoxStream<'e, Result<<E::Database as Database>::QueryResult>>
where E: Executor<'e>, 'q: 'e,

Execute the SQL string. Returns a stream which gives the number of rows affected for each statement in the string.

source

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

Execute the SQL string and return the generated results as a stream.

If the string contains multiple statements, their results will be concatenated together.

source

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

Execute the SQL string 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, E>( self, executor: E, ) -> Result<Vec<<E::Database as Database>::Row>>
where E: Executor<'e>, 'q: 'e,

Execute the SQL string 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, E>( self, executor: E, ) -> Result<<E::Database as Database>::Row>
where E: Executor<'e>, 'q: 'e,

Execute the SQL string, 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, E>( self, executor: E, ) -> Result<<E::Database as Database>::Row>
where E: Executor<'e>, 'q: 'e,

Execute the SQL string, 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> Execute<'q, DB> for RawSql<'q>

source§

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

Gets the SQL that will be executed.
source§

fn statement(&self) -> Option<&<DB as HasStatement<'q>>::Statement>

Gets the previously cached statement, if available.
source§

fn take_arguments(&mut self) -> Option<<DB as HasArguments<'q>>::Arguments>

Returns the arguments to be bound against the query string. Read more
source§

fn persistent(&self) -> bool

Returns true if the statement should be cached.

Auto Trait Implementations§

§

impl<'q> Freeze for RawSql<'q>

§

impl<'q> RefUnwindSafe for RawSql<'q>

§

impl<'q> Send for RawSql<'q>

§

impl<'q> Sync for RawSql<'q>

§

impl<'q> Unpin for RawSql<'q>

§

impl<'q> UnwindSafe for RawSql<'q>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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