summaryrefslogtreecommitdiffstats
path: root/rust/src/lib.rs
blob: 679b9ed320b3b0ad44116e4350d8faddf1b0412a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

#[macro_use]
extern crate diesel;
extern crate dotenv;

use diesel::prelude::*;
use diesel::pg::PgConnection;
use dotenv::dotenv;
use std::env;

pub fn establish_connection() -> PgConnection {
    dotenv().ok();

    let database_url = env::var("DATABASE_URL")
        .expect("DATABASE_URL must be set");
    PgConnection::establish(&database_url)
        .expect(&format!("Error connecting to {}", database_url))
}