aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src/lib.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-05-15 14:45:42 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-05-15 14:45:42 -0700
commitfe77445bd16db003e03b5c44fa02c65b78e6fa02 (patch)
tree7411bbbaecf4c086c97746fa1845dc0169b33438 /rust/src/lib.rs
parent85d469196ff17a3aee7a950ae57d4797938e8f42 (diff)
downloadfatcat-fe77445bd16db003e03b5c44fa02c65b78e6fa02.tar.gz
fatcat-fe77445bd16db003e03b5c44fa02c65b78e6fa02.zip
working db_pool and response
Diffstat (limited to 'rust/src/lib.rs')
-rw-r--r--rust/src/lib.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index ae39224f..c1336561 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -1,7 +1,7 @@
#[macro_use]
extern crate fatcat_api;
extern crate chrono;
-extern crate diesel;
+#[macro_use] extern crate diesel;
extern crate iron_diesel_middleware;
extern crate dotenv;
extern crate futures;
@@ -9,7 +9,10 @@ extern crate futures;
extern crate swagger;
#[macro_use] extern crate error_chain;
extern crate iron;
+extern crate r2d2;
+extern crate r2d2_diesel;
+pub mod database_schema;
pub mod api_server;
mod errors {
@@ -21,9 +24,11 @@ use diesel::pg::PgConnection;
use diesel::prelude::*;
use dotenv::dotenv;
use std::env;
-use hyper::header::Headers;
use iron::{Request, Response};
use iron::middleware::AfterMiddleware;
+use r2d2_diesel::ConnectionManager;
+
+pub type ConnectionPool = r2d2::Pool<r2d2_diesel::ConnectionManager<diesel::pg::PgConnection>>;
pub fn establish_connection() -> PgConnection {
dotenv().ok();
@@ -34,7 +39,13 @@ pub fn establish_connection() -> PgConnection {
/// Instantiate a new server.
pub fn server() -> Result<api_server::Server> {
- Ok(api_server::Server {})
+ dotenv().ok();
+ let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
+ let manager = ConnectionManager::<PgConnection>::new(database_url);
+ let pool = r2d2::Pool::builder().build(manager).expect("Failed to create database pool.");
+ Ok(api_server::Server {
+ db_pool: pool,
+ })
}
/// HTTP header middleware