use anyhow::{Ok, Result};
use crate::client_sql::ClientSql;
use crate::config::ConfigClient;
use std::borrow::Cow;
pub struct ClientBuilder<'a>{
host: Option<Cow<'a, str>>,
user: Option<Cow<'a, str>>,
password: Option<Cow<'a, str>>,
}
impl <'a> ClientBuilder<'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 connect(self)->Result<ClientSql>{
let cfg = ConfigClient{
host: self.host.expect("host obrigatorio"),
user: self.user.expect("usuario obrigatorio"),
password: self.password.expect("senha obrigatoria"),
};
ClientSql::new(&cfg).await
}
}