Merge pull request #193 from SeaQL/codegen-col-unique-keys
Codegen parse column unique key from index
This commit is contained in:
commit
be01782ac7
@ -15,7 +15,7 @@ name = "sea_orm_codegen"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
sea-query = { version = "^0.16.2" }
|
||||
sea-query = { version = "^0.16.4" }
|
||||
syn = { version = "^1", default-features = false, features = [
|
||||
"derive",
|
||||
"parsing",
|
||||
|
@ -33,6 +33,17 @@ impl EntityTransformer {
|
||||
.get_columns()
|
||||
.iter()
|
||||
.map(|col_def| col_def.into())
|
||||
.map(|mut col: Column| {
|
||||
col.unique = table_create
|
||||
.get_indexes()
|
||||
.iter()
|
||||
.filter(|index| index.is_unique_key())
|
||||
.map(|index| index.get_index_spec().get_column_names())
|
||||
.filter(|col_names| col_names.len() == 1 && col_names[0] == col.name)
|
||||
.count()
|
||||
> 0;
|
||||
col
|
||||
})
|
||||
.collect();
|
||||
let relations = table_create
|
||||
.get_foreign_key_create_stmts()
|
||||
|
@ -346,6 +346,9 @@ impl EntityWriter {
|
||||
attrs.push(quote! { nullable });
|
||||
}
|
||||
};
|
||||
if col.unique {
|
||||
attrs.push(quote! { unique });
|
||||
}
|
||||
if !attrs.is_empty() {
|
||||
let mut ts = TokenStream::new();
|
||||
for (i, attr) in attrs.into_iter().enumerate() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user