diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-11-13 11:16:51 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-11-13 11:17:36 +0100 |
commit | 5f2c600fded421b57ebf44558f8d5dffe8e5580e (patch) | |
tree | d7de9c14515068e525847f346c7039cf9bab8463 /src/commands/db.rs | |
parent | 93952aec4bab58dbc901ed463f66994209be1ad7 (diff) |
Add subcommand: db submits - for listing submits
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/commands/db.rs')
-rw-r--r-- | src/commands/db.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/commands/db.rs b/src/commands/db.rs index ba85446..cc4fe5a 100644 --- a/src/commands/db.rs +++ b/src/commands/db.rs @@ -20,6 +20,7 @@ pub fn db(db_connection_config: DbConnectionConfig, matches: &ArgMatches) -> Res ("artifacts", Some(matches)) => artifacts(db_connection_config, matches), ("envvars", Some(matches)) => envvars(db_connection_config, matches), ("images", Some(matches)) => images(db_connection_config, matches), + ("submits", Some(matches)) => submits(db_connection_config, matches), (other, _) => return Err(anyhow!("Unknown subcommand: {}", other)), } } @@ -181,6 +182,30 @@ fn images(conn_cfg: DbConnectionConfig, matches: &ArgMatches) -> Result<()> { Ok(()) } +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<_>>(); + + if data.is_empty() { + info!("No submits in database"); + } else { + display_data(hdrs, data, csv)?; + } + + Ok(()) +} + + fn mk_header(vec: Vec<&str>) -> Vec<ascii_table::Column> { vec.into_iter() .map(|name| { |