1
0
Fork 0
mirror of https://github.com/SinTan1729/chhoto-url synced 2024-12-28 08:28:36 -06:00
chhoto-url/actix/src/database.rs

24 lines
561 B
Rust
Raw Normal View History

2023-04-02 22:26:23 -05:00
use sqlite::{open, Row};
pub fn find_url(shortlink: &str) -> String {
let db = open("./urls.sqlite").expect("Unable to open database!");
let query = "SELECT long_url FROM urls WHERE short_url = ?";
let statement: Vec<Row> = db
.prepare(query)
.unwrap()
.into_iter()
.bind((1, shortlink))
.unwrap()
.map(|row| row.unwrap())
.collect();
let mut longlink = "";
if statement.len() == 1 {
longlink = statement[0].read::<&str, _>("long_url");
}
String::from(longlink)
}