use super::assets; use crate::types::News; use clickhouse::Client; use serde::Serialize; pub async fn upsert(clickhouse_client: &Client, news: &News) { let mut insert = clickhouse_client.insert("news").unwrap(); insert.write(news).await.unwrap(); insert.end().await.unwrap(); } pub async fn upsert_batch(clickhouse_client: &Client, news: T) where T: IntoIterator + Send + Sync, T::IntoIter: Send, { let mut insert = clickhouse_client.insert("news").unwrap(); for news in news { insert.write(&news).await.unwrap(); } insert.end().await.unwrap(); } pub async fn delete_where_symbols(clickhouse_client: &Client, symbols: &[T]) where T: AsRef + Serialize + Send + Sync, { clickhouse_client .query("DELETE FROM news WHERE hasAny(symbols, ?)") .bind(symbols) .execute() .await .unwrap(); } pub async fn cleanup(clickhouse_client: &Client) { let assets = assets::select(clickhouse_client).await; let symbols = assets .into_iter() .map(|asset| asset.abbreviation) .collect::>(); clickhouse_client .query("DELETE FROM news WHERE NOT hasAny(symbols, ?)") .bind(symbols) .execute() .await .unwrap(); }