Skip to main content

GenericClient

Trait GenericClient 

Source
pub trait GenericClient {
    // Required methods
    async fn query(
        &mut self,
        sql: &str,
        params: &[&(dyn ToSql + Sync)],
    ) -> Result<Vec<Row>>;
    async fn query_one(
        &mut self,
        sql: &str,
        params: &[&(dyn ToSql + Sync)],
    ) -> Result<Row>;
    async fn query_opt(
        &mut self,
        sql: &str,
        params: &[&(dyn ToSql + Sync)],
    ) -> Result<Option<Row>>;
    async fn execute(
        &mut self,
        sql: &str,
        params: &[&(dyn ToSql + Sync)],
    ) -> Result<u64>;
    async fn simple_query(
        &mut self,
        sql: &str,
    ) -> Result<Vec<SimpleQueryMessage>>;
}
Expand description

A trait for types that can execute PostgreSQL queries.

Allows writing code that is generic over Connection and PooledConnection.

use sentinel_driver::{GenericClient, Result, Row};

async fn get_user_name(client: &mut impl GenericClient, id: i32) -> Result<String> {
    let row = client.query_one("SELECT name FROM users WHERE id = $1", &[&id]).await?;
    row.try_get(0)
}

Required Methods§

Source

async fn query( &mut self, sql: &str, params: &[&(dyn ToSql + Sync)], ) -> Result<Vec<Row>>

Execute a query that returns rows.

Source

async fn query_one( &mut self, sql: &str, params: &[&(dyn ToSql + Sync)], ) -> Result<Row>

Execute a query that returns a single row.

Source

async fn query_opt( &mut self, sql: &str, params: &[&(dyn ToSql + Sync)], ) -> Result<Option<Row>>

Execute a query that returns an optional single row.

Source

async fn execute( &mut self, sql: &str, params: &[&(dyn ToSql + Sync)], ) -> Result<u64>

Execute a non-SELECT query, returning rows affected.

Source

async fn simple_query(&mut self, sql: &str) -> Result<Vec<SimpleQueryMessage>>

Execute a simple query (text protocol, no parameters).

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§