Skip to content

Commit

Permalink
Fix display string concatenation for array columns (#98)
Browse files Browse the repository at this point in the history
* Fixes display string concatenation for array columns (["a", "b", "c"] was rendered "abc", now "{a, b, c}")

* Applied clippy recommendations

---------

Co-authored-by: Iwer Petersen <iwer.petersen@gmail.com>
  • Loading branch information
iwer and Iwer Petersen authored Sep 23, 2024
1 parent 1441ef4 commit 6712de2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,14 @@ pub fn row_to_json(row: &PgRow) -> HashMap<String, String> {
}

pub fn vec_to_string<T: std::string::ToString>(vec: Vec<T>) -> String {
vec.iter().fold(String::new(), |mut output, b| {
let s = b.to_string();
let _ = write!(output, "{s}");
output
})
let mut content = String::new();
for (i, elem) in vec.iter().enumerate() {
content.push_str(&elem.to_string());
if i != vec.len() - 1 {
content.push_str(", ");
}
}
"{ ".to_owned() + &*content + &*" }".to_owned()
}

pub fn row_to_vec(row: &PgRow) -> Vec<String> {
Expand Down

0 comments on commit 6712de2

Please sign in to comment.