Skip to content

Commit

Permalink
Rename Column Name And Enum Variant Renaming Macro Attributes SeaQL#2160
Browse files Browse the repository at this point in the history
  • Loading branch information
anshap1719 committed Apr 25, 2024
1 parent 52ebf65 commit 35bca74
Show file tree
Hide file tree
Showing 27 changed files with 103 additions and 147 deletions.
2 changes: 1 addition & 1 deletion issues/1599/entity/src/cake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*;
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(column_name = "name", enum_name = "Name")]
#[sea_orm(rename = "name", enum_name = "Name")]
pub name: String,
}

Expand Down
10 changes: 5 additions & 5 deletions issues/630/src/entity/underscores_workaround.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use serde::{Deserialize, Serialize};
pub struct Model {
#[sea_orm(primary_key)]
pub id: u32,
#[sea_orm(column_name = "a_b_c_d")]
#[sea_orm(rename = "a_b_c_d")]
pub a_b_c_d: i32,
#[sea_orm(column_name = "a_b_c_dd")]
#[sea_orm(rename = "a_b_c_dd")]
pub a_b_c_dd: i32,
#[sea_orm(column_name = "a_b_cc_d")]
#[sea_orm(rename = "a_b_cc_d")]
pub a_b_cc_d: i32,
#[sea_orm(column_name = "a_bb_c_d")]
#[sea_orm(rename = "a_bb_c_d")]
pub a_bb_c_d: i32,
#[sea_orm(column_name = "aa_b_c_d")]
#[sea_orm(rename = "aa_b_c_d")]
pub aa_b_c_d: i32,
}

Expand Down
2 changes: 1 addition & 1 deletion issues/693/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub mod model {
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "container")]
pub struct Model {
#[sea_orm(primary_key, column_name = "db_id")]
#[sea_orm(primary_key, rename = "db_id")]
pub rust_id: i32,
}

Expand Down
8 changes: 4 additions & 4 deletions sea-orm-codegen/src/entity/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,9 @@ impl EntityWriter {
let variant = col.get_name_camel_case();
let mut variant = quote! { #variant };
if !col.is_snake_case_name() {
let column_name = &col.name;
let rename = &col.name;
variant = quote! {
#[sea_orm(column_name = #column_name)]
#[sea_orm(rename = #rename)]
#variant
};
}
Expand Down Expand Up @@ -739,8 +739,8 @@ impl EntityWriter {
let mut attrs: Punctuated<_, Comma> = Punctuated::new();
let is_primary_key = primary_keys.contains(&col.name);
if !col.is_snake_case_name() {
let column_name = &col.name;
attrs.push(quote! { column_name = #column_name });
let rename = &col.name;
attrs.push(quote! { rename = #rename });
}
if is_primary_key {
attrs.push(quote! { primary_key });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*;
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub user_id: Option<i32> ,
pub user_id: Option<i32>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand All @@ -15,7 +15,7 @@ pub enum Relation {
from = "Column::UserId",
to = "super::users::Column::Id",
on_update = "NoAction",
on_delete = "NoAction",
on_delete = "NoAction"
)]
Users,
#[sea_orm(has_many = "super::users_saved_bills::Entity")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ pub enum Relation {
from = "Column::BillId",
to = "super::bills::Column::Id",
on_update = "Cascade",
on_delete = "Cascade",
on_delete = "Cascade"
)]
Bills,
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::UserId",
to = "super::users::Column::Id",
on_update = "Cascade",
on_delete = "Cascade",
on_delete = "Cascade"
)]
Users,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ pub enum Relation {
from = "Column::BillId",
to = "super::bills::Column::Id",
on_update = "Cascade",
on_delete = "Cascade",
on_delete = "Cascade"
)]
Bills,
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::UserId",
to = "super::users::Column::Id",
on_update = "Cascade",
on_delete = "Cascade",
on_delete = "Cascade"
)]
Users,
}
Expand Down
4 changes: 2 additions & 2 deletions sea-orm-codegen/src/tests_cfg/many_to_many/bills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*;
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub user_id: Option<i32> ,
pub user_id: Option<i32>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand All @@ -15,7 +15,7 @@ pub enum Relation {
from = "Column::UserId",
to = "super::users::Column::Id",
on_update = "NoAction",
on_delete = "NoAction",
on_delete = "NoAction"
)]
Users,
#[sea_orm(has_many = "super::users_votes::Entity")]
Expand Down
4 changes: 2 additions & 2 deletions sea-orm-codegen/src/tests_cfg/many_to_many/users_votes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ pub enum Relation {
from = "Column::BillId",
to = "super::bills::Column::Id",
on_update = "Cascade",
on_delete = "Cascade",
on_delete = "Cascade"
)]
Bills,
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::UserId",
to = "super::users::Column::Id",
on_update = "Cascade",
on_delete = "Cascade",
on_delete = "Cascade"
)]
Users,
}
Expand Down
4 changes: 2 additions & 2 deletions sea-orm-codegen/src/tests_cfg/many_to_many_multiple/bills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*;
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub user_id: Option<i32> ,
pub user_id: Option<i32>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand All @@ -15,7 +15,7 @@ pub enum Relation {
from = "Column::UserId",
to = "super::users::Column::Id",
on_update = "NoAction",
on_delete = "NoAction",
on_delete = "NoAction"
)]
Users,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub struct Model {
pub user_id: i32,
#[sea_orm(primary_key, auto_increment = false)]
pub bill_id: i32,
pub user_idd: Option<i32> ,
pub bill_idd: Option<i32> ,
pub user_idd: Option<i32>,
pub bill_idd: Option<i32>,
pub vote: bool,
}

Expand All @@ -17,25 +17,25 @@ pub enum Relation {
#[sea_orm(
belongs_to = "super::bills::Entity",
from = "Column::BillIdd",
to = "super::bills::Column::Id",
to = "super::bills::Column::Id"
)]
Bills2,
#[sea_orm(
belongs_to = "super::bills::Entity",
from = "Column::BillId",
to = "super::bills::Column::Id",
to = "super::bills::Column::Id"
)]
Bills1,
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::UserIdd",
to = "super::users::Column::Id",
to = "super::users::Column::Id"
)]
Users2,
#[sea_orm(
belongs_to = "super::users::Entity",
from = "Column::UserId",
to = "super::users::Column::Id",
to = "super::users::Column::Id"
)]
Users1,
}
Expand Down
8 changes: 2 additions & 6 deletions sea-orm-codegen/src/tests_cfg/self_referencing/bills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ use sea_orm::entity::prelude::*;
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub self_id: Option<i32> ,
pub self_id: Option<i32>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "Entity",
from = "Column::SelfId",
to = "Column::Id",
)]
#[sea_orm(belongs_to = "Entity", from = "Column::SelfId", to = "Column::Id")]
SelfRef,
}

Expand Down
16 changes: 4 additions & 12 deletions sea-orm-codegen/src/tests_cfg/self_referencing/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,15 @@ use sea_orm::entity::prelude::*;
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub self_id: Option<i32> ,
pub self_idd: Option<i32> ,
pub self_id: Option<i32>,
pub self_idd: Option<i32>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "Entity",
from = "Column::SelfId",
to = "Column::Id",
)]
#[sea_orm(belongs_to = "Entity", from = "Column::SelfId", to = "Column::Id")]
SelfRef2,
#[sea_orm(
belongs_to = "Entity",
from = "Column::SelfIdd",
to = "Column::Id",
)]
#[sea_orm(belongs_to = "Entity", from = "Column::SelfIdd", to = "Column::Id")]
SelfRef1,
}

Expand Down
8 changes: 4 additions & 4 deletions sea-orm-codegen/tests/compact/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ use sea_orm::entity::prelude::*;
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(column_name = "_name_")]
#[sea_orm(rename = "_name_")]
pub name: String,
#[sea_orm(column_name = "fruitId")]
pub fruit_id: Option<i32> ,
#[sea_orm(rename = "fruitId")]
pub fruit_id: Option<i32>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::fruit::Entity",
from = "Column::FruitId",
to = "super::fruit::Column::Id",
to = "super::fruit::Column::Id"
)]
Fruit,
}
Expand Down
8 changes: 4 additions & 4 deletions sea-orm-codegen/tests/compact_with_schema_name/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ use sea_orm::entity::prelude::*;
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(column_name = "_name_")]
#[sea_orm(rename = "_name_")]
pub name: String,
#[sea_orm(column_name = "fruitId")]
pub fruit_id: Option<i32> ,
#[sea_orm(rename = "fruitId")]
pub fruit_id: Option<i32>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::fruit::Entity",
from = "Column::FruitId",
to = "super::fruit::Column::Id",
to = "super::fruit::Column::Id"
)]
Fruit,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0

use sea_orm::entity::prelude:: * ;
use sea_orm::entity::prelude::*;
use serde::Serialize;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize)]
#[sea_orm(table_name = "cake")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(column_name = "_name", column_type = "Text", nullable)]
#[sea_orm(rename = "_name", column_type = "Text", nullable)]
#[serde(skip)]
pub name: Option<String> ,
pub name: Option<String>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
6 changes: 3 additions & 3 deletions sea-orm-codegen/tests/expanded/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ impl EntityName for Entity {
pub struct Model {
pub id: i32,
pub name: String,
pub fruit_id: Option<i32> ,
pub fruit_id: Option<i32>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
Id,
#[sea_orm(column_name = "_name_")]
#[sea_orm(rename = "_name_")]
Name,
#[sea_orm(column_name = "fruitId")]
#[sea_orm(rename = "fruitId")]
FruitId,
}

Expand Down
8 changes: 4 additions & 4 deletions sea-orm-codegen/tests/expanded_with_schema_name/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sea_orm::entity::prelude::*;
pub struct Entity;

impl EntityName for Entity {
fn schema_name(&self) -> Option< &str > {
fn schema_name(&self) -> Option<&str> {
Some("schema_name")
}

Expand All @@ -19,15 +19,15 @@ impl EntityName for Entity {
pub struct Model {
pub id: i32,
pub name: String,
pub fruit_id: Option<i32> ,
pub fruit_id: Option<i32>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
Id,
#[sea_orm(column_name = "_name_")]
#[sea_orm(rename = "_name_")]
Name,
#[sea_orm(column_name = "fruitId")]
#[sea_orm(rename = "fruitId")]
FruitId,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0

use sea_orm::entity::prelude:: * ;
use sea_orm::entity::prelude::*;
use serde::Serialize;

#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
Expand All @@ -16,13 +16,13 @@ impl EntityName for Entity {
pub struct Model {
pub id: i32,
#[serde(skip)]
pub name: Option<String> ,
pub name: Option<String>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
Id,
#[sea_orm(column_name = "_name")]
#[sea_orm(rename = "_name")]
Name,
}

Expand Down

0 comments on commit 35bca74

Please sign in to comment.