(table_create_stmts: Vec<TableCreateStatement>)
| 10 | |
| 11 | impl EntityTransformer { |
| 12 | pub fn transform(table_create_stmts: Vec<TableCreateStatement>) -> Result<EntityWriter, Error> { |
| 13 | let mut enums: BTreeMap<String, ActiveEnum> = BTreeMap::new(); |
| 14 | let mut inverse_relations: BTreeMap<String, Vec<Relation>> = BTreeMap::new(); |
| 15 | let mut entities = BTreeMap::new(); |
| 16 | for table_create in table_create_stmts.into_iter() { |
| 17 | let table_name = match table_create.get_table_name() { |
| 18 | Some(table_ref) => match table_ref { |
| 19 | sea_query::TableRef::Table(t) |
| 20 | | sea_query::TableRef::SchemaTable(_, t) |
| 21 | | sea_query::TableRef::DatabaseSchemaTable(_, _, t) |
| 22 | | sea_query::TableRef::TableAlias(t, _) |
| 23 | | sea_query::TableRef::SchemaTableAlias(_, t, _) |
| 24 | | sea_query::TableRef::DatabaseSchemaTableAlias(_, _, t, _) => t.to_string(), |
| 25 | _ => unimplemented!(), |
| 26 | }, |
| 27 | None => { |
| 28 | return Err(Error::TransformError( |
| 29 | "Table name should not be empty".into(), |
| 30 | )) |
| 31 | } |
| 32 | }; |
| 33 | let mut primary_keys: Vec<PrimaryKey> = Vec::new(); |
| 34 | let columns: Vec<Column> = table_create |
| 35 | .get_columns() |
| 36 | .iter() |
| 37 | .map(|col_def| { |
| 38 | let primary_key = col_def |
| 39 | .get_column_spec() |
| 40 | .iter() |
| 41 | .any(|spec| matches!(spec, ColumnSpec::PrimaryKey)); |
| 42 | if primary_key { |
| 43 | primary_keys.push(PrimaryKey { |
| 44 | name: col_def.get_column_name(), |
| 45 | }); |
| 46 | } |
| 47 | col_def.into() |
| 48 | }) |
| 49 | .map(|mut col: Column| { |
| 50 | col.unique = table_create |
| 51 | .get_indexes() |
| 52 | .iter() |
| 53 | .filter(|index| index.is_unique_key()) |
| 54 | .map(|index| index.get_index_spec().get_column_names()) |
| 55 | .filter(|col_names| col_names.len() == 1 && col_names[0] == col.name) |
| 56 | .count() |
| 57 | > 0; |
| 58 | col |
| 59 | }) |
| 60 | .inspect(|col| { |
| 61 | if let sea_query::ColumnType::Enum { name, variants } = col.get_inner_col_type() |
| 62 | { |
| 63 | enums.insert( |
| 64 | name.to_string(), |
| 65 | ActiveEnum { |
| 66 | enum_name: name.clone(), |
| 67 | values: variants.clone(), |
| 68 | }, |
| 69 | ); |
nothing calls this directly
no test coverage detected