use std::sync::Arc;
use crate::config::CassandraConfig;
use crate::connection::CassandraConnection;
use crate::error::CassandraResult;
pub struct CassandraPool {
connection: Arc<CassandraConnection>,
}
impl CassandraPool {
pub async fn connect(config: CassandraConfig) -> CassandraResult<Self> {
let connection = CassandraConnection::connect(config).await?;
Ok(Self {
connection: Arc::new(connection),
})
}
pub async fn close(self) -> CassandraResult<()> {
Ok(())
}
pub fn connection(&self) -> &CassandraConnection {
&self.connection
}
pub fn shared(&self) -> Arc<CassandraConnection> {
Arc::clone(&self.connection)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_pool_connect_returns_error_without_cluster() {
let config = CassandraConfig::builder()
.known_nodes(["127.0.0.1:9042".to_string()])
.build();
let result = CassandraPool::connect(config).await;
assert!(result.is_err());
}
}