Trait sqlx::Statement

source ·
pub trait Statement<'q>: Send + Sync {
    type Database: Database;

    // Required methods
    fn to_owned(&self) -> <Self::Database as HasStatement<'static>>::Statement;
    fn sql(&self) -> &str;
    fn parameters(
        &self
    ) -> Option<Either<&[<Self::Database as Database>::TypeInfo], usize>>;
    fn columns(&self) -> &[<Self::Database as Database>::Column];
    fn query(
        &self
    ) -> Query<'_, Self::Database, <Self::Database as HasArguments<'_>>::Arguments>;
    fn query_with<'s, A>(&'s self, arguments: A) -> Query<'s, Self::Database, A>
       where A: IntoArguments<'s, Self::Database>;
    fn query_as<O>(
        &self
    ) -> QueryAs<'_, Self::Database, O, <Self::Database as HasArguments<'_>>::Arguments>
       where O: for<'r> FromRow<'r, <Self::Database as Database>::Row>;
    fn query_as_with<'s, O, A>(
        &'s self,
        arguments: A
    ) -> QueryAs<'s, Self::Database, O, A>
       where O: for<'r> FromRow<'r, <Self::Database as Database>::Row>,
             A: IntoArguments<'s, Self::Database>;
    fn query_scalar<O>(
        &self
    ) -> QueryScalar<'_, Self::Database, O, <Self::Database as HasArguments<'_>>::Arguments>
       where (O,): for<'r> FromRow<'r, <Self::Database as Database>::Row>;
    fn query_scalar_with<'s, O, A>(
        &'s self,
        arguments: A
    ) -> QueryScalar<'s, Self::Database, O, A>
       where (O,): for<'r> FromRow<'r, <Self::Database as Database>::Row>,
             A: IntoArguments<'s, Self::Database>;

    // Provided methods
    fn column<I>(&self, index: I) -> &<Self::Database as Database>::Column
       where I: ColumnIndex<Self> { ... }
    fn try_column<I>(
        &self,
        index: I
    ) -> Result<&<Self::Database as Database>::Column, Error>
       where I: ColumnIndex<Self> { ... }
}
Expand description

An explicitly prepared statement.

Statements are prepared and cached by default, per connection. This type allows you to look at that cache in-between the statement being prepared and it being executed. This contains the expected columns to be returned and the expected parameter types (if available).

Statements can be re-used with any connection and on first-use it will be re-prepared and cached within the connection.

Required Associated Types§

Required Methods§

source

fn to_owned(&self) -> <Self::Database as HasStatement<'static>>::Statement

Creates an owned statement from this statement reference. This copies the original SQL text.

source

fn sql(&self) -> &str

Get the original SQL text used to create this statement.

source

fn parameters( &self ) -> Option<Either<&[<Self::Database as Database>::TypeInfo], usize>>

Get the expected parameters for this statement.

The information returned depends on what is available from the driver. SQLite can only tell us the number of parameters. PostgreSQL can give us full type information.

source

fn columns(&self) -> &[<Self::Database as Database>::Column]

Get the columns expected to be returned by executing this statement.

source

fn query( &self ) -> Query<'_, Self::Database, <Self::Database as HasArguments<'_>>::Arguments>

source

fn query_with<'s, A>(&'s self, arguments: A) -> Query<'s, Self::Database, A>
where A: IntoArguments<'s, Self::Database>,

source

fn query_as<O>( &self ) -> QueryAs<'_, Self::Database, O, <Self::Database as HasArguments<'_>>::Arguments>
where O: for<'r> FromRow<'r, <Self::Database as Database>::Row>,

source

fn query_as_with<'s, O, A>( &'s self, arguments: A ) -> QueryAs<'s, Self::Database, O, A>
where O: for<'r> FromRow<'r, <Self::Database as Database>::Row>, A: IntoArguments<'s, Self::Database>,

source

fn query_scalar<O>( &self ) -> QueryScalar<'_, Self::Database, O, <Self::Database as HasArguments<'_>>::Arguments>
where (O,): for<'r> FromRow<'r, <Self::Database as Database>::Row>,

source

fn query_scalar_with<'s, O, A>( &'s self, arguments: A ) -> QueryScalar<'s, Self::Database, O, A>
where (O,): for<'r> FromRow<'r, <Self::Database as Database>::Row>, A: IntoArguments<'s, Self::Database>,

Provided Methods§

source

fn column<I>(&self, index: I) -> &<Self::Database as Database>::Column
where I: ColumnIndex<Self>,

Gets the column information at index.

A string index can be used to access a column by name and a usize index can be used to access a column by position.

§Panics

Panics if index is out of bounds. See try_column for a non-panicking version.

source

fn try_column<I>( &self, index: I ) -> Result<&<Self::Database as Database>::Column, Error>
where I: ColumnIndex<Self>,

Gets the column information at index or a ColumnIndexOutOfBounds error if out of bounds.

Object Safety§

This trait is not object safe.

Implementors§