Skip to content

Commit

Permalink
Adding a way to configure the Table Iden when using enum def
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptiste LE MORLEC committed Mar 9, 2024
1 parent 604af6e commit 3acc554
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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());
}

0 comments on commit 3acc554

Please sign in to comment.