pub mod mysql;
pub mod postgres;
pub mod schema_utils;
pub mod traits;
pub use mysql::MySQL;
pub use postgres::PostgreSQL;
pub use traits::*;
#[derive(Debug, Clone)]
pub struct DatabaseConfig {
pub host: String,
pub port: u16,
pub database: String,
pub username: String,
pub password: String,
pub ssl_mode: Option<String>,
}
impl DatabaseConfig {
pub fn new(
host: impl Into<String>,
port: u16,
database: impl Into<String>,
username: impl Into<String>,
password: impl Into<String>,
) -> Self {
Self {
host: host.into(),
port,
database: database.into(),
username: username.into(),
password: password.into(),
ssl_mode: None,
}
}
pub fn postgres(
host: impl Into<String>,
port: u16,
database: impl Into<String>,
username: impl Into<String>,
password: impl Into<String>,
) -> Self {
Self::new(host, port, database, username, password)
}
pub fn mysql(
host: impl Into<String>,
port: u16,
database: impl Into<String>,
username: impl Into<String>,
password: impl Into<String>,
) -> Self {
Self::new(host, port, database, username, password)
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum DatabaseType {
PostgreSQL,
MySQL,
SQLite,
MSSQL,
}
impl DatabaseType {
pub fn default_port(&self) -> u16 {
match self {
DatabaseType::PostgreSQL => 5432,
DatabaseType::MySQL => 3306,
DatabaseType::SQLite => 0, DatabaseType::MSSQL => 1433,
}
}
pub fn display_name(&self) -> &'static str {
match self {
DatabaseType::PostgreSQL => "PostgreSQL",
DatabaseType::MySQL => "MySQL",
DatabaseType::SQLite => "SQLite",
DatabaseType::MSSQL => "Microsoft SQL Server",
}
}
}