Trait sqlm_postgres::Connection

source ·
pub trait Connection: Send + Sync {
    // Required methods
    fn query_one<'a>(
        &'a self,
        query: &'a str,
        parameters: &'a [&'a (dyn ToSql + Sync)],
    ) -> impl Future<Output = Result<Row, Error>> + Send + 'a;
    fn query_opt<'a>(
        &'a self,
        query: &'a str,
        parameters: &'a [&'a (dyn ToSql + Sync)],
    ) -> impl Future<Output = Result<Option<Row>, Error>> + Send + 'a;
    fn query<'a>(
        &'a self,
        query: &'a str,
        parameters: &'a [&'a (dyn ToSql + Sync)],
    ) -> impl Future<Output = Result<Vec<Row>, Error>> + Send + 'a;
    fn execute<'a>(
        &'a self,
        query: &'a str,
        parameters: &'a [&'a (dyn ToSql + Sync)],
    ) -> impl Future<Output = Result<(), Error>> + Send + 'a;
}
Expand description

A trait used to allow functions to accept connections without having to explicit about whether it’s a transaction or not.

§Example

pub async fn fetch_username(id: i64, conn: impl Connection) -> Result<String, sqlm_postgres::Error> {
    sql!("SELECT name FROM users WHERE id = {id}")
        .run_with(conn)
        .await
}

Required Methods§

source

fn query_one<'a>( &'a self, query: &'a str, parameters: &'a [&'a (dyn ToSql + Sync)], ) -> impl Future<Output = Result<Row, Error>> + Send + 'a

source

fn query_opt<'a>( &'a self, query: &'a str, parameters: &'a [&'a (dyn ToSql + Sync)], ) -> impl Future<Output = Result<Option<Row>, Error>> + Send + 'a

source

fn query<'a>( &'a self, query: &'a str, parameters: &'a [&'a (dyn ToSql + Sync)], ) -> impl Future<Output = Result<Vec<Row>, Error>> + Send + 'a

source

fn execute<'a>( &'a self, query: &'a str, parameters: &'a [&'a (dyn ToSql + Sync)], ) -> impl Future<Output = Result<(), Error>> + Send + 'a

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Connection for Client

source§

fn query_one<'a>( &'a self, query: &'a str, parameters: &'a [&'a (dyn ToSql + Sync)], ) -> impl Future<Output = Result<Row, Error>> + Send + 'a

source§

fn query_opt<'a>( &'a self, query: &'a str, parameters: &'a [&'a (dyn ToSql + Sync)], ) -> impl Future<Output = Result<Option<Row>, Error>> + Send + 'a

source§

fn query<'a>( &'a self, query: &'a str, parameters: &'a [&'a (dyn ToSql + Sync)], ) -> impl Future<Output = Result<Vec<Row>, Error>> + Send + 'a

source§

fn execute<'a>( &'a self, query: &'a str, parameters: &'a [&'a (dyn ToSql + Sync)], ) -> impl Future<Output = Result<(), Error>> + Send + 'a

source§

impl<'b, C> Connection for &'b C
where C: Connection,

source§

fn query_one<'a>( &'a self, query: &'a str, parameters: &'a [&'a (dyn ToSql + Sync)], ) -> impl Future<Output = Result<Row, Error>> + Send + 'a

source§

fn query_opt<'a>( &'a self, query: &'a str, parameters: &'a [&'a (dyn ToSql + Sync)], ) -> impl Future<Output = Result<Option<Row>, Error>> + Send + 'a

source§

fn query<'a>( &'a self, query: &'a str, parameters: &'a [&'a (dyn ToSql + Sync)], ) -> impl Future<Output = Result<Vec<Row>, Error>> + Send + 'a

source§

fn execute<'a>( &'a self, query: &'a str, parameters: &'a [&'a (dyn ToSql + Sync)], ) -> impl Future<Output = Result<(), Error>> + Send + 'a

source§

impl<'t> Connection for Transaction<'t>

source§

fn query_one<'a>( &'a self, query: &'a str, parameters: &'a [&'a (dyn ToSql + Sync)], ) -> impl Future<Output = Result<Row, Error>> + Send + 'a

source§

fn query_opt<'a>( &'a self, query: &'a str, parameters: &'a [&'a (dyn ToSql + Sync)], ) -> impl Future<Output = Result<Option<Row>, Error>> + Send + 'a

source§

fn query<'a>( &'a self, query: &'a str, parameters: &'a [&'a (dyn ToSql + Sync)], ) -> impl Future<Output = Result<Vec<Row>, Error>> + Send + 'a

source§

fn execute<'a>( &'a self, query: &'a str, parameters: &'a [&'a (dyn ToSql + Sync)], ) -> impl Future<Output = Result<(), Error>> + Send + 'a

Implementors§