Skip to main content

Client

Trait Client 

Source
pub trait Client: Send + Sync {
    type Error: Error + Send + Sync + 'static;
    type Row: Row;
    type Transaction<'a>: Transaction<Error = Self::Error, Row = Self::Row> + 'a
       where Self: 'a;

    // Required methods
    fn query(
        &self,
        sql: &str,
        params: &[&dyn ToSqlParam],
    ) -> impl Future<Output = Result<Vec<Self::Row>, Self::Error>> + Send;
    fn execute(
        &self,
        sql: &str,
        params: &[&dyn ToSqlParam],
    ) -> impl Future<Output = Result<u64, Self::Error>> + Send;
    fn transaction(
        &mut self,
    ) -> impl Future<Output = Result<Self::Transaction<'_>, Self::Error>> + Send;
}
Expand description

Trait for executing SQL queries against a database. Uses impl Future instead of async_trait to avoid proc macro compile overhead.

This trait is backend-agnostic: implementations exist for PostgreSQL (tokio-postgres), and can be added for MySQL, SQLite, etc.

Required Associated Types§

Source

type Error: Error + Send + Sync + 'static

Source

type Row: Row

Source

type Transaction<'a>: Transaction<Error = Self::Error, Row = Self::Row> + 'a where Self: 'a

Required Methods§

Source

fn query( &self, sql: &str, params: &[&dyn ToSqlParam], ) -> impl Future<Output = Result<Vec<Self::Row>, Self::Error>> + Send

Execute a query that returns rows.

Source

fn execute( &self, sql: &str, params: &[&dyn ToSqlParam], ) -> impl Future<Output = Result<u64, Self::Error>> + Send

Execute a statement that returns the number of affected rows.

Source

fn transaction( &mut self, ) -> impl Future<Output = Result<Self::Transaction<'_>, Self::Error>> + Send

Begin a new transaction.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§