Skip to content

Commit 3acc554

Browse files
author
Baptiste LE MORLEC
committed
Adding a way to configure the Table Iden when using enum def
1 parent 604af6e commit 3acc554

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

sea-query-attr/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ struct GenEnumArgs {
1919
pub suffix: Option<String>,
2020
#[darling(default)]
2121
pub crate_name: Option<String>,
22+
#[darling(default)]
23+
pub table_iden: Option<String>,
2224
}
2325

2426
const DEFAULT_PREFIX: &str = "";
@@ -31,6 +33,7 @@ impl Default for GenEnumArgs {
3133
prefix: Some(DEFAULT_PREFIX.to_string()),
3234
suffix: Some(DEFAULT_SUFFIX.to_string()),
3335
crate_name: Some(DEFAULT_CRATE_NAME.to_string()),
36+
table_iden: None,
3437
}
3538
}
3639
}
@@ -66,7 +69,9 @@ pub fn enum_def(args: TokenStream, input: TokenStream) -> TokenStream {
6669
.collect();
6770

6871
let table_name = Ident::new(
69-
input.ident.to_string().to_snake_case().as_str(),
72+
args.table_iden
73+
.unwrap_or_else(|| input.ident.to_string().to_snake_case())
74+
.as_str(),
7075
input.ident.span(),
7176
);
7277

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use sea_query::Iden;
2+
use sea_query_attr::enum_def;
3+
4+
#[enum_def(table_iden = "HelloTable")]
5+
pub struct Hello {
6+
pub name: String,
7+
}
8+
9+
fn main() {
10+
println!("{:?}", HelloIden::Table.to_string());
11+
}

0 commit comments

Comments
 (0)