use async_trait::async_trait;
use crate::WithId;
#[async_trait]
pub trait Create<E> {
async fn create(&self, entity: E) -> sqlx::Result<WithId<E>>;
}
#[async_trait]
pub trait Read<E> {
async fn read(&self, id: i64) -> sqlx::Result<WithId<E>>;
async fn list(&self) -> sqlx::Result<Vec<WithId<E>>>;
async fn count(&self) -> sqlx::Result<u64>;
}
#[async_trait]
pub trait Update<E> {
async fn update(&self, entity: WithId<E>) -> sqlx::Result<WithId<E>>;
}
#[async_trait]
pub trait Delete<E> {
async fn delete(&self, id: i64) -> sqlx::Result<()>;
async fn delete_all(&self) -> sqlx::Result<u64>;
}
#[async_trait]
pub trait Crud<E>: Create<E> + Read<E> + Update<E> + Delete<E> {}
impl<S, E> Crud<E> for S where S: Create<E> + Read<E> + Update<E> + Delete<E> {}