mirror of
https://github.com/13hannes11/ics-proxy.git
synced 2024-09-06 08:01:41 +02:00
add selecting entries from the database
This commit is contained in:
19
src/model.rs
19
src/model.rs
@@ -11,6 +11,25 @@ pub struct Link {
|
||||
}
|
||||
|
||||
impl Link {
|
||||
pub async fn find_by_uuid(
|
||||
uuid: String,
|
||||
pool: web::Data<Pool<Sqlite>>,
|
||||
) -> Result<Link, sqlx::Error> {
|
||||
let mut tx = pool.begin().await?;
|
||||
let rec = sqlx::query!(
|
||||
r#"
|
||||
SELECT * FROM links WHERE uuid = $1
|
||||
"#,
|
||||
uuid
|
||||
)
|
||||
.fetch_one(&mut tx)
|
||||
.await?;
|
||||
|
||||
Ok(Link {
|
||||
uuid: rec.UUID,
|
||||
destination: rec.DESTINATION,
|
||||
})
|
||||
}
|
||||
pub async fn create(link: Link, pool: web::Data<Pool<Sqlite>>) -> Result<Link, sqlx::Error> {
|
||||
let mut tx = pool.begin().await?;
|
||||
sqlx::query("INSERT INTO links (uuid, destination) VALUES ($1, $2);")
|
||||
|
||||
Reference in New Issue
Block a user