From e852a09498e7a7ad8ad24af5688f1f77d148d05f Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Fri, 3 Sep 2021 16:51:22 +0800 Subject: [PATCH] cargo clippy --- .github/workflows/rust.yml | 2 +- sea-orm-codegen/src/entity/column.rs | 27 +++++------------------ sea-orm-codegen/src/entity/transformer.rs | 14 ++++++------ sea-orm-codegen/src/entity/writer.rs | 2 +- 4 files changed, 15 insertions(+), 30 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f2fc7579..b7f014e1 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -27,7 +27,7 @@ jobs: - uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} - args: --all-targets + args: --all-targets --all compile-sqlite: name: Compile SQLite diff --git a/sea-orm-codegen/src/entity/column.rs b/sea-orm-codegen/src/entity/column.rs index a2c3b4f5..0b9eb8de 100644 --- a/sea-orm-codegen/src/entity/column.rs +++ b/sea-orm-codegen/src/entity/column.rs @@ -119,33 +119,18 @@ impl From<&ColumnDef> for Column { Some(ty) => ty.clone(), None => panic!("ColumnType should not be empty"), }; - let auto_increments: Vec = col_def + let auto_increment = col_def .get_column_spec() .iter() - .filter_map(|spec| match spec { - ColumnSpec::AutoIncrement => Some(true), - _ => None, - }) - .collect(); - let auto_increment = !auto_increments.is_empty(); - let not_nulls: Vec = col_def + .any(|spec| matches!(spec, ColumnSpec::AutoIncrement)); + let not_null = col_def .get_column_spec() .iter() - .filter_map(|spec| match spec { - ColumnSpec::NotNull => Some(true), - _ => None, - }) - .collect(); - let not_null = !not_nulls.is_empty(); - let uniques: Vec = col_def + .any(|spec| matches!(spec, ColumnSpec::NotNull)); + let unique = col_def .get_column_spec() .iter() - .filter_map(|spec| match spec { - ColumnSpec::UniqueKey => Some(true), - _ => None, - }) - .collect(); - let unique = !uniques.is_empty(); + .any(|spec| matches!(spec, ColumnSpec::UniqueKey)); Self { name, col_type, diff --git a/sea-orm-codegen/src/entity/transformer.rs b/sea-orm-codegen/src/entity/transformer.rs index 75dc25c7..840eade0 100644 --- a/sea-orm-codegen/src/entity/transformer.rs +++ b/sea-orm-codegen/src/entity/transformer.rs @@ -34,11 +34,6 @@ impl EntityTransformer { .iter() .map(|col_def| col_def.into()) .collect(); - let unique_columns: Vec = columns - .iter() - .filter(|col| col.unique) - .map(|col| col.name.clone()) - .collect(); let relations = table_create .get_foreign_key_create_stmts() .iter() @@ -85,8 +80,13 @@ impl EntityTransformer { false => { let ref_table = rel.ref_table; let mut unique = true; - for col in rel.columns.iter() { - if !unique_columns.contains(col) { + for column in rel.columns.iter() { + if !entity + .columns + .iter() + .filter(|col| col.unique) + .any(|col| col.name.as_str() == column) + { unique = false; break; } diff --git a/sea-orm-codegen/src/entity/writer.rs b/sea-orm-codegen/src/entity/writer.rs index 7accac2d..19e9af1c 100644 --- a/sea-orm-codegen/src/entity/writer.rs +++ b/sea-orm-codegen/src/entity/writer.rs @@ -308,7 +308,7 @@ mod tests { use sea_query::ColumnType; use std::io::{self, BufRead, BufReader}; - const ENTITY_FILES: [&'static str; 5] = [ + const ENTITY_FILES: [&str; 5] = [ include_str!("../../tests/entity/cake.rs"), include_str!("../../tests/entity/cake_filling.rs"), include_str!("../../tests/entity/filling.rs"),