Use DeriveIden to replace ToString

This commit is contained in:
Chris Tsang 2021-09-30 22:05:23 +08:00
parent 5728ac4329
commit fcd969e57c
3 changed files with 12 additions and 29 deletions

View File

@ -320,24 +320,14 @@ pub trait TryGetableMany: Sized {
/// # ]])
/// # .into_connection();
/// #
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, EnumIter, TryGetableMany};
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, EnumIter, DeriveIden, TryGetableMany};
///
/// #[derive(EnumIter)]
/// #[derive(EnumIter, DeriveIden)]
/// enum ResultCol {
/// Name,
/// NumOfCakes,
/// }
///
/// // this can be derived using derive_more crate
/// impl std::fmt::Display for ResultCol {
/// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
/// match self {
/// Self::Name => write!(f, "name"),
/// Self::NumOfCakes => write!(f, "num_of_cakes"),
/// }
/// }
/// }
///
/// # let _: Result<(), DbErr> = smol::block_on(async {
/// #
/// let res: Vec<(String, i32)> =
@ -371,7 +361,7 @@ pub trait TryGetableMany: Sized {
/// ```
fn find_by_statement<C>(stmt: Statement) -> SelectorRaw<SelectGetableValue<Self, C>>
where
C: sea_strum::IntoEnumIterator + ToString,
C: sea_strum::IntoEnumIterator + sea_query::Iden,
{
SelectorRaw::<SelectGetableValue<Self, C>>::with_columns(stmt)
}

View File

@ -34,7 +34,7 @@ pub trait SelectorTrait {
pub struct SelectGetableValue<T, C>
where
T: TryGetableMany,
C: sea_strum::IntoEnumIterator + ToString,
C: sea_strum::IntoEnumIterator + sea_query::Iden,
{
columns: PhantomData<C>,
model: PhantomData<T>,
@ -60,7 +60,7 @@ where
impl<T, C> SelectorTrait for SelectGetableValue<T, C>
where
T: TryGetableMany,
C: sea_strum::IntoEnumIterator + ToString,
C: sea_strum::IntoEnumIterator + sea_query::Iden,
{
type Item = T;
@ -143,22 +143,13 @@ where
/// # ]])
/// # .into_connection();
/// #
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, EnumIter, TryGetableMany};
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, EnumIter, DeriveIden, TryGetableMany};
///
/// #[derive(EnumIter)]
/// #[derive(EnumIter, DeriveIden)]
/// enum ResultCol {
/// Name,
/// }
///
/// // this can be derived using derive_more crate
/// impl std::fmt::Display for ResultCol {
/// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
/// match self {
/// Self::Name => write!(f, "name"),
/// }
/// }
/// }
///
/// # let _: Result<(), DbErr> = smol::block_on(async {
/// #
/// let res: Vec<String> = cake::Entity::find()
@ -188,7 +179,7 @@ where
pub fn into_values<T, C>(self) -> Selector<SelectGetableValue<T, C>>
where
T: TryGetableMany,
C: sea_strum::IntoEnumIterator + ToString,
C: sea_strum::IntoEnumIterator + sea_query::Iden,
{
Selector::<SelectGetableValue<T, C>>::with_columns(self.query)
}
@ -323,7 +314,7 @@ where
pub fn with_columns<T, C>(query: SelectStatement) -> Selector<SelectGetableValue<T, C>>
where
T: TryGetableMany,
C: sea_strum::IntoEnumIterator + ToString,
C: sea_strum::IntoEnumIterator + sea_query::Iden,
{
Selector {
query,
@ -386,7 +377,7 @@ where
pub fn with_columns<T, C>(stmt: Statement) -> SelectorRaw<SelectGetableValue<T, C>>
where
T: TryGetableMany,
C: sea_strum::IntoEnumIterator + ToString,
C: sea_strum::IntoEnumIterator + sea_query::Iden,
{
SelectorRaw {
stmt,

View File

@ -440,5 +440,7 @@ pub use sea_orm_macros::{
pub use sea_query;
pub use sea_query::Iden;
pub use sea_query::Iden as DeriveIden;
pub use sea_strum;
pub use sea_strum::EnumIter;