From 7c82670d12c19ef64029412904ee9d26c4983000 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Sat, 2 Oct 2021 00:02:17 +0800 Subject: [PATCH] Doc --- src/entity/column.rs | 28 ++++++++++++++++++++++++++++ src/query/helper.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/entity/column.rs b/src/entity/column.rs index 04cb835e..a27215e5 100644 --- a/src/entity/column.rs +++ b/src/entity/column.rs @@ -774,4 +774,32 @@ mod tests { assert_eq!(hello::Column::Two.to_string().as_str(), "two"); assert_eq!(hello::Column::Three3.to_string().as_str(), "THREE"); } + + #[test] + #[cfg(feature = "macros")] + fn column_name_enum_name_3() { + use sea_query::Iden; + + mod my_entity { + use crate as sea_orm; + use crate::entity::prelude::*; + + #[derive(Clone, Debug, PartialEq, DeriveEntityModel)] + #[sea_orm(table_name = "my_entity")] + pub struct Model { + #[sea_orm(primary_key, enum_name = "IdentityColumn", column_name = "id")] + pub id: i32, + #[sea_orm(column_name = "type")] + pub type_: String, + } + + #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] + pub enum Relation {} + + impl ActiveModelBehavior for ActiveModel {} + } + + assert_eq!(my_entity::Column::IdentityColumn.to_string().as_str(), "id"); + assert_eq!(my_entity::Column::Type.to_string().as_str(), "type"); + } } diff --git a/src/query/helper.rs b/src/query/helper.rs index 5b8053de..7efe0ca1 100644 --- a/src/query/helper.rs +++ b/src/query/helper.rs @@ -314,6 +314,32 @@ pub trait QueryFilter: Sized { /// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` LIKE '%cheese%'" /// ); /// ``` + /// + /// A slightly more complex example. + /// ``` + /// use sea_orm::{entity::*, query::*, tests_cfg::cake, sea_query::Expr, DbBackend}; + /// + /// assert_eq!( + /// cake::Entity::find() + /// .filter( + /// Condition::all() + /// .add( + /// Condition::all() + /// .not() + /// .add(Expr::val(1).eq(1)) + /// .add(Expr::val(2).eq(2)) + /// ) + /// .add( + /// Condition::any() + /// .add(Expr::val(3).eq(3)) + /// .add(Expr::val(4).eq(4)) + /// ) + /// ) + /// .build(DbBackend::Postgres) + /// .to_string(), + /// r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE (NOT (1 = 1 AND 2 = 2)) AND (3 = 3 OR 4 = 4)"# + /// ); + /// ``` fn filter(mut self, filter: F) -> Self where F: IntoCondition,