simplify retrieval in find_by_host()

we can use "first()" instead of limit(1).load().etc…
since on a UNIQUE field, we only expect 1 result.

first() returns QueryResult, which is Result<T, diesel::Error>, so we
need to implement a converter for that error type.

This commit addresses @fdb-hiroshima's review.
This commit is contained in:
Igor Galić
2019-05-28 11:14:41 +02:00
committed by Igor Galić
parent 1c34ac38f7
commit 8e6b1ab86e
2 changed files with 10 additions and 8 deletions
+6
View File
@@ -14,6 +14,12 @@ impl From<Error> for ErrorPage {
}
}
impl From<diesel::result::Error> for ErrorPage {
fn from(err: diesel::result::Error) -> ErrorPage {
ErrorPage(plume_models::Error::Db(err))
}
}
impl<'r> Responder<'r> for ErrorPage {
fn respond_to(self, req: &Request) -> response::Result<'r> {
let rockets = req.guard::<PlumeRocket>().unwrap();