summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-01-11 09:48:43 +0100
committerMatthias Beyer <matthias.beyer@atos.net>2021-01-14 13:29:40 +0100
commit7c40da3f5e15d52183500e1b48aab79415ecea7a (patch)
tree4a8be40a045f7acaa86f4834c226223da7935e3f
parentb6a52fd28003ed3ce251a3647e837ca11b9d1222 (diff)
Add --with-pkg flag for "db submits" command
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r--src/cli.rs8
-rw-r--r--src/commands/db.rs26
2 files changed, 25 insertions, 9 deletions
diff --git a/src/cli.rs b/src/cli.rs
index c58ba1a..a202b29 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -155,6 +155,14 @@ pub fn cli<'a>() -> App<'a> {
.takes_value(false)
.about("Format output as CSV")
)
+ .arg(Arg::new("with_pkg")
+ .required(false)
+ .multiple(false)
+ .long("with-pkg")
+ .takes_value(true)
+ .value_name("PKG")
+ .about("Only list submits that contained package PKG")
+ )
)
.subcommand(App::new("jobs")
diff --git a/src/commands/db.rs b/src/commands/db.rs
index 38e1de5..9f438c9 100644
--- a/src/commands/db.rs
+++ b/src/commands/db.rs
@@ -219,18 +219,26 @@ fn images(conn_cfg: DbConnectionConfig, matches: &ArgMatches) -> Result<()> {
}
fn submits(conn_cfg: DbConnectionConfig, matches: &ArgMatches) -> Result<()> {
- use crate::schema::submits::dsl;
-
let csv = matches.is_present("csv");
let hdrs = mk_header(vec!["id", "time", "uuid"]);
let conn = crate::db::establish_connection(conn_cfg)?;
- let data = dsl::submits
- .load::<models::Submit>(&conn)?
- .into_iter()
- .map(|submit| {
- vec![format!("{}", submit.id), submit.submit_time.to_string(), submit.uuid.to_string()]
- })
- .collect::<Vec<_>>();
+
+ let data = if let Some(pkgname) = matches.value_of("with_pkg").map(String::from) {
+ schema::packages::table
+ .filter(schema::packages::name.eq(pkgname))
+ .inner_join(schema::jobs::table)
+ .inner_join(schema::submits::table)
+ .select(schema::submits::all_columns)
+ .load::<models::Submit>(&conn)?
+ } else {
+ schema::submits::table
+ .load::<models::Submit>(&conn)?
+ }
+ .into_iter()
+ .map(|submit| {
+ vec![format!("{}", submit.id), submit.submit_time.to_string(), submit.uuid.to_string()]
+ })
+ .collect::<Vec<_>>();
if data.is_empty() {
info!("No submits in database");