Skip to main content

max / makenotwork

580 B · 25 lines History Blame Raw
1 use super::{PgPool, Uuid};
2
3 /// Insert a link preview for a post. Ignores duplicates.
4 #[tracing::instrument(skip_all)]
5 pub async fn insert_link_preview(
6 pool: &PgPool,
7 post_id: Uuid,
8 url: &str,
9 title: Option<&str>,
10 description: Option<&str>,
11 ) -> Result<(), sqlx::Error> {
12 sqlx::query!(
13 "INSERT INTO link_previews (post_id, url, title, description)
14 VALUES ($1, $2, $3, $4)
15 ON CONFLICT (post_id, url) DO NOTHING",
16 post_id,
17 url,
18 title,
19 description,
20 )
21 .execute(pool)
22 .await?;
23 Ok(())
24 }
25