use arrow_array::RecordBatch;
use crate::duckdb_destination::_helpers::blocking::with_connection;
use crate::duckdb_destination::errors::DuckDbError;
use crate::duckdb_destination::models::DuckDbDestination;
use crate::write_sql::models::TableName;
pub async fn append_batch(
destination: &DuckDbDestination,
table: &TableName,
batch: RecordBatch,
) -> Result<(), DuckDbError> {
let schema = table.schema.clone();
let name = table.table.clone();
with_connection(destination, move |connection| {
let mut appender = connection.appender_to_db(&name, &schema)?;
appender.append_record_batch(batch)?;
appender.flush()?;
Ok(())
})
.await
}