Skip to main content

Queryer

Trait Queryer 

Source
pub trait Queryer: Send + Sync {
    // Required methods
    async fn query_raw(
        &self,
        sql: &str,
        params: &[&dyn ToSql],
    ) -> Result<Vec<Row>, PgError>;
    async fn execute_raw(
        &self,
        sql: &str,
        params: &[&dyn ToSql],
    ) -> Result<u64, PgError>;

    // Provided methods
    async fn query<T: FromSql>(
        &self,
        sql: &str,
        params: &[&dyn ToSql],
    ) -> Result<Vec<Vec<T>>, PgError> { ... }
    async fn query_as<T: FromRow>(
        &self,
        sql: &str,
        params: &[&dyn ToSql],
    ) -> Result<Vec<T>, PgError> { ... }
    async fn query_one_as<T: FromRow>(
        &self,
        sql: &str,
        params: &[&dyn ToSql],
    ) -> Result<T, PgError> { ... }
    async fn query_first_as<T: FromRow>(
        &self,
        sql: &str,
        params: &[&dyn ToSql],
    ) -> Result<Option<T>, PgError> { ... }
    async fn query_first<T: FromSql>(
        &self,
        sql: &str,
        params: &[&dyn ToSql],
    ) -> Result<Option<T>, PgError> { ... }
}
Expand description

Trait for anything that can execute SQL queries. Implemented for Connection, Pool, Transaction. All methods take &self thanks to interior mutability.

Required Methods§

Source

async fn query_raw( &self, sql: &str, params: &[&dyn ToSql], ) -> Result<Vec<Row>, PgError>

Source

async fn execute_raw( &self, sql: &str, params: &[&dyn ToSql], ) -> Result<u64, PgError>

Provided Methods§

Source

async fn query<T: FromSql>( &self, sql: &str, params: &[&dyn ToSql], ) -> Result<Vec<Vec<T>>, PgError>

Source

async fn query_as<T: FromRow>( &self, sql: &str, params: &[&dyn ToSql], ) -> Result<Vec<T>, PgError>

Source

async fn query_one_as<T: FromRow>( &self, sql: &str, params: &[&dyn ToSql], ) -> Result<T, PgError>

Source

async fn query_first_as<T: FromRow>( &self, sql: &str, params: &[&dyn ToSql], ) -> Result<Option<T>, PgError>

Source

async fn query_first<T: FromSql>( &self, sql: &str, params: &[&dyn ToSql], ) -> Result<Option<T>, PgError>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: Queryer + Send + Sync + ?Sized> Queryer for &T

Source§

async fn query_raw( &self, sql: &str, params: &[&dyn ToSql], ) -> Result<Vec<Row>, PgError>

Source§

async fn execute_raw( &self, sql: &str, params: &[&dyn ToSql], ) -> Result<u64, PgError>

Implementors§