Skip to main content

sofie_db/
load.rs

1use sofie_core::{Error, Result};
2
3use crate::{Aggregate, Id, Query, Read, Source};
4
5pub trait Select: Source {
6    #[must_use]
7    fn query() -> Query<Self> {
8        Query::default()
9    }
10}
11
12impl<T: Source> Select for T {}
13
14pub trait Load: Aggregate {
15    fn find(read: &Read, id: Id<Self>) -> impl Future<Output = Result<Self>> + Send {
16        async move {
17            Self::query()
18                .where_(Self::ID.eq(id))
19                .first(read)
20                .await?
21                .ok_or(Error::NotFound)
22        }
23    }
24}
25
26impl<A: Aggregate> Load for A {}