rquery_orm/services/
examples.rs1use crate::mapping::{Entity, FromRowNamed, Persistable, Validatable};
2use crate::{col, val, Repository};
3
4pub struct GenericListService<R, T>
5where
6 R: Repository<T>,
7 T: Entity + FromRowNamed + Validatable + Persistable + Send + Sync,
8{
9 repo: R,
10 _t: std::marker::PhantomData<T>,
11}
12
13impl<R, T> GenericListService<R, T>
14where
15 R: Repository<T>,
16 T: Entity + FromRowNamed + Validatable + Persistable + Send + Sync,
17{
18 pub fn new(repo: R) -> Self {
19 Self {
20 repo,
21 _t: Default::default(),
22 }
23 }
24
25 pub async fn list_by_country(&self, country: &str) -> anyhow::Result<Vec<T>> {
26 let q = self
27 .repo
28 .Select()
29 .Where(col!("E.CountryId").eq(val!(country)));
30 q.to_list_async().await
31 }
32}