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