mod dot;
mod html;
pub(crate) mod json;
mod mermaid;
pub use dot::to_dot;
pub use html::to_html;
pub use json::to_json;
#[allow(unused_imports)] pub use json::{ColumnJson, ErdJson, ErdStats, RelationshipJson, TableJson};
pub use mermaid::to_mermaid;
use std::fmt;
use std::str::FromStr;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum OutputFormat {
#[default]
Dot,
Mermaid,
Json,
Html,
}
impl FromStr for OutputFormat {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"dot" | "graphviz" => Ok(OutputFormat::Dot),
"mermaid" | "mmd" => Ok(OutputFormat::Mermaid),
"json" => Ok(OutputFormat::Json),
"html" => Ok(OutputFormat::Html),
_ => Err(format!(
"Unknown format: {}. Valid options: dot, mermaid, json, html",
s
)),
}
}
}
impl fmt::Display for OutputFormat {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
OutputFormat::Dot => write!(f, "dot"),
OutputFormat::Mermaid => write!(f, "mermaid"),
OutputFormat::Json => write!(f, "json"),
OutputFormat::Html => write!(f, "html"),
}
}
}
impl OutputFormat {
pub fn extension(&self) -> &'static str {
match self {
OutputFormat::Dot => "dot",
OutputFormat::Mermaid => "mmd",
OutputFormat::Json => "json",
OutputFormat::Html => "html",
}
}
pub fn from_extension(ext: &str) -> Option<Self> {
match ext.to_lowercase().as_str() {
"dot" | "gv" => Some(OutputFormat::Dot),
"mmd" | "mermaid" => Some(OutputFormat::Mermaid),
"json" => Some(OutputFormat::Json),
"html" | "htm" => Some(OutputFormat::Html),
"png" | "svg" | "pdf" => Some(OutputFormat::Dot), _ => None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Layout {
#[default]
LR,
TB,
}
impl FromStr for Layout {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"lr" | "left-right" | "horizontal" => Ok(Layout::LR),
"tb" | "td" | "top-bottom" | "top-down" | "vertical" => Ok(Layout::TB),
_ => Err(format!("Unknown layout: {}. Valid options: lr, tb", s)),
}
}
}
impl fmt::Display for Layout {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Layout::LR => write!(f, "lr"),
Layout::TB => write!(f, "tb"),
}
}
}