sqlload 0.16.0

SQL data loading tooling. Pre-release, under development.
//! Give one table's load its own connection.

use std::sync::{Arc, Mutex};

use crate::adapters::duckdb::errors::DuckDbError;
use crate::adapters::duckdb::models::DuckDbDestination;

/// A new connection to the same database, so one table's transaction never mixes with another table's loading at the same time.
pub(in crate::adapters) fn own_connection(
    destination: &DuckDbDestination,
) -> Result<DuckDbDestination, DuckDbError> {
    let connection = destination
        .connection
        .lock()
        .map_err(|_| DuckDbError::Task("the connection lock is poisoned".to_owned()))?
        .try_clone()?;
    Ok(DuckDbDestination {
        connection: Arc::new(Mutex::new(connection)),
        ddl: destination.ddl.clone(),
    })
}