Fix array formatting for SQL

This commit is contained in:
Elias Schriefer 2021-11-16 23:49:43 +01:00
parent 0d9631b6c4
commit 5c8e72a733

View File

@ -79,21 +79,24 @@ where
} }
#[inline] #[inline]
fn format_array_for_sql<T>(values: &[T]) -> String fn format_array_for_sql<I, T>(values: I) -> String
where where
T: Display I: IntoIterator<Item=T>,
T: Display,
{ {
match values.len() { let mut iter = values.into_iter();
1.. => {
let mut output = values[0].to_string(); let mut output = match iter.next() {
for v in &values[1..] { Some(first) => first.to_string(),
None => return String::new(),
};
for v in iter {
output += ","; output += ",";
output += &v.to_string(); output += &v.to_string();
} }
output output
},
_ => values.first().map(|v| v.to_string()).unwrap_or(String::new()),
}
} }
#[inline] #[inline]