1mod csv;
10mod error;
11mod extract;
12mod html;
13mod json;
14mod mermaid;
15mod naming;
16mod schema;
17mod sql_backend;
18mod xlsx;
19
20#[cfg(feature = "duckdb")]
21mod duckdb_backend;
22
23pub use error::ExportError;
24pub use extract::{ColumnMapping, ScriptInfo, TableDependency, TableInfo, TableType};
25pub use mermaid::MermaidView;
26pub use naming::ExportNaming;
27
28use flowscope_core::AnalyzeResult;
29
30#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub enum ExportFormat {
33 DuckDb,
34 Sql { schema: bool },
35 Json { compact: bool },
36 Mermaid { view: MermaidView },
37 Html,
38 CsvBundle,
39 Xlsx,
40 Png,
41}
42
43pub type Format = ExportFormat;
44
45pub fn export(result: &AnalyzeResult, format: ExportFormat) -> Result<Vec<u8>, ExportError> {
50 match format {
51 #[cfg(feature = "duckdb")]
52 ExportFormat::DuckDb => duckdb_backend::export(result),
53 #[cfg(not(feature = "duckdb"))]
54 ExportFormat::DuckDb => Err(ExportError::UnsupportedFormat("DuckDB feature not enabled")),
55 ExportFormat::Sql { .. } => Ok(sql_backend::export_sql(result, None)?.into_bytes()),
56 ExportFormat::Json { compact } => Ok(json::export_json(result, compact)?.into_bytes()),
57 ExportFormat::Mermaid { view } => Ok(mermaid::export_mermaid(result, view).into_bytes()),
58 ExportFormat::Html => {
59 Ok(html::export_html(result, "FlowScope", chrono::Utc::now()).into_bytes())
60 }
61 ExportFormat::CsvBundle => csv::export_csv_bundle(result),
62 ExportFormat::Xlsx => xlsx::export_xlsx(result),
63 ExportFormat::Png => Err(ExportError::UnsupportedFormat("PNG export is UI-only")),
64 }
65}
66
67#[cfg(feature = "duckdb")]
71pub fn export_duckdb(result: &AnalyzeResult) -> Result<Vec<u8>, ExportError> {
72 duckdb_backend::export(result)
73}
74
75pub fn export_sql(result: &AnalyzeResult, schema: Option<&str>) -> Result<String, ExportError> {
85 sql_backend::export_sql(result, schema)
86}
87
88pub fn export_json(result: &AnalyzeResult, compact: bool) -> Result<String, ExportError> {
89 json::export_json(result, compact)
90}
91
92pub fn export_mermaid(result: &AnalyzeResult, view: MermaidView) -> Result<String, ExportError> {
93 Ok(mermaid::export_mermaid(result, view))
94}
95
96pub fn export_csv_bundle(result: &AnalyzeResult) -> Result<Vec<u8>, ExportError> {
97 csv::export_csv_bundle(result)
98}
99
100pub fn export_xlsx(result: &AnalyzeResult) -> Result<Vec<u8>, ExportError> {
101 xlsx::export_xlsx(result)
102}
103
104pub fn export_html(
105 result: &AnalyzeResult,
106 project_name: &str,
107 exported_at: chrono::DateTime<chrono::Utc>,
108) -> Result<String, ExportError> {
109 Ok(html::export_html(result, project_name, exported_at))
110}