Skip to content

Generic CRUD pattern trait for DB services #10

Description

@ipapandinas

Instead of having multiple DB services traits for each route, we should implement a generic one following CRUD pattern. For example:

#[async_trait]
pub trait DBService<T, K>: Send + Sync + Clone + 'static 
where
    T: Send + Sync + 'static, 
    K: Send + Sync + 'static,
{
    async fn get_all(&self) -> Result<Vec<T>, reject::Rejection>;
    async fn get_by_id(&self, id: i64) -> Result<Option<T>, reject::Rejection>;
    async fn create(&self, item: K) -> Result<T, reject::Rejection>;
    async fn update(&self, id: i64, item: K) -> Result<T, reject::Rejection>;
    async fn remove(&self, id: i64) -> Result<(), reject::Rejection>;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions