Trait Repository

Source
pub trait Repository: Send + Sync {
    type Entity: Send + Sync + Debug;
    type Id: Send + Sync + Debug + Clone;

    // Required methods
    fn get<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 Self::Id,
    ) -> Pin<Box<dyn Future<Output = RepositoryResult<Self::Entity>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn list<'life0, 'async_trait>(
        &'life0 self,
        pagination: Option<PaginationParams>,
        filters: Option<FilterParams>,
    ) -> Pin<Box<dyn Future<Output = RepositoryResult<Vec<Self::Entity>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn create<'life0, 'life1, 'async_trait>(
        &'life0 self,
        entity: &'life1 Self::Entity,
    ) -> Pin<Box<dyn Future<Output = RepositoryResult<Self::Entity>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn update<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        id: &'life1 Self::Id,
        entity: &'life2 Self::Entity,
    ) -> Pin<Box<dyn Future<Output = RepositoryResult<Self::Entity>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 Self::Id,
    ) -> Pin<Box<dyn Future<Output = RepositoryResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn exists<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 Self::Id,
    ) -> Pin<Box<dyn Future<Output = RepositoryResult<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn count<'life0, 'async_trait>(
        &'life0 self,
        filters: Option<FilterParams>,
    ) -> Pin<Box<dyn Future<Output = RepositoryResult<u64>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Base repository trait

This trait defines common operations that all repositories should support.

Required Associated Types§

Source

type Entity: Send + Sync + Debug

The entity type this repository manages

Source

type Id: Send + Sync + Debug + Clone

The ID type for entities

Required Methods§

Source

fn get<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 Self::Id, ) -> Pin<Box<dyn Future<Output = RepositoryResult<Self::Entity>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get an entity by ID

Source

fn list<'life0, 'async_trait>( &'life0 self, pagination: Option<PaginationParams>, filters: Option<FilterParams>, ) -> Pin<Box<dyn Future<Output = RepositoryResult<Vec<Self::Entity>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List entities with optional pagination and filters

Source

fn create<'life0, 'life1, 'async_trait>( &'life0 self, entity: &'life1 Self::Entity, ) -> Pin<Box<dyn Future<Output = RepositoryResult<Self::Entity>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Create a new entity

Source

fn update<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 Self::Id, entity: &'life2 Self::Entity, ) -> Pin<Box<dyn Future<Output = RepositoryResult<Self::Entity>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Update an existing entity

Source

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

Delete an entity

Provided Methods§

Source

fn exists<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 Self::Id, ) -> Pin<Box<dyn Future<Output = RepositoryResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Check if an entity exists

Source

fn count<'life0, 'async_trait>( &'life0 self, filters: Option<FilterParams>, ) -> Pin<Box<dyn Future<Output = RepositoryResult<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Count entities matching filters

Implementors§