Skip to main content

QueryMethods

Trait QueryMethods 

Source
pub trait QueryMethods: Model {
    // Provided methods
    fn query() -> QueryBuilder<Self>
       where Self: Sized { ... }
    async fn all(pool: &Pool<Postgres>) -> ModelResult<Vec<Self>>
       where Self: Sized { ... }
    async fn count(pool: &Pool<Postgres>) -> ModelResult<i64>
       where Self: Sized { ... }
    async fn where_field<V>(
        pool: &Pool<Postgres>,
        field: &str,
        value: V,
    ) -> ModelResult<Vec<Self>>
       where Self: Sized,
             for<'q> V: Send + Sync + 'static + Encode<'q, Postgres> + Type<Postgres> { ... }
    async fn first_where<V>(
        pool: &Pool<Postgres>,
        field: &str,
        value: V,
    ) -> ModelResult<Option<Self>>
       where Self: Sized,
             for<'q> V: Send + Sync + 'static + Encode<'q, Postgres> + Type<Postgres> { ... }
    async fn first(pool: &Pool<Postgres>) -> ModelResult<Option<Self>>
       where Self: Sized { ... }
    async fn last(pool: &Pool<Postgres>) -> ModelResult<Option<Self>>
       where Self: Sized { ... }
}
Expand description

Trait providing query operations for model collections

Provided Methods§

Source

fn query() -> QueryBuilder<Self>
where Self: Sized,

Get a query builder for this model

Source

async fn all(pool: &Pool<Postgres>) -> ModelResult<Vec<Self>>
where Self: Sized,

Get all records for this model with proper SQL execution

Source

async fn count(pool: &Pool<Postgres>) -> ModelResult<i64>
where Self: Sized,

Count all records for this model with proper SQL execution

Source

async fn where_field<V>( pool: &Pool<Postgres>, field: &str, value: V, ) -> ModelResult<Vec<Self>>
where Self: Sized, for<'q> V: Send + Sync + 'static + Encode<'q, Postgres> + Type<Postgres>,

Find models by a specific field value with proper parameter binding

Source

async fn first_where<V>( pool: &Pool<Postgres>, field: &str, value: V, ) -> ModelResult<Option<Self>>
where Self: Sized, for<'q> V: Send + Sync + 'static + Encode<'q, Postgres> + Type<Postgres>,

Find the first model by a specific field value

Source

async fn first(pool: &Pool<Postgres>) -> ModelResult<Option<Self>>
where Self: Sized,

Get the first record from this model

Source

async fn last(pool: &Pool<Postgres>) -> ModelResult<Option<Self>>
where Self: Sized,

Get the last record from this model (ordered by primary key)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§