dsq_io/
traits.rs

1use crate::{Error, Result};
2use dsq_formats::{format::DataFormat, WriteOptions};
3use dsq_shared::value::Value;
4use polars::prelude::*;
5
6/// Trait for writing data to various destinations
7pub trait DataWriter {
8    /// Write a DataFrame to the destination
9    fn write(&mut self, value: &Value, options: &WriteOptions) -> Result<()>;
10
11    /// Write a LazyFrame to the destination (if supported)
12    fn write_lazy(&mut self, lf: &LazyFrame, options: &WriteOptions) -> Result<()> {
13        // Default implementation: collect then write
14        let df = lf.clone().collect().map_err(Error::from)?;
15        self.write(&Value::DataFrame(df), options)
16    }
17
18    /// Write streaming data (if supported)
19    fn write_streaming<I>(&mut self, _iter: I, _options: &WriteOptions) -> Result<()>
20    where
21        I: Iterator<Item = Result<Value>>,
22    {
23        Err(Error::Other("Streaming write not supported".to_string()))
24    }
25
26    /// Check if the writer supports streaming
27    fn supports_streaming(&self) -> bool {
28        false
29    }
30
31    /// Get the output format
32    fn format(&self) -> DataFormat;
33
34    /// Finalize the write operation (flush buffers, etc.)
35    fn finalize(&mut self) -> Result<()> {
36        Ok(())
37    }
38}