pub fn new(config: &Config) -> Self {
        match config.connection.type_ {
            ConnectionType::Postgres => {
                let connection_info = config.connection.url.clone();
                let mut client = Client::connect(&connection_info, NoTls)
                    .expect("failed to connect to database");

                if let Err(e) = client.simple_query("SELECT 1") {
                    error!("Failed to connect to database: {}", e);
                } else {
                    info!("Connected to database: {}", connection_info);
                }

                let conn_config = connection_info.parse::<ConnConfig>().unwrap();

                DbConnection {
                    connection_info,
                    client,
                    conn_config,
                }
            }
        }
    }
/// A convenience function which store the connection string into `connection_info` and then connects to the database.
///
/// Refer to <https://rust-lang-nursery.github.io/rust-cookbook/database/postgres.html>
/// for more information.
///
/// ```rust
/// use grant::{config::Config, connection::DbConnection};
/// use std::str::FromStr;
///
/// let config = Config::from_str(
///     r#"
///       connection:
///         type: postgres
///         url: "postgresql://postgres:postgres@localhost:5432/postgres"
///       roles: []
///       users: []
///     "#,
///    )
///    .unwrap();
///    let mut db = DbConnection::new(&config);
///    db.query("SELECT 1", &[]).unwrap();
/// ```
A convenience function which store the connection string into `connection_info` and then connects to the database.
Refer to
for more information.




A convenience function which store the connection string into ` connection_info ` and then connects to the database . Refer to for more information .
pub fn new(config: &Config) -> Self {
        match config.connection.type_ {
            ConnectionType::Postgres => {
                let connection_info = config.connection.url.clone();
                let mut client = Client::connect(&connection_info, NoTls)
                    .expect("failed to connect to database");
                if let Err(e) = client.simple_query("SELECT 1") {
                    error!("Failed to connect to database: {}", e);
                } else {
                    info!("Connected to database: {}", connection_info);
                }
                let conn_config = connection_info.parse::<ConnConfig>().unwrap();
                DbConnection {
                    connection_info,
                    client,
                    conn_config,
                }
            }
        }
    }
pub fn new ( config : & Config ) -> Self { match config . connection . type_ { ConnectionType :: Postgres => { let connection_info = config . connection . url . clone ( ) ; let mut client = Client :: connect ( & connection_info , NoTls ) . expect ( " " ) ; if let Err ( e ) = client . simple_query ( " " ) { error ! ( " " e ) ; } else { info ! ( " " connection_info ) ; } let conn_config = connection_info . parse :: < ConnConfig > ( ) . unwrap ( ) ; DbConnection { connection_info , client , conn_config , } } } }
A convenience function which store the connection string into `connection_info` and then connects to the database.
A convenience function which store the connection string into ` connection_info ` and then connects to the database .
config
&Config
config
&Config