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
//! `DBViz` - Database Diagram Generator
//!
//! `DBViz` is a tool for generating database diagrams.

mod opts;
mod postgresql;
mod schema;

use std::fs;

use anyhow::Result;
use minijinja::{context, Environment};

fn main() -> Result<()> {
    let opts = opts::load();

    let loader = postgresql::Conn::new(&opts)?;
    let schema = loader.load()?;

    let template_file = match &opts.template {
        Some(fname) => fs::read_to_string(fname)?,
        None => include_str!("default_template.jinja").to_string(),
    };

    let mut env = Environment::new();
    env.add_template("diagram", &template_file)?;
    let tmpl = env.get_template("diagram")?;

    let ctx = context!(
        opts => opts,
        schema => schema
    );

    let rendered = tmpl.render(ctx)?;

    println!("{rendered}");

    Ok(())
}