Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to configure the Table enum variant Iden implementation with enum_def macro #759

Merged
merged 2 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion sea-query-attr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ struct GenEnumArgs {
pub suffix: Option<String>,
#[darling(default)]
pub crate_name: Option<String>,
#[darling(default)]
pub table_iden: Option<String>,
}

const DEFAULT_PREFIX: &str = "";
Expand All @@ -31,6 +33,7 @@ impl Default for GenEnumArgs {
prefix: Some(DEFAULT_PREFIX.to_string()),
suffix: Some(DEFAULT_SUFFIX.to_string()),
crate_name: Some(DEFAULT_CRATE_NAME.to_string()),
table_iden: None,
}
}
}
Expand Down Expand Up @@ -66,7 +69,9 @@ pub fn enum_def(args: TokenStream, input: TokenStream) -> TokenStream {
.collect();

let table_name = Ident::new(
input.ident.to_string().to_snake_case().as_str(),
args.table_iden
.unwrap_or_else(|| input.ident.to_string().to_snake_case())
.as_str(),
input.ident.span(),
);

Expand Down
11 changes: 11 additions & 0 deletions sea-query-attr/tests/pass/table_iden.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use sea_query::Iden;
use sea_query_attr::enum_def;

#[enum_def(table_iden = "HelloTable")]
pub struct Hello {
pub name: String,
}

fn main() {
println!("{:?}", HelloIden::Table.to_string());
Gaelik-git marked this conversation as resolved.
Show resolved Hide resolved
}
Loading