Skip to content

Commit

Permalink
Remove sea-query's Iden macro
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Jul 13, 2023
1 parent 866025a commit 578191a
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 60 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,34 @@ impl ColumnTrait for Column {
* Replace the use of `SeaRc<T>` where `T` isn't `dyn Iden` with `RcOrArc<T>` https://github.com/SeaQL/sea-orm/pull/1661
* Enabled `hashable-value` feature in SeaQuery, thus `Value::Float(NaN) == Value::Float(NaN)` would be true https://github.com/SeaQL/sea-orm/pull/1728, https://github.com/SeaQL/sea-orm/pull/1743
* The `DeriveActiveEnum` derive macro no longer provide `std::fmt::Display` implementation for the enum. You need to derive an extra `DeriveDisplay` macro alongside with `DeriveActiveEnum` derive macro. https://github.com/SeaQL/sea-orm/pull/1726
* `sea-query/derive` is no longer enabled by `sea-orm`, as such, `Iden` no longer works as a derive macro (it's still a trait). Instead, we are shipping a new macro `DeriveIden`:
```rust
// then:

#[derive(Iden)]
#[iden = "category"]
pub struct CategoryEnum;

#[derive(Iden)]
pub enum Tea {
Table,
#[iden = "EverydayTea"]
EverydayTea,
}

// now:

#[derive(DeriveIden)]
#[sea_orm(iden = "category")]
pub struct CategoryEnum;

#[derive(DeriveIden)]
pub enum Tea {
Table,
#[sea_orm(iden = "EverydayTea")]
EverydayTea,
}
```

## 0.11.3 - 2023-04-24

Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ tracing = { version = "0.1", default-features = false, features = ["attributes",
rust_decimal = { version = "1", default-features = false, optional = true }
bigdecimal = { version = "0.3", default-features = false, optional = true }
sea-orm-macros = { version = "0.12.0-rc.4", path = "sea-orm-macros", default-features = false, features = ["strum"] }
sea-query = { version = "0.29.0", features = ["thread-safe", "hashable-value"] }
sea-query = { version = "0.29.0", default-features = false, features = ["thread-safe", "hashable-value", "backend-mysql", "backend-postgres", "backend-sqlite"] }
sea-query-binder = { version = "0.4.0-rc.2", default-features = false, optional = true }
strum = { version = "0.25", default-features = false }
serde = { version = "1.0", default-features = false }
Expand Down Expand Up @@ -74,7 +74,7 @@ default = [
"with-uuid",
"with-time",
]
macros = ["sea-orm-macros/derive", "sea-query/derive"]
macros = ["sea-orm-macros/derive"]
mock = []
with-json = ["serde_json", "sea-query/with-json", "chrono?/serde", "time?/serde", "uuid?/serde", "sea-query-binder?/with-json", "sqlx?/json"]
with-chrono = ["chrono", "sea-query/with-chrono", "sea-query-binder?/with-chrono", "sqlx?/chrono"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
enum Posts {
Table,
Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
enum Posts {
Table,
Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
enum Posts {
Table,
Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
enum Notes {
Table,
Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
enum Posts {
Table,
Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
enum Posts {
Table,
Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
enum Posts {
Table,
Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
enum Posts {
Table,
Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
enum Posts {
Table,
Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
enum Posts {
Table,
Id,
Expand Down
2 changes: 1 addition & 1 deletion issues/1473/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ publish = false
[dependencies.sea-orm]
path = "../../"
default-features = false
features = ["macros", "runtime-tokio-native-tls"]
features = ["macros", "runtime-tokio-native-tls"]
7 changes: 3 additions & 4 deletions issues/1473/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use sea_orm::{sea_query::{self, Iden}};
use sea_orm::{DeriveIden, Iden};

#[derive(Iden)]
#[derive(DeriveIden)]
enum Character {
Table,
Id,
}

#[derive(Iden)]
#[derive(DeriveIden)]
struct Glyph;

fn main() {
assert_eq!(Character::Table.to_string(), "character");
assert_eq!(Character::Id.to_string(), "id");

assert_eq!(Glyph.to_string(), "glyph");
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
enum Post {
Table,
Id,
Expand Down
19 changes: 10 additions & 9 deletions sea-orm-migration/src/migrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ use std::time::SystemTime;
use tracing::info;

use sea_orm::sea_query::{
self, extension::postgres::Type, Alias, Expr, ForeignKey, Iden, IntoIden, JoinType, Order,
self, extension::postgres::Type, Alias, Expr, ForeignKey, IntoIden, JoinType, Order,
Query, SelectStatement, SimpleExpr, Table,
};
use sea_orm::{
ActiveModelTrait, ActiveValue, Condition, ConnectionTrait, DbBackend, DbErr, DynIden,
EntityTrait, FromQueryResult, Iterable, QueryFilter, Schema, Statement, TransactionTrait,
ActiveModelTrait, ActiveValue, Condition, ConnectionTrait, DbBackend, DbErr, DeriveIden,
DynIden, EntityTrait, FromQueryResult, Iterable, QueryFilter, Schema, Statement,
TransactionTrait,
};
use sea_schema::{mysql::MySql, postgres::Postgres, probe::SchemaProbe, sqlite::Sqlite};

Expand Down Expand Up @@ -457,13 +458,13 @@ where
}
}

#[derive(Iden)]
#[derive(DeriveIden)]
enum InformationSchema {
#[iden = "information_schema"]
#[sea_orm(iden = "information_schema")]
Schema,
#[iden = "TABLE_NAME"]
#[sea_orm(iden = "TABLE_NAME")]
TableName,
#[iden = "CONSTRAINT_NAME"]
#[sea_orm(iden = "CONSTRAINT_NAME")]
ConstraintName,
TableConstraints,
TableSchema,
Expand Down Expand Up @@ -500,15 +501,15 @@ where
stmt
}

#[derive(Iden)]
#[derive(DeriveIden)]
enum PgType {
Table,
Typname,
Typnamespace,
Typelem,
}

#[derive(Iden)]
#[derive(DeriveIden)]
enum PgNamespace {
Table,
Oid,
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-migration/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ pub use async_trait;
pub use sea_orm::{
self,
sea_query::{self, *},
ConnectionTrait, DbErr, DeriveMigrationName,
ConnectionTrait, DbErr, DeriveIden, DeriveMigrationName,
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
pub enum Cake {
Table,
Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
pub enum Fruit {
Table,
Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
pub enum Tea {
Table,
#[iden = "EverydayTea"]
#[sea_orm(iden = "EverydayTea")]
EverydayTea,
#[iden = "BreakfastTea"]
#[sea_orm(iden = "BreakfastTea")]
BreakfastTea,
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ impl MigrationTrait for Migration {
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
#[derive(DeriveIden)]
pub enum Cake {
Table,
Name,
Expand Down
6 changes: 3 additions & 3 deletions src/entity/active_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use sea_query::{DynIden, Expr, Nullable, SimpleExpr, Value, ValueType};
/// Small,
/// }
///
/// #[derive(Debug, Iden)]
/// #[derive(Debug, DeriveIden)]
/// pub struct CategoryEnum;
///
/// impl ActiveEnum for Category {
Expand Down Expand Up @@ -182,8 +182,8 @@ mod tests {
Small,
}

#[derive(Debug, Iden)]
#[iden = "category"]
#[derive(Debug, DeriveIden)]
#[sea_orm(iden = "category")]
pub struct CategoryEnum;

impl ActiveEnum for Category {
Expand Down
20 changes: 14 additions & 6 deletions src/entity/column.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{self as sea_orm, EntityName, IdenStatic, IntoSimpleExpr, Iterable};
use crate::{EntityName, Iden, IdenStatic, IntoSimpleExpr, Iterable};
use sea_query::{
Alias, BinOper, DynIden, Expr, Iden, IntoIden, SeaRc, SelectStatement, SimpleExpr, Value,
Alias, BinOper, DynIden, Expr, IntoIden, SeaRc, SelectStatement, SimpleExpr, Value,
};
use std::str::FromStr;

Expand Down Expand Up @@ -381,13 +381,21 @@ impl ColumnDef {
}
}

#[derive(Iden)]
struct Text;

#[derive(Iden)]
#[iden = "text[]"]
struct TextArray;

impl Iden for Text {
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
write!(s, "text").unwrap();
}
}

impl Iden for TextArray {
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
write!(s, "text[]").unwrap();
}
}

fn cast_enum_as<C, F>(expr: Expr, col: &C, f: F) -> SimpleExpr
where
C: ColumnTrait,
Expand Down
5 changes: 3 additions & 2 deletions src/entity/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ pub use crate::{
#[cfg(feature = "macros")]
pub use crate::{
DeriveActiveEnum, DeriveActiveModel, DeriveActiveModelBehavior, DeriveColumn,
DeriveCustomColumn, DeriveDisplay, DeriveEntity, DeriveEntityModel, DeriveIntoActiveModel,
DeriveModel, DerivePrimaryKey, DeriveRelatedEntity, DeriveRelation, FromJsonQueryResult,
DeriveCustomColumn, DeriveDisplay, DeriveEntity, DeriveEntityModel, DeriveIden,
DeriveIntoActiveModel, DeriveModel, DerivePrimaryKey, DeriveRelatedEntity, DeriveRelation,
FromJsonQueryResult,
};

pub use async_trait;
Expand Down

0 comments on commit 578191a

Please sign in to comment.