Separate clock handler
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use crate::types::{Asset, Class};
|
||||
use clickhouse::Client;
|
||||
use serde::Serialize;
|
||||
|
||||
pub async fn select(clickhouse_client: &Client) -> Vec<Asset> {
|
||||
clickhouse_client
|
||||
@@ -18,7 +19,10 @@ pub async fn select_where_class(clickhouse_client: &Client, class: &Class) -> Ve
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub async fn select_where_symbol(clickhouse_client: &Client, symbol: &str) -> Option<Asset> {
|
||||
pub async fn select_where_symbol<T>(clickhouse_client: &Client, symbol: &T) -> Option<Asset>
|
||||
where
|
||||
T: AsRef<str> + Serialize + Send + Sync,
|
||||
{
|
||||
clickhouse_client
|
||||
.query("SELECT ?fields FROM assets FINAL WHERE symbol = ?")
|
||||
.bind(symbol)
|
||||
@@ -27,15 +31,22 @@ pub async fn select_where_symbol(clickhouse_client: &Client, symbol: &str) -> Op
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub async fn upsert_batch(clickhouse_client: &Client, assets: &Vec<Asset>) {
|
||||
pub async fn upsert_batch<T>(clickhouse_client: &Client, assets: T)
|
||||
where
|
||||
T: IntoIterator<Item = Asset> + Send + Sync,
|
||||
T::IntoIter: Send,
|
||||
{
|
||||
let mut insert = clickhouse_client.insert("assets").unwrap();
|
||||
for asset in assets {
|
||||
insert.write(asset).await.unwrap();
|
||||
insert.write(&asset).await.unwrap();
|
||||
}
|
||||
insert.end().await.unwrap();
|
||||
}
|
||||
|
||||
pub async fn delete_where_symbols(clickhouse_client: &Client, symbols: &Vec<String>) {
|
||||
pub async fn delete_where_symbols<T>(clickhouse_client: &Client, symbols: &[T])
|
||||
where
|
||||
T: AsRef<str> + Serialize + Send + Sync,
|
||||
{
|
||||
clickhouse_client
|
||||
.query("DELETE FROM assets WHERE symbol IN ?")
|
||||
.bind(symbols)
|
||||
|
Reference in New Issue
Block a user