diff --git a/src/executor/paginator.rs b/src/executor/paginator.rs index 727f9076..0775848a 100644 --- a/src/executor/paginator.rs +++ b/src/executor/paginator.rs @@ -155,22 +155,31 @@ where } } +#[async_trait::async_trait] /// Used to enforce constraints on any type that wants to paginate results pub trait PaginatorTrait<'db, C> where C: ConnectionTrait<'db>, { /// Select operation - type Selector: SelectorTrait + 'db; + type Selector: SelectorTrait + Send + Sync + 'db; /// Paginate the result of a select operation. fn paginate(self, db: &'db C, page_size: usize) -> Paginator<'db, C, Self::Selector>; + + /// Perform a count on the paginated results + async fn count(self, db: &'db C) -> Result + where + Self: Send + Sized + { + self.paginate(db, 1).num_items().await + } } impl<'db, C, S> PaginatorTrait<'db, C> for Selector where C: ConnectionTrait<'db>, - S: SelectorTrait + 'db, + S: SelectorTrait + Send + Sync + 'db, { type Selector = S; @@ -189,7 +198,7 @@ impl<'db, C, M, E> PaginatorTrait<'db, C> for Select where C: ConnectionTrait<'db>, E: EntityTrait, - M: FromQueryResult + Sized + 'db, + M: FromQueryResult + Sized + Send + Sync + 'db, { type Selector = SelectModel; @@ -203,8 +212,8 @@ where C: ConnectionTrait<'db>, E: EntityTrait, F: EntityTrait, - M: FromQueryResult + Sized + 'db, - N: FromQueryResult + Sized + 'db, + M: FromQueryResult + Sized + Send + Sync + 'db, + N: FromQueryResult + Sized + Send + Sync + 'db, { type Selector = SelectTwoModel; @@ -213,27 +222,6 @@ where } } -/// Used to enforce constraints on any type that wants to count results using pagination. -#[async_trait::async_trait] -pub trait CountTrait<'db, C>: PaginatorTrait<'db, C> -where - C: ConnectionTrait<'db>, -{ - /// Perform a count on the paginated results - async fn count(self, db: &'db C) -> Result; -} - -#[async_trait::async_trait] -impl<'db, C, P, S> CountTrait<'db, C> for P -where - C: ConnectionTrait<'db>, - P: PaginatorTrait<'db, C, Selector = S> + Send, - S: SelectorTrait + Send + Sync + 'db -{ - async fn count(self, db:&'db C) -> Result { - self.paginate(db, 1).num_items().await - } -} #[cfg(test)] #[cfg(feature = "mock")] mod tests { diff --git a/tests/basic.rs b/tests/basic.rs index 74d6a3ba..18d80a6b 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -1,6 +1,6 @@ pub mod common; -pub use sea_orm::{entity::*, error::*, query::*, sea_query, tests_cfg::*, Database, DbConn, CountTrait}; +pub use sea_orm::{entity::*, error::*, query::*, sea_query, tests_cfg::*, Database, DbConn, PaginatorTrait}; // cargo test --features sqlx-sqlite,runtime-async-std-native-tls --test basic #[sea_orm_macros::test] diff --git a/tests/crud/updates.rs b/tests/crud/updates.rs index 04aea292..4a3a05a0 100644 --- a/tests/crud/updates.rs +++ b/tests/crud/updates.rs @@ -1,6 +1,6 @@ pub use super::*; use rust_decimal_macros::dec; -use sea_orm::{DbErr, CountTrait}; +use sea_orm::{DbErr, PaginatorTrait}; use uuid::Uuid; pub async fn test_update_cake(db: &DbConn) {