New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

environment variable `DATABASE_URL` not defined #1614

Closed
haruhinoshana opened this Issue Apr 5, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@haruhinoshana

haruhinoshana commented Apr 5, 2018

hi good evening im new on using diesel i use it with rocket ... i do try to work diesel on rocket but i got
environment variable DATABASE_URL not defined error

heres my code
#![feature(plugin)]
#![plugin(rocket_codegen)]
#[macro_use]
extern crate rocket;
extern crate diesel;
extern crate dotenv;

use diesel::prelude::*;
use diesel::r2d2::{ConnectionManager, Pool, PooledConnection};
use dotenv::dotenv;
use std::env;

// An alias to the type for a pool of Diesel SQLite connections.
type MysqlPool = Pool<ConnectionManager>;

// The URL to the database, set via the DATABASE_URL environment variable.
static DATABASE_URL: &'static str = env!("DATABASE_URL");

/// Initializes a database pool.
fn init_pool() -> Pool {
let manager = ConnectionManager::::new(DATABASE_URL);
Pool::new(manager).expect("db pool");
}

#[get("/")]
fn index() -> &'static str {
"Hello, world!"
}

fn main() {
rocket::ignite()
.manager(init_pool())
.mount("/", routes![index])
.launch();
}

my rust version 1.27.0-nightly (637ac17c5 2018-04-03)

@weiznich weiznich added the question label Apr 5, 2018

@weiznich

This comment has been minimized.

Contributor

weiznich commented Apr 5, 2018

This error message means that the environment variable DATABASE_URL is not set at compile time. See the documentation of env! for details.

@sgrif sgrif closed this Apr 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment