clickhouse_client/intf/
mod.rs

1//! Interface
2//!
3//! The interface defines the interface used to communicate with the DB
4
5use async_trait::async_trait;
6
7use crate::{
8    error::Error,
9    query::{Query, QueryResponse},
10    Client,
11};
12
13pub mod http;
14
15/// An interface is a means of communicating with the database
16#[async_trait]
17pub trait Interface: Send + Sync {
18    /// Sends a ping request
19    async fn ping(&self) -> bool;
20
21    /// Sends a query
22    async fn send(&self, query: Query) -> Result<QueryResponse, Error>;
23}
24
25impl<T> Client<T>
26where
27    T: Interface,
28{
29    /// Pings the DB
30    #[tracing::instrument(skip_all)]
31    pub async fn ping(&self) -> bool {
32        self.interface.ping().await
33    }
34
35    /// Sends a query
36    pub async fn send(&self, query: Query) -> Result<QueryResponse, Error> {
37        self.interface.send(query).await
38    }
39}