ModelRepository

Trait ModelRepository 

Source
pub trait ModelRepository: Send + Sync {
    // Required methods
    fn list<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Model>, RepositoryError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_by_id<'life0, 'async_trait>(
        &'life0 self,
        id: i64,
    ) -> Pin<Box<dyn Future<Output = Result<Model, RepositoryError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_by_name<'life0, 'life1, 'async_trait>(
        &'life0 self,
        name: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Model, RepositoryError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn insert<'life0, 'life1, 'async_trait>(
        &'life0 self,
        model: &'life1 NewModel,
    ) -> Pin<Box<dyn Future<Output = Result<Model, RepositoryError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn update<'life0, 'life1, 'async_trait>(
        &'life0 self,
        model: &'life1 Model,
    ) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn delete<'life0, 'async_trait>(
        &'life0 self,
        id: i64,
    ) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Repository for model persistence operations.

This trait defines CRUD operations for models. Implementations are responsible for all storage details (SQL, filesystem, etc.).

§Design Rules

  • No sqlx types in signatures
  • CRUD-only: list, get, insert, update, delete
  • Tags and search logic belong in ModelService, not here

Required Methods§

Source

fn list<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Model>, RepositoryError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List all models in the repository.

Source

fn get_by_id<'life0, 'async_trait>( &'life0 self, id: i64, ) -> Pin<Box<dyn Future<Output = Result<Model, RepositoryError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get a model by its database ID.

Returns Err(RepositoryError::NotFound) if the model doesn’t exist.

Source

fn get_by_name<'life0, 'life1, 'async_trait>( &'life0 self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Model, RepositoryError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a model by its name.

Returns Err(RepositoryError::NotFound) if no model with that name exists.

Source

fn insert<'life0, 'life1, 'async_trait>( &'life0 self, model: &'life1 NewModel, ) -> Pin<Box<dyn Future<Output = Result<Model, RepositoryError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Insert a new model into the repository.

Returns the persisted model with its assigned ID. Returns Err(RepositoryError::AlreadyExists) if a model with the same file path already exists.

Source

fn update<'life0, 'life1, 'async_trait>( &'life0 self, model: &'life1 Model, ) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Update an existing model.

Returns Err(RepositoryError::NotFound) if the model doesn’t exist.

Source

fn delete<'life0, 'async_trait>( &'life0 self, id: i64, ) -> Pin<Box<dyn Future<Output = Result<(), RepositoryError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Delete a model by its database ID.

Returns Err(RepositoryError::NotFound) if the model doesn’t exist.

Implementors§