updating link from edit page works now

This commit is contained in:
2021-09-03 12:53:39 +02:00
parent 5820549f01
commit 6a0bbf2059
2 changed files with 41 additions and 23 deletions

View File

@@ -30,6 +30,17 @@ impl Link {
destination: rec.DESTINATION,
})
}
pub async fn update(link: Link, pool: web::Data<Pool<Sqlite>>) -> Result<Link, sqlx::Error> {
let mut tx = pool.begin().await?;
sqlx::query("UPDATE links SET destination = $2 WHERE uuid = $1;")
.bind(&link.uuid)
.bind(&link.destination)
.execute(&mut tx)
.await?;
tx.commit().await?;
Ok(link)
}
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);")