oiseau 0.3.0

Super simple SQL helper
Documentation
use serde::{Deserialize, Serialize};

/// Configuration for connecting to the database.
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct DatabaseConfig {
    pub name: String,
    #[cfg(any(feature = "postgres", feature = "both"))]
    #[serde(default)]
    pub url: String,
    #[cfg(any(feature = "postgres", feature = "both"))]
    #[serde(default)]
    pub user: String,
    #[cfg(any(feature = "postgres", feature = "both"))]
    #[serde(default)]
    pub password: String,
}

impl Default for DatabaseConfig {
    fn default() -> Self {
        Self {
            #[cfg(any(feature = "postgres", feature = "both"))]
            name: "postgres".to_string(),
            #[cfg(feature = "sqlite")]
            name: "sqlite.db".to_string(),
            #[cfg(any(feature = "postgres", feature = "both"))]
            url: "localhost:5432".to_string(),
            #[cfg(any(feature = "postgres", feature = "both"))]
            user: "postgres".to_string(),
            #[cfg(any(feature = "postgres", feature = "both"))]
            password: "postgres".to_string(),
        }
    }
}

pub trait Configuration {
    fn db_config(&self) -> DatabaseConfig;
}