Skip to main content

max / makenotwork

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