Skip to main content

Repository

Trait Repository 

Source
pub trait Repository<T: Model, ID> {
    // Required methods
    async fn find_by_id(&self, id: ID) -> Result<Option<T>, DbError>;
    async fn find_all(&self) -> Result<Vec<T>, DbError>;
    async fn save(&self, entity: &T) -> Result<T, DbError>;
    async fn save_all(&self, entities: &[T]) -> Result<Vec<T>, DbError>;
    async fn delete_by_id(&self, id: ID) -> Result<(), DbError>;
    async fn delete_all_by_id(&self, ids: &[ID]) -> Result<(), DbError>;
    async fn count(&self) -> Result<i64, DbError>;
    async fn exists_by_id(&self, id: ID) -> Result<bool, DbError>;
}
Available on crate features model-mysql or model-postgres or model-sqlite only.
Expand description

Async CRUD operations for a model type.

Required Methods§

Source

async fn find_by_id(&self, id: ID) -> Result<Option<T>, DbError>

Source

async fn find_all(&self) -> Result<Vec<T>, DbError>

Source

async fn save(&self, entity: &T) -> Result<T, DbError>

Source

async fn save_all(&self, entities: &[T]) -> Result<Vec<T>, DbError>

Source

async fn delete_by_id(&self, id: ID) -> Result<(), DbError>

Source

async fn delete_all_by_id(&self, ids: &[ID]) -> Result<(), DbError>

Source

async fn count(&self) -> Result<i64, DbError>

Source

async fn exists_by_id(&self, id: ID) -> Result<bool, DbError>

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<'a, T: Model> Repository<T, i64> for ModelRepository<'a, T, i64>