athena_rs 3.18.0

Hyper performant polyglot Database driver
Documentation
//! Compatibility facade for the extracted `athena-driver` Scylla backend.

use crate::config::Config;
pub use athena_driver::scylla::client::{
    ScyllaConnectionInfo, execute_query_with_info, open_session,
};
use serde_json::Value;
use std::collections::HashMap;
use std::error::Error;

fn parse_hosts(raw: &str) -> Vec<String> {
    raw.split(',')
        .map(str::trim)
        .filter(|value| !value.is_empty())
        .map(str::to_string)
        .collect::<Vec<_>>()
}

fn scylla_connection_info_from_config(config: &Config) -> ScyllaConnectionInfo {
    let hosts: Vec<String> = parse_hosts(
        config
            .get_host_resolved("scylladb")
            .as_deref()
            .unwrap_or("167.235.9.113:9042"),
    );
    let auth: Option<HashMap<String, String>> = config.get_authenticator_resolved("scylladb");
    ScyllaConnectionInfo::from_resolved_parts(hosts, auth)
}

/// Load the Scylla connection configuration from disk.
pub fn load_connection_info() -> Result<ScyllaConnectionInfo, Box<dyn Error>> {
    let config: Config = Config::load()?;
    Ok(scylla_connection_info_from_config(&config))
}

/// Execute the provided CQL query and return the normalized JSON rows.
pub async fn execute_query(query: String) -> Result<(Vec<Value>, Vec<String>), Box<dyn Error>> {
    let info: ScyllaConnectionInfo = load_connection_info()?;
    execute_query_with_info(query, &info).await
}