solidb_client/client/
builder.rs1use super::DriverError;
2use super::SoliDBClient;
3
4pub struct SoliDBClientBuilder {
5 addr: String,
6 auth: Option<(String, String, String)>,
7 timeout_ms: Option<u64>,
8}
9
10impl SoliDBClientBuilder {
11 pub fn new(addr: &str) -> Self {
12 Self {
13 addr: addr.to_string(),
14 auth: None,
15 timeout_ms: None,
16 }
17 }
18
19 pub fn auth(mut self, database: &str, username: &str, password: &str) -> Self {
20 self.auth = Some((
21 database.to_string(),
22 username.to_string(),
23 password.to_string(),
24 ));
25 self
26 }
27
28 pub fn timeout_ms(mut self, ms: u64) -> Self {
29 self.timeout_ms = Some(ms);
30 self
31 }
32
33 pub async fn build(self) -> Result<SoliDBClient, DriverError> {
34 let mut client = SoliDBClient::connect(&self.addr).await?;
35
36 if let Some((database, username, password)) = self.auth {
37 client.auth(&database, &username, &password).await?;
38 }
39
40 Ok(client)
41 }
42}