diff --git a/src/lib.rs b/src/lib.rs index b0f1ee2..bf940e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,8 +3,10 @@ pub use model::historic::Historic; pub use model::reference::*; pub use model::valid::Validate; pub use model::Model; +pub use model::Sort; pub use mongod_derive as derive; pub use mongodb; + #[cfg(feature = "cache")] pub mod cache; #[cfg(feature = "cache")] diff --git a/src/model/mod.rs b/src/model/mod.rs index 7279058..e0b850e 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -354,11 +354,19 @@ pub trait Model: /// "sort_key": Sort::Ascending /// })).await.unwrap(); /// ``` -#[repr(i8)] -#[derive(serde::Serialize, serde::Deserialize, Debug)] +#[derive(Debug)] pub enum Sort { /// Sort in ascending order - Ascending = 1, + Ascending, /// Sort in descending order - Descending = -1, + Descending, +} + +impl Into for Sort { + fn into(self) -> mongodb::bson::Bson { + match self { + Sort::Ascending => mongodb::bson::bson!(1), + Sort::Descending => mongodb::bson::bson!(-1), + } + } }