Display list of links

This commit is contained in:
SinTan1729 committed 2023-04-03 11:55:27 -05:00
1 parent b9d76b6734
commit a1f73c8a9d
6 files changed
+36 -7

No files matched your search

+22
View File
@@ -21,3 +21,25 @@ pub fn find_url(shortlink: &str) -> String {
String::from(longlink)
}
pub fn getall() -> Vec<String> {
let db = open("./urls.sqlite").expect("Unable to open database!");
let query = "SELECT * FROM urls";
let statement: Vec<Row> = db
.prepare(query)
.unwrap()
.into_iter()
.map(|row| row.unwrap())
.collect();
let mut links: Vec<String> = Vec::new();
for row in statement {
let short_url = row.read::<&str, _>("short_url");
let long_url = row.read::<&str, _>("long_url");
let hits = row.read::<i64, _>("hits");
links.push(format!("{short_url},{long_url},{hits}"));
}
links
}