Skip to main content

Repository

Trait Repository 

Source
pub trait Repository<T, ID>: Send + Sync
where T: Send + Sync, ID: Send + Sync,
{ // Required methods fn find_by_id<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ID, ) -> Pin<Box<dyn Future<Output = AppResult<Option<T>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn find_all<'life0, 'async_trait>( &'life0 self, opts: FindOpts, ) -> Pin<Box<dyn Future<Output = AppResult<Vec<T>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn find_first<'life0, 'async_trait>( &'life0 self, opts: FindOpts, ) -> Pin<Box<dyn Future<Output = AppResult<Option<T>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn count<'life0, 'async_trait>( &'life0 self, opts: FindOpts, ) -> Pin<Box<dyn Future<Output = AppResult<i64>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn exists<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ID, ) -> Pin<Box<dyn Future<Output = AppResult<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn create<'life0, 'life1, 'async_trait>( &'life0 self, entity: &'life1 T, ) -> Pin<Box<dyn Future<Output = AppResult<T>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn update<'life0, 'life1, 'async_trait>( &'life0 self, entity: &'life1 T, ) -> Pin<Box<dyn Future<Output = AppResult<T>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn delete<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ID, ) -> Pin<Box<dyn Future<Output = AppResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn upsert<'life0, 'life1, 'async_trait>( &'life0 self, entity: &'life1 T, ) -> Pin<Box<dyn Future<Output = AppResult<T>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; }
Expand description

Generic repository interface for CRUD operations.

Implement this trait for each entity type. Backend-specific repository helpers belong in adapter crates so the core contract remains vendor-neutral.

Required Methods§

Source

fn find_by_id<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ID, ) -> Pin<Box<dyn Future<Output = AppResult<Option<T>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Find a single entity by its primary key.

Source

fn find_all<'life0, 'async_trait>( &'life0 self, opts: FindOpts, ) -> Pin<Box<dyn Future<Output = AppResult<Vec<T>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Find all entities matching the given options.

Source

fn find_first<'life0, 'async_trait>( &'life0 self, opts: FindOpts, ) -> Pin<Box<dyn Future<Output = AppResult<Option<T>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Find the first entity matching the given options.

Source

fn count<'life0, 'async_trait>( &'life0 self, opts: FindOpts, ) -> Pin<Box<dyn Future<Output = AppResult<i64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Count entities matching the given options.

Source

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

Check whether an entity with the given ID exists.

Source

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

Insert a new entity and return the persisted version.

Source

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

Update an existing entity and return the updated version.

Source

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

Delete the entity with the given primary key.

Source

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

Insert or update (upsert) an entity and return the result.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§