Skip to content

Escape column names that conflict with Rust keywords in CLI #82

Answered by billy1624
tqwewe asked this question in Q&A
Discussion options

You must be logged in to vote

I think we can leave it for the user to decide how to resolve the name conflict.

Personally think that neither r#type nor type_ be a good option. For me, I would simply choose another name to avoid conflicting with Rust keywords.

#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
pub struct Model {
    pub id: i32,
    pub type_of: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveCustomColumn)]
pub enum Column {
    Id,
    TypeOf,
}

impl IdenStatic for Column {
    fn as_str(&self) -> &str {
        match self {
            Self::TypeOf => "type",
            _ => self.default_as_str(),
        }
    }
}

Replies: 7 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jsalort
Comment options

Answer selected by tyt2y3
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@tyt2y3
Comment options

@baoyachi
Comment options

@Stumblinbear
Comment options

@DanielHZhang
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants
Converted from issue

This discussion was converted from issue #76 on August 13, 2021 13:30.