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§
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
Object Safety§
This trait is not object safe.