From d525ea2456b2fc7945752ab75a03a163068eab5a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 17 Sep 2021 08:39:26 +0200 Subject: Add GitHash::with_id() to get GitHash object from DB with specific id Signed-off-by: Matthias Beyer --- src/db/models/githash.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/db') diff --git a/src/db/models/githash.rs b/src/db/models/githash.rs index 2dcb0bb..e9034e8 100644 --- a/src/db/models/githash.rs +++ b/src/db/models/githash.rs @@ -8,6 +8,7 @@ // SPDX-License-Identifier: EPL-2.0 // +use anyhow::Context; use anyhow::Error; use anyhow::Result; use diesel::prelude::*; @@ -44,4 +45,12 @@ impl GitHash { .map_err(Error::from) }) } + + pub fn with_id(database_connection: &PgConnection, git_hash_id: i32) -> Result { + dsl::githashes + .find(git_hash_id) + .first::<_>(database_connection) + .context("Loading GitHash") + .map_err(Error::from) + } } -- cgit v1.2.3