use std::marker::PhantomData;
#[cfg(feature = "sqlite")]
use std::sync::Arc;
#[cfg(feature = "duckdb")]
use std::sync::Arc as DuckDbArc;
pub enum StreamConnection<'a> {
#[cfg(feature = "sqlite")]
Sqlite(Arc<turso::Connection>),
#[cfg(feature = "duckdb")]
DuckDB(DuckDbArc<super::super::duckdb_backend::duckcompat::Connection>),
#[cfg(feature = "postgresql")]
PostgreSQL(&'a tokio_postgres::Client),
#[cfg(feature = "mysql")]
MySQL(mysql_async::Conn),
#[cfg(feature = "mssql")]
MSSQL(&'a tiberius::Client<tokio_util::compat::Compat<tokio::net::TcpStream>>),
#[doc(hidden)]
__Lifetime(PhantomData<&'a ()>),
}
impl<'a> StreamConnection<'a> {
#[cfg(feature = "sqlite")]
pub fn expect_sqlite(&self) -> &Arc<turso::Connection> {
match self {
StreamConnection::Sqlite(conn) => conn,
_ => unreachable!("Expected Sqlite connection"),
}
}
#[cfg(feature = "postgresql")]
pub fn expect_postgresql(&self) -> &&'a tokio_postgres::Client {
match self {
StreamConnection::PostgreSQL(client) => client,
_ => unreachable!("Expected PostgreSQL connection"),
}
}
#[cfg(feature = "duckdb")]
pub fn expect_duckdb(
&self,
) -> &DuckDbArc<super::super::duckdb_backend::duckcompat::Connection> {
match self {
StreamConnection::DuckDB(conn) => conn,
_ => unreachable!("Expected DuckDB connection"),
}
}
}
impl<'a> Drop for StreamConnection<'a> {
fn drop(&mut self) {
match self {
#[cfg(feature = "sqlite")]
StreamConnection::Sqlite(_) => {
}
#[cfg(feature = "duckdb")]
StreamConnection::DuckDB(_) => {}
#[cfg(feature = "postgresql")]
StreamConnection::PostgreSQL(_) => {
}
#[cfg(feature = "mysql")]
StreamConnection::MySQL(conn) => {
let _ = conn;
}
#[cfg(feature = "mssql")]
StreamConnection::MSSQL(_) => {
}
StreamConnection::__Lifetime(_) => {}
}
}
}