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
56
57
58
59
60
61
62
use serde::{Deserialize, Serialize};

/// Stores information used to connect to a database. The password is usually encrypted.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ConnectionParams {
  server: String,
  port: Option<i32>,
  database: String,
  user: String,
  password: Option<String>,
  tls: bool
}

impl ConnectionParams {
  pub fn new(server: String, port: Option<i32>, database: String, user: String, password: Option<String>, tls: bool) -> ConnectionParams {
    ConnectionParams {
      server,
      port,
      database,
      user,
      password,
      tls
    }
  }

  pub fn server(&self) -> &String {
    &self.server
  }

  pub fn port(&self) -> &Option<i32> {
    &self.port
  }

  pub fn database(&self) -> &String {
    &self.database
  }

  pub fn user(&self) -> &String {
    &self.user
  }

  pub fn password(&self) -> &Option<String> {
    &self.password
  }

  pub fn tls(&self) -> bool {
    self.tls
  }
}

impl Default for ConnectionParams {
  fn default() -> ConnectionParams {
    ConnectionParams {
      server: "localhost".into(),
      port: None,
      database: "postgres".into(),
      user: "postgres".into(),
      password: None,
      tls: false
    }
  }
}