sql_table/index_name.rs
1use crate::table::{Iden, Table, TableColumn, Unquote};
2
3pub trait IndexName: Unquote + Iden {
4 fn index_name<C>(cols: &[C]) -> String
5 where
6 C: TableColumn,
7 {
8 let q = if !C::QUOTE.is_empty() {
9 C::QUOTE
10 } else {
11 C::Table::QUOTE
12 };
13 format!(
14 "{q}ix_{}{}{q}",
15 C::TABLE.unquoted(),
16 cols.iter()
17 .fold(String::new(), |acc, x| format!("{}_{}", acc, x.unquoted()))
18 )
19 }
20}
21
22impl<T> IndexName for T where T: Unquote + Iden {}