Display list of links
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user