pub trait Repository<T>where
T: Identifiable,{
// Required methods
fn find_by_id<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 <T as Identifiable>::Key,
) -> Pin<Box<dyn Future<Output = Result<Option<T>, RepoError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn find_by_field<'life0, 'life1, 'async_trait>(
&'life0 self,
field_name: &'life1 str,
value: ParamValue,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, RepoError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn insert<'life0, 'life1, 'async_trait>(
&'life0 self,
entity: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<T, RepoError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn update<'life0, 'life1, 'async_trait>(
&'life0 self,
entity: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<T, RepoError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn delete_by_id<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 <T as Identifiable>::Key,
) -> Pin<Box<dyn Future<Output = Result<bool, RepoError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
}Expand description
A trait describing a minimal, asynchronous repository interface for an entity T identified by key K.
This is intentionally DB-agnostic. Concrete backends provide implementations.
Required Methods§
Sourcefn find_by_id<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 <T as Identifiable>::Key,
) -> Pin<Box<dyn Future<Output = Result<Option<T>, RepoError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn find_by_id<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 <T as Identifiable>::Key,
) -> Pin<Box<dyn Future<Output = Result<Option<T>, RepoError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Fetch an entity by its primary key. Returns Ok(None) if not found.
Sourcefn find_by_field<'life0, 'life1, 'async_trait>(
&'life0 self,
field_name: &'life1 str,
value: ParamValue,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, RepoError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn find_by_field<'life0, 'life1, 'async_trait>(
&'life0 self,
field_name: &'life1 str,
value: ParamValue,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, RepoError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
A generic finder for a single field. Returns a (possibly empty) Vec of entities.
This is the low-level hook used by macro-generated find_by_<field> methods.
Sourcefn insert<'life0, 'life1, 'async_trait>(
&'life0 self,
entity: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<T, RepoError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn insert<'life0, 'life1, 'async_trait>(
&'life0 self,
entity: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<T, RepoError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Insert a new entity. The returned entity may be different if the database generates some fields (e.g., auto-incrementing IDs).
Sourcefn update<'life0, 'life1, 'async_trait>(
&'life0 self,
entity: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<T, RepoError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn update<'life0, 'life1, 'async_trait>(
&'life0 self,
entity: &'life1 T,
) -> Pin<Box<dyn Future<Output = Result<T, RepoError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Update an existing entity. The returned entity may be different if the
database modifies it (e.g., ON UPDATE timestamps).
Sourcefn delete_by_id<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 <T as Identifiable>::Key,
) -> Pin<Box<dyn Future<Output = Result<bool, RepoError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn delete_by_id<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 <T as Identifiable>::Key,
) -> Pin<Box<dyn Future<Output = Result<bool, RepoError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Delete an entity by key. Returns true if a row was affected.