Skip to main content

Repository

Trait Repository 

Source
pub trait Repository<Entity, Id> {
    // Required methods
    fn find_by_id<'life0, 'async_trait>(
        &'life0 self,
        id: Id,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Entity>, AppError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn find_all<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Entity>, AppError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn insert<'life0, 'async_trait>(
        &'life0 self,
        entity: Entity,
    ) -> Pin<Box<dyn Future<Output = Result<Entity, AppError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn update<'life0, 'async_trait>(
        &'life0 self,
        id: Id,
        entity: Entity,
    ) -> Pin<Box<dyn Future<Output = Result<Entity, AppError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn delete<'life0, 'async_trait>(
        &'life0 self,
        id: Id,
    ) -> Pin<Box<dyn Future<Output = Result<(), AppError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Core Repository Trait This is the equivalent of the base repository in TypeORM/NestJS. Implementations (like SeaORM or Mongo) will implement this trait for specific entities.

Required Methods§

Source

fn find_by_id<'life0, 'async_trait>( &'life0 self, id: Id, ) -> Pin<Box<dyn Future<Output = Result<Option<Entity>, AppError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Finds a single entity by its primary key

Source

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

Finds all entities

Source

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

Inserts a new entity

Source

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

Updates an existing entity

Source

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

Deletes an entity by its primary key

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§