Repository

Trait Repository 

Source
pub trait Repository<T: Model> {
    type Error;

    // Required methods
    fn save(&self, model: &T) -> Result<T, Self::Error>;
    fn find_by_id(&self, id: &T::PrimaryKey) -> Result<Option<T>, Self::Error>;
    fn find_all(&self) -> Result<Vec<T>, Self::Error>;
    fn delete(&self, id: &T::PrimaryKey) -> Result<bool, Self::Error>;
    fn exists(&self, id: &T::PrimaryKey) -> Result<bool, Self::Error>;
}
Expand description

Repository trait providing high-level database operations for models

Required Associated Types§

Required Methods§

Source

fn save(&self, model: &T) -> Result<T, Self::Error>

Insert or update a model instance

Source

fn find_by_id(&self, id: &T::PrimaryKey) -> Result<Option<T>, Self::Error>

Get a model by its primary key

Source

fn find_all(&self) -> Result<Vec<T>, Self::Error>

Get all models

Source

fn delete(&self, id: &T::PrimaryKey) -> Result<bool, Self::Error>

Delete a model by its primary key

Source

fn exists(&self, id: &T::PrimaryKey) -> Result<bool, Self::Error>

Check if a model exists by its primary key

Implementors§