Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic CRUD pattern trait for DB services #10

Open
ipapandinas opened this issue Dec 11, 2023 · 0 comments
Open

Generic CRUD pattern trait for DB services #10

ipapandinas opened this issue Dec 11, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@ipapandinas
Copy link
Contributor

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>;
}
@ipapandinas ipapandinas added the enhancement New feature or request label Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant