kdb-connection 0.1.0

kDB connection.
Documentation
use crate::connection;

use crate::prelude::*;

// Structures

#[derive(Clone)]
pub struct Connection
{
    service_client: mqtt_service::Client,
    prefix: String,
}

// Implementations

impl Connection
{
    /// Create a new MQTT Connection, to connect to a kDB server at the given prefix and MQTT broker
    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
    {
        // https://gitlab.com/auksys/kdb/-/issues/34
        // https://gitlab.com/cyloncore/mqtt-channel/-/issues/4
        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?) })
    }
}