Fix the SQlite build

This commit is contained in:
Bat
2018-09-27 22:06:40 +01:00
committed by Igor Galić
parent 535c68b423
commit 743620eb6a
20 changed files with 142 additions and 114 deletions
+6 -5
View File
@@ -1,16 +1,17 @@
use diesel::{
pg::PgConnection,
r2d2::{ConnectionManager, Pool, PooledConnection}
};
use rocket::{Request, State, Outcome, http::Status, request::{self, FromRequest}};
use std::ops::Deref;
pub type PgPool = Pool<ConnectionManager<PgConnection>>;
use Connection;
pub type DbPool = Pool<ConnectionManager<Connection>>;
// From rocket documentation
// Connection request guard type: a wrapper around an r2d2 pooled connection.
pub struct DbConn(pub PooledConnection<ConnectionManager<PgConnection>>);
pub struct DbConn(pub PooledConnection<ConnectionManager<Connection>>);
/// Attempts to retrieve a single connection from the managed database pool. If
/// no pool is currently managed, fails with an `InternalServerError` status. If
@@ -19,7 +20,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for DbConn {
type Error = ();
fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
let pool = request.guard::<State<PgPool>>()?;
let pool = request.guard::<State<DbPool>>()?;
match pool.get() {
Ok(conn) => Outcome::Success(DbConn(conn)),
Err(_) => Outcome::Failure((Status::ServiceUnavailable, ()))
@@ -29,7 +30,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for DbConn {
// For the convenience of using an &DbConn as an &Connection.
impl Deref for DbConn {
type Target = PgConnection;
type Target = Connection;
fn deref(&self) -> &Self::Target {
&self.0