use crate::connection;
use crate::prelude::*;
#[derive(Clone)]
pub struct Connection
{
service_client: mqtt_service::Client,
prefix: String,
}
impl Connection
{
pub fn new(prefix: impl Into<String>, mqtt_client: mqtt_channel::Client) -> Connection
{
Connection {
service_client: mqtt_service::Client::new(mqtt_client),
prefix: prefix.into(),
}
}
}
impl Connection {}
impl connection::ConnectionPrivate for Connection {}
impl connection::Connection for Connection
{
async fn is_connected(&self) -> bool
{
true
}
fn execute_query<TQuery>(
&self,
query: TQuery,
) -> Result<impl std::future::Future<Output = Result<dbc::Result>>>
where
TQuery: TryInto<dbc::Query>,
crate::Error: From<<TQuery as TryInto<dbc::Query>>::Error>,
{
let query = query.try_into()?;
let fut = self
.service_client
.clone()
.call_json_service::<crate::dbc::Query, crate::dbc::Result>(
format!("{}/krql_query", self.prefix),
&query,
)?;
Ok(async { Ok(fut.await?) })
}
}