mod csv;
mod error;
mod extract;
mod html;
mod json;
mod mermaid;
mod naming;
mod schema;
mod sql_backend;
mod xlsx;
#[cfg(feature = "duckdb")]
mod duckdb_backend;
pub use error::ExportError;
pub use extract::{ColumnMapping, ScriptInfo, TableDependency, TableInfo, TableType};
pub use mermaid::MermaidView;
pub use naming::ExportNaming;
use flowscope_core::AnalyzeResult;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ExportFormat {
DuckDb,
Sql { schema: bool },
Json { compact: bool },
Mermaid { view: MermaidView },
Html,
CsvBundle,
Xlsx,
Png,
}
pub type Format = ExportFormat;
pub fn export(result: &AnalyzeResult, format: ExportFormat) -> Result<Vec<u8>, ExportError> {
match format {
#[cfg(feature = "duckdb")]
ExportFormat::DuckDb => duckdb_backend::export(result),
#[cfg(not(feature = "duckdb"))]
ExportFormat::DuckDb => Err(ExportError::UnsupportedFormat("DuckDB feature not enabled")),
ExportFormat::Sql { .. } => Ok(sql_backend::export_sql(result, None)?.into_bytes()),
ExportFormat::Json { compact } => Ok(json::export_json(result, compact)?.into_bytes()),
ExportFormat::Mermaid { view } => Ok(mermaid::export_mermaid(result, view).into_bytes()),
ExportFormat::Html => {
Ok(html::export_html(result, "FlowScope", chrono::Utc::now()).into_bytes())
}
ExportFormat::CsvBundle => csv::export_csv_bundle(result),
ExportFormat::Xlsx => xlsx::export_xlsx(result),
ExportFormat::Png => Err(ExportError::UnsupportedFormat("PNG export is UI-only")),
}
}
#[cfg(feature = "duckdb")]
pub fn export_duckdb(result: &AnalyzeResult) -> Result<Vec<u8>, ExportError> {
duckdb_backend::export(result)
}
pub fn export_sql(result: &AnalyzeResult, schema: Option<&str>) -> Result<String, ExportError> {
sql_backend::export_sql(result, schema)
}
pub fn export_json(result: &AnalyzeResult, compact: bool) -> Result<String, ExportError> {
json::export_json(result, compact)
}
pub fn export_mermaid(result: &AnalyzeResult, view: MermaidView) -> Result<String, ExportError> {
Ok(mermaid::export_mermaid(result, view))
}
pub fn export_csv_bundle(result: &AnalyzeResult) -> Result<Vec<u8>, ExportError> {
csv::export_csv_bundle(result)
}
pub fn export_xlsx(result: &AnalyzeResult) -> Result<Vec<u8>, ExportError> {
xlsx::export_xlsx(result)
}
pub fn export_html(
result: &AnalyzeResult,
project_name: &str,
exported_at: chrono::DateTime<chrono::Utc>,
) -> Result<String, ExportError> {
Ok(html::export_html(result, project_name, exported_at))
}