summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-04-22 08:27:58 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-04-22 08:38:40 +0200
commitbee61d29d526d227b5ae1398c508440736a2b927 (patch)
tree298b811c16540d93df494ebaf5f401b4ee1ae6b0
parentc52c4595f6aaab514e3ceaa72b8bf27456f4947f (diff)
Add helper functions to load Image from DB
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r--src/db/models/image.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/db/models/image.rs b/src/db/models/image.rs
index 2570dc2..600edd6 100644
--- a/src/db/models/image.rs
+++ b/src/db/models/image.rs
@@ -48,4 +48,16 @@ impl Image {
.first::<Image>(database_connection)
.map_err(Error::from)
}
+
+ pub fn fetch_for_job(database_connection: &PgConnection, j: &crate::db::models::Job) -> Result<Option<Image>> {
+ Self::fetch_by_id(database_connection, j.image_id)
+ }
+
+ pub fn fetch_by_id(database_connection: &PgConnection, iid: i32) -> Result<Option<Image>> {
+ match dsl::images.filter(id.eq(iid)).first::<Image>(database_connection) {
+ Err(diesel::result::Error::NotFound) => Ok(None),
+ Err(e) => Err(Error::from(e)),
+ Ok(i) => Ok(Some(i)),
+ }
+ }
}