data_goes 0.1.0-alpha.2

Biblioteca experimental para demonstração.
Documentation
use anyhow::{Ok, Result};
use crate::generator::Generator;
use crate::config::ConfigClient;
use std::borrow::Cow;

pub struct GeneratorBuilder<'a>{
    host: Option<Cow<'a, str>>,
    user: Option<Cow<'a, str>>,
    password: Option<Cow<'a, str>>,
}

impl <'a> GeneratorBuilder<'a> {
    pub fn new() -> Self{
        Self {
            host: None,
            user: None,
            password: None,
        }
    }
    pub fn host(mut self, host: impl Into<Cow<'a, str>>)-> Self{
        self.host= Some(host.into());
        self
    }
    pub fn user(mut self, user:impl Into<Cow<'a, str>>)-> Self{
        self.user= Some(user.into());
        self
    }
    pub fn password(mut self, pasword:impl Into<Cow<'a, str>>)-> Self{
        self.password= Some(pasword.into());
        self
    }

    pub async fn create(self)->Result<Generator>{
        let cfg = ConfigClient{
            host: self.host.expect("host obrigatorio"),
            user: self.user.expect("usuario obrigatorio"),
            password: self.password.expect("senha obrigatoria"),
        };
        let client = Generator::new(&cfg).await?;
        let root =client.get_schema().await?;
        let code = client.code_generator(&root);
        std::fs::write("src/banco_gerado.rs", code)?;
        Ok(client)
    }
}