Clean up error propagation
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
use crate::types::News;
|
||||
use clickhouse::Client;
|
||||
use clickhouse::{error::Error, 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(clickhouse_client: &Client, news: &News) -> Result<(), Error> {
|
||||
let mut insert = clickhouse_client.insert("news")?;
|
||||
insert.write(news).await?;
|
||||
insert.end().await
|
||||
}
|
||||
|
||||
pub async fn upsert_batch<T>(clickhouse_client: &Client, news: T)
|
||||
pub async fn upsert_batch<T>(clickhouse_client: &Client, news: T) -> Result<(), Error>
|
||||
where
|
||||
T: IntoIterator<Item = News> + Send + Sync,
|
||||
T::IntoIter: Send,
|
||||
{
|
||||
let mut insert = clickhouse_client.insert("news").unwrap();
|
||||
let mut insert = clickhouse_client.insert("news")?;
|
||||
for news in news {
|
||||
insert.write(&news).await.unwrap();
|
||||
insert.write(&news).await?;
|
||||
}
|
||||
insert.end().await.unwrap();
|
||||
insert.end().await
|
||||
}
|
||||
|
||||
pub async fn delete_where_symbols<T>(clickhouse_client: &Client, symbols: &[T])
|
||||
pub async fn delete_where_symbols<T>(clickhouse_client: &Client, symbols: &[T]) -> Result<(), Error>
|
||||
where
|
||||
T: AsRef<str> + Serialize + Send + Sync,
|
||||
{
|
||||
@@ -29,15 +29,13 @@ where
|
||||
.bind(symbols)
|
||||
.execute()
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub async fn cleanup(clickhouse_client: &Client) {
|
||||
pub async fn cleanup(clickhouse_client: &Client) -> Result<(), Error> {
|
||||
clickhouse_client
|
||||
.query(
|
||||
"DELETE FROM news WHERE NOT hasAny(symbols, (SELECT groupArray(symbol) FROM assets))",
|
||||
)
|
||||
.execute()
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
Reference in New Issue
Block a user