dbui-core 0.0.64

Core classes used by dbui in the app and WASM
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum DatabaseEngine {
  Postgres
}

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

impl ConnectionParams {
  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 {
      engine: DatabaseEngine::Postgres,
      server: "localhost".into(),
      port: None,
      database: "postgres".into(),
      user: "postgres".into(),
      password: None,
      tls: false
    }
  }
}