Skip to content

Commit

Permalink
[fix] clippy errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
coderPaddyS committed Jun 20, 2024
1 parent 92d81f2 commit 0fd7dfd
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
14 changes: 7 additions & 7 deletions diesel_cli/src/infer_schema_internals/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ impl ForeignKeyConstraint {

#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum SupportedColumnStructures {
VIEW,
TABLE,
View,
Table,
}

#[derive(Debug)]
Expand Down Expand Up @@ -198,8 +198,8 @@ impl ColumnData {
impl Display for SupportedColumnStructures {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let format = match self {
Self::TABLE => "BASE TABLE",
Self::VIEW => "VIEW",
Self::Table => "BASE TABLE",
Self::View => "VIEW",
};
write!(f, "{format}")
}
Expand All @@ -209,8 +209,8 @@ impl FromStr for SupportedColumnStructures {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"BASE TABLE" => Ok(Self::TABLE),
"VIEW" => Ok(Self::VIEW),
"BASE TABLE" => Ok(Self::Table),
"VIEW" => Ok(Self::View),
_ => unreachable!("This should never happen. Read {s}"),
}
}
Expand All @@ -224,6 +224,6 @@ impl SupportedColumnStructures {
.collect()
}
pub fn all() -> Vec<SupportedColumnStructures> {
vec![Self::VIEW, Self::TABLE]
vec![Self::View, Self::Table]
}
}
12 changes: 6 additions & 6 deletions diesel_cli/src/infer_schema_internals/inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ pub fn load_table_names(
}

pub fn filter_column_structure(
table_names: &Vec<(SupportedColumnStructures, TableName)>,
table_names: &[(SupportedColumnStructures, TableName)],
structure: SupportedColumnStructures,
) -> Vec<TableName> {
table_names
.into_iter()
.iter()
.filter_map(|(s, t)| if *s == structure { Some(t) } else { None })
.cloned()
.collect()
Expand Down Expand Up @@ -286,19 +286,19 @@ fn load_column_structure_data(
DocConfig::NoDocComments => None,
DocConfig::OnlyDatabaseComments
| DocConfig::DatabaseCommentsFallbackToAutoGeneratedDocComment => {
get_table_comment(connection, &name)?
get_table_comment(connection, name)?
}
};

get_column_information(connection, &name, &config.column_sorting)?
get_column_information(connection, name, &config.column_sorting)?
.into_iter()
.map(|c| {
let default_pk = vec![];
let ty = determine_column_type(
&c,
connection,
&name,
primary_key.unwrap_or_else(|| &default_pk),
name,
primary_key.unwrap_or(&default_pk),
config,
)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ where
Ok(table_names
.into_iter()
.map(|(name, tpy)| {
let tpy = SupportedColumnStructures::from_str(&tpy).unwrap();
let tpy = SupportedColumnStructures::from_str(&tpy).expect("This should never happen.");
let data = TableName {
rust_name: inference::rust_name_for_sql_name(&name),
sql_name: name,
Expand Down
4 changes: 2 additions & 2 deletions diesel_cli/src/infer_schema_internals/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn load_table_names(
.into_iter()
.map(|table| {
(
SupportedColumnStructures::TABLE,
SupportedColumnStructures::Table,
TableName::from_name(table),
)
});
Expand All @@ -62,7 +62,7 @@ pub fn load_table_names(
.order(name)
.load::<String>(connection)?
.into_iter()
.map(|table| (SupportedColumnStructures::VIEW, TableName::from_name(table)));
.map(|table| (SupportedColumnStructures::View, TableName::from_name(table)));

Ok(tables.chain(view).collect())
}
Expand Down
4 changes: 2 additions & 2 deletions diesel_cli/src/migrations/diff_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn generate_sql_based_on_diff_schema(
for (structure, table) in tables_from_database {
tracing::info!(?table, "Diff for existing table");
match structure {
SupportedColumnStructures::TABLE => {
SupportedColumnStructures::Table => {
let columns = crate::infer_schema_internals::load_table_data(
&mut conn,
table.clone(),
Expand Down Expand Up @@ -151,7 +151,7 @@ pub fn generate_sql_based_on_diff_schema(
});
}
}
SupportedColumnStructures::VIEW => {
SupportedColumnStructures::View => {
return Err(crate::errors::Error::UnsupportedFeature(
"Views are not supported by --diff-schema yet".into(),
));
Expand Down
8 changes: 4 additions & 4 deletions diesel_cli/src/print_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub fn output_schema(
let foreign_keys = remove_unsafe_foreign_keys_for_codegen(
connection,
&foreign_keys,
&filter_column_structure(&table_names, SupportedColumnStructures::TABLE),
&filter_column_structure(&table_names, SupportedColumnStructures::Table),
);

let mut out = String::new();
Expand All @@ -169,10 +169,10 @@ pub fn output_schema(
let data = table_names
.into_iter()
.map(|(kind, t)| match kind {
SupportedColumnStructures::TABLE => {
SupportedColumnStructures::Table => {
Ok(ColumnData::Table(load_table_data(connection, t, config)?))
}
SupportedColumnStructures::VIEW => {
SupportedColumnStructures::View => {
Ok(ColumnData::View(load_view_data(connection, t, config)?))
}
})
Expand Down Expand Up @@ -660,7 +660,7 @@ impl<'a> Display for ColumnStructureDefinition<'a> {
out,
"{}",
ColumnDefinitions {
columns: &self.table.columns(),
columns: self.table.columns(),
with_docs: self.with_docs,
table_full_sql_name: &full_sql_name,
custom_type_overrides: self.custom_type_overrides
Expand Down

0 comments on commit 0fd7dfd

Please sign in to comment.