rquery_orm/
repository.rs

1use async_trait::async_trait;
2
3use crate::mapping::{Entity, FromRowNamed, Persistable, Validatable};
4use crate::query::{Query, SqlParam};
5
6#[allow(non_snake_case)]
7#[async_trait]
8pub trait QueryExecutor<T>
9where
10    T: Entity + FromRowNamed + Validatable + Persistable + Send + Sync,
11{
12    fn Select(&self) -> Query<T>;
13    async fn get_by_key_async(&self, key: SqlParam) -> anyhow::Result<Option<T>>;
14}
15
16#[async_trait]
17pub trait Crud<T>
18where
19    T: Entity + FromRowNamed + Validatable + Persistable + Send + Sync,
20{
21    async fn insert_async(&self, entity: &T) -> anyhow::Result<()>;
22    async fn update_async(&self, entity: &T) -> anyhow::Result<()>;
23    async fn delete_by_entity_async(&self, entity: &T) -> anyhow::Result<()>;
24    async fn delete_by_key_async(&self, key: SqlParam) -> anyhow::Result<()>;
25}
26
27pub trait Repository<T>: QueryExecutor<T> + Crud<T>
28where
29    T: Entity + FromRowNamed + Validatable + Persistable + Send + Sync,
30{
31}