From 9a303b182a32d2908caaaf5d24c7bc1ff3831505 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 15 May 2018 11:04:23 -0700 Subject: broken diesel+iron integration --- rust/src/api_server.rs | 10 ++++++++++ rust/src/bin/fatcat-iron.rs | 6 ++++++ rust/src/lib.rs | 2 ++ 3 files changed, 18 insertions(+) (limited to 'rust/src') diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index 59836e31..cac222e6 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -7,6 +7,11 @@ use futures::{self, Future}; use std::collections::HashMap; +use self::models::*; +use diesel; +use diesel::prelude::*; +use iron_diesel_middleware::DieselPooledConnection; + use swagger; use fatcat_api::models; @@ -28,11 +33,16 @@ impl Api for Server { context: &Context, ) -> Box + Send> { let context = context.clone(); + let con: DieselPooledConnection = req.db_conn(); println!( "container_id_get(\"{}\") - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("")).clone() ); + println!( + "container count: {}", + containers.count().load(&con).expect("DB Error"), + ); Box::new(futures::failed("Generic failure".into())) } diff --git a/rust/src/bin/fatcat-iron.rs b/rust/src/bin/fatcat-iron.rs index 0bed0fa2..1f443e8e 100644 --- a/rust/src/bin/fatcat-iron.rs +++ b/rust/src/bin/fatcat-iron.rs @@ -37,6 +37,11 @@ fn main() { let logger = Logger::root(drain, o!()); let formatter = DefaultLogFormatter; + dotenv().ok(); + let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set"); + + let diesel_middleware: DieselMiddleware = DieselMiddleware::new(database_url).unwrap(); + let server = fatcat::server().unwrap(); let router = fatcat_api::router(server); @@ -49,6 +54,7 @@ fn main() { chain.link_before(AllowAllMiddleware::new("cosmo")); chain.link_after(fatcat::XClacksOverheadMiddleware); + chain.link_before(diesel_middleware); if matches.is_present("https") { unimplemented!() diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 55040f0c..fecea06e 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -2,6 +2,7 @@ extern crate fatcat_api; extern crate chrono; extern crate diesel; +extern crate iron_diesel_middleware; extern crate dotenv; extern crate futures; #[macro_use] extern crate hyper; @@ -23,6 +24,7 @@ use std::env; use hyper::header::Headers; use iron::{Request, Response}; use iron::middleware::AfterMiddleware; +use iron_diesel_middleware::{DieselMiddleware, DieselPooledConnection, DieselReqExt}; pub fn establish_connection() -> PgConnection { dotenv().ok(); -- cgit v1.2.3