#[cfg(feature = "duckdb")]
use std::sync::{Arc, Mutex};
#[cfg(feature = "duckdb")]
use crate::adapters::motherduck_bridge::models::BridgeConnection;
#[cfg(feature = "duckdb")]
#[derive(Debug, Clone)]
pub struct DuckDbDestination {
pub connection: DuckDbConnection,
pub ddl: Arc<tokio::sync::Mutex<()>>,
pub motherduck: bool,
pub bridge_duckdb: String,
pub memory: Option<crate::memory_budget::models::DuckDbShare>,
pub own_limit: Option<u64>,
pub unflushed: Arc<std::sync::atomic::AtomicU64>,
pub secrets: Arc<tokio::sync::Mutex<std::collections::HashMap<String, SetSecret>>>,
pub stage: Option<Arc<ExternalStage>>,
}
#[cfg(feature = "duckdb")]
#[derive(Debug)]
pub struct ExternalStage {
pub folder: crate::file_store::models::OpenFolder,
pub keep: bool,
pub checked: tokio::sync::OnceCell<Result<(), String>>,
}
#[cfg(feature = "duckdb")]
#[derive(Debug, Default)]
pub struct StagedChunks {
pub insert: String,
pub waiting: Vec<(String, u64)>,
pub loaded: Vec<String>,
pub written: u64,
pub transaction: bool,
}
#[cfg(feature = "duckdb")]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SetSecret {
pub hash: u64,
pub chain: bool,
pub at: std::time::Instant,
}
#[cfg(feature = "duckdb")]
#[derive(Debug, Clone)]
pub enum DuckDbConnection {
Local(Arc<Mutex<duckdb::Connection>>),
Bridge(BridgeConnection),
}
#[derive(Debug, Clone, Copy, Default)]
pub struct DuckDbSql;
#[cfg(feature = "duckdb")]
#[derive(Debug)]
pub struct DuckDbWriter {
pub destination: DuckDbDestination,
pub open_transaction: bool,
pub staged: Box<StagedChunks>,
}