QueryExecutor

Trait QueryExecutor 

Source
pub trait QueryExecutor {
    type Output;

    // Required method
    fn execute<'life0, 'life1, 'async_trait>(
        &'life0 self,
        db: &'life1 Database,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Output>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Trait for executing queries with type-safe results

This trait is implemented by generated query functions to provide type-safe query execution.

§Example

// Generated code might look like:
struct GetUserQuery {
    id: Uuid,
}

#[async_trait]
impl QueryExecutor for GetUserQuery {
    type Output = User;

    async fn execute(&self, db: &Database) -> Result<Self::Output> {
        let result = db.execute_hyperql("SELECT * FROM users WHERE id = :id").await?;
        let row = result.one()?;
        User::from_row(row)
    }
}

Required Associated Types§

Source

type Output

The output type of the query

Required Methods§

Source

fn execute<'life0, 'life1, 'async_trait>( &'life0 self, db: &'life1 Database, ) -> Pin<Box<dyn Future<Output = Result<Self::Output>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute the query against the database

Implementors§