articles_rs/databases/
postgres_repository.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use async_trait::async_trait;
use std::collections::HashMap;
use uuid::Uuid;

#[async_trait]
pub trait PostgresRepository {
    type Error;
    type Item;

    async fn find_by_id(&self, id: Uuid) -> Result<Option<Self::Item>, Self::Error>;
    async fn find_by_name(&self, name: String) -> Result<Option<Self::Item>, Self::Error>;
    async fn list(
        &self,
        filters: Option<HashMap<String, String>>,
    ) -> Result<Vec<Self::Item>, Self::Error>;
    async fn create(&self, item: &Self::Item) -> Result<Uuid, Self::Error>;
    async fn delete(&self, id: Uuid) -> Result<(), Self::Error>;
    async fn delete_all(&self, filters: Option<HashMap<String, String>>)
        -> Result<(), Self::Error>;
    async fn update(&self, item: &Self::Item) -> Result<(), Self::Error>;
}