Implement LoaderTrait for slices (#1368)
This commit is contained in:
parent
2a713b06cd
commit
a0d972633a
@ -32,8 +32,35 @@ pub trait LoaderTrait {
|
||||
#[async_trait]
|
||||
impl<M> LoaderTrait for Vec<M>
|
||||
where
|
||||
M: ModelTrait,
|
||||
Vec<M>: Sync,
|
||||
M: ModelTrait + Sync,
|
||||
{
|
||||
type Model = M;
|
||||
|
||||
async fn load_one<R, C>(&self, stmt: Select<R>, db: &C) -> Result<Vec<Option<R::Model>>, DbErr>
|
||||
where
|
||||
C: ConnectionTrait,
|
||||
R: EntityTrait,
|
||||
R::Model: Send + Sync,
|
||||
<<Self as LoaderTrait>::Model as ModelTrait>::Entity: Related<R>,
|
||||
{
|
||||
self.as_slice().load_one(stmt, db).await
|
||||
}
|
||||
|
||||
async fn load_many<R, C>(&self, stmt: Select<R>, db: &C) -> Result<Vec<Vec<R::Model>>, DbErr>
|
||||
where
|
||||
C: ConnectionTrait,
|
||||
R: EntityTrait,
|
||||
R::Model: Send + Sync,
|
||||
<<Self as LoaderTrait>::Model as ModelTrait>::Entity: Related<R>,
|
||||
{
|
||||
self.as_slice().load_many(stmt, db).await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<M> LoaderTrait for &[M]
|
||||
where
|
||||
M: ModelTrait + Sync,
|
||||
{
|
||||
type Model = M;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user