pub trait Repository<T, 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§
Sourcefn 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_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.
Sourcefn 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_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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".