pub trait PgRepository<T: PgEntity>: Send + Sync {
// Required methods
fn create<'life0, 'async_trait>(
&'life0 self,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<T, PgError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn upsert<'life0, 'async_trait>(
&'life0 self,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<T, PgError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn update<'life0, 'async_trait>(
&'life0 self,
entity: T,
) -> Pin<Box<dyn Future<Output = Result<T, PgError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn find_by_id<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 T::Id,
) -> Pin<Box<dyn Future<Output = Result<Option<T>, PgError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn find_by_ids<'life0, 'life1, 'async_trait>(
&'life0 self,
ids: &'life1 [T::Id],
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, PgError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn find_page<'life0, 'async_trait>(
&'life0 self,
limit: i64,
offset: i64,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, PgError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 T::Id,
) -> Pin<Box<dyn Future<Output = Result<bool, PgError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn count<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<i64, PgError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 T::Id,
) -> Pin<Box<dyn Future<Output = Result<bool, PgError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn delete_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
ids: &'life1 [T::Id],
) -> Pin<Box<dyn Future<Output = Result<u64, PgError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn create_batch<'life0, 'async_trait>(
&'life0 self,
entities: Vec<T>,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, PgError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn upsert_batch<'life0, 'async_trait>(
&'life0 self,
entities: Vec<T>,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, PgError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Repository trait providing CRUD operations for entities on PgClient.
This trait is implemented for PgClient automatically when using #[derive(PgEntity)].
Each entity type gets its own implementation, allowing a single PgClient to work
with multiple entity types.
§Example
ⓘ
use gearbox_rs_postgres::{PgClient, PgRepository};
let client: Arc<PgClient> = hub.get()?;
// Create
let user = client.create(user).await?;
// Read
let found = client.find_by_id::<User>(&id).await?;
// Update
let updated = client.update(user).await?;
// Delete
client.delete::<User>(&id).await?;