Files
web-at-transit/backend/src/api/delete_image/repo.rs
T
2026-05-24 22:55:17 +07:00

35 lines
938 B
Rust

use sqlx::PgPool;
use uuid::Uuid;
pub struct ImageRowMin {
pub fid: String,
pub url_path: String,
}
pub async fn fetch_min(pool: &PgPool, id: Uuid) -> Result<Option<ImageRowMin>, sqlx::Error> {
let row: Option<(String, String)> =
sqlx::query_as("SELECT fid, url_path FROM images WHERE id = $1")
.bind(id)
.fetch_optional(pool)
.await?;
Ok(row.map(|(fid, url_path)| ImageRowMin { fid, url_path }))
}
pub async fn delete(pool: &PgPool, id: Uuid) -> Result<u64, sqlx::Error> {
let r = sqlx::query("DELETE FROM images WHERE id = $1")
.bind(id)
.execute(pool)
.await?;
Ok(r.rows_affected())
}
pub async fn mark_pending_gc(pool: &PgPool, id: Uuid) -> Result<(), sqlx::Error> {
sqlx::query(
"UPDATE images SET meta = meta || '{\"pending_gc\":true}'::jsonb WHERE id = $1",
)
.bind(id)
.execute(pool)
.await?;
Ok(())
}