-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlib.rs
More file actions
55 lines (48 loc) · 1.52 KB
/
lib.rs
File metadata and controls
55 lines (48 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use strum_macros::{Display, EnumString};
pub mod error;
pub mod mermaid_generator;
pub mod plantuml_generator;
pub mod psql_erd_loader;
pub mod sql_entities;
pub use error::SqlantError;
use mermaid_generator::MermaidGenerator;
use plantuml_generator::PlantUmlDefaultGenerator;
use psql_erd_loader::PostgreSqlERDLoader;
use sql_entities::{SqlERData, SqlERDataLoader};
pub struct GeneratorConfigOptions {
pub not_null: bool,
pub draw_enums: bool,
pub draw_legend: bool,
pub inline_puml_lib: bool,
pub conceptual_diagram: bool,
}
pub trait ViewGenerator {
fn generate(
&self,
sql_erd: SqlERData,
opts: &GeneratorConfigOptions,
) -> Result<String, SqlantError>;
}
pub async fn lookup_parser(
connection_string: &str,
schema_name: String,
) -> Result<Box<dyn SqlERDataLoader>, SqlantError> {
Ok(Box::new(
PostgreSqlERDLoader::new(connection_string, schema_name).await?,
))
}
#[derive(Clone, Debug, Display, EnumString, Eq, PartialEq, PartialOrd, Ord)]
#[strum(serialize_all = "lowercase")]
pub enum GeneratorType {
PlantUML,
Mermaid,
}
// If you want to add generator, you need to add input parameter
// for this function.
// To distinguish what exactly generator you need.
pub fn get_generator(generator_type: GeneratorType) -> Result<Box<dyn ViewGenerator>, SqlantError> {
match generator_type {
GeneratorType::PlantUML => Ok(Box::new(PlantUmlDefaultGenerator::new()?)),
GeneratorType::Mermaid => Ok(Box::new(MermaidGenerator::new()?)),
}
}