Skip to content

Commit

Permalink
Simplify formatting code, avoid trailing , after macro formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sgoll committed Feb 22, 2025
1 parent 472ed39 commit 758b090
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
23 changes: 10 additions & 13 deletions diesel_cli/src/print_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,26 +603,23 @@ impl Display for TableDefinitions<'_> {
vec![self.tables.iter().map(|table| &table.name).collect()]
}
};
is_first = true;
for tables in table_groups {
if tables.len() < 2 {
continue;
}

if is_first {
for (table_group_index, table_group) in table_groups
.into_iter()
.filter(|table_group| table_group.len() >= 2)
.enumerate()
{
if table_group_index == 0 {
writeln!(f)?;
is_first = false;
}
write!(f, "diesel::allow_tables_to_appear_in_same_query!(")?;
{
let mut out = PadAdapter::new(f);
writeln!(out)?;
for table in tables {
if table.rust_name == table.sql_name {
writeln!(out, "{},", table.sql_name)?;
} else {
writeln!(out, "{},", table.rust_name)?;
for (table_index, table) in table_group.into_iter().enumerate() {
if table_index != 0 {
write!(out, ", ")?;
}
write!(out, "{}", table.rust_name)?;
}
}
writeln!(f, ");")?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ diesel::joinable!(comments -> posts (post_id));
diesel::joinable!(posts -> users (user_id));
diesel::joinable!(transactions -> sessions (session_id));

diesel::allow_tables_to_appear_in_same_query!(comments, posts, users,);
diesel::allow_tables_to_appear_in_same_query!(sessions, transactions,);
diesel::allow_tables_to_appear_in_same_query!(comments, posts, users);
diesel::allow_tables_to_appear_in_same_query!(sessions, transactions);

0 comments on commit 758b090

Please sign in to comment.