diff options
Diffstat (limited to 'src/commands/db.rs')
-rw-r--r-- | src/commands/db.rs | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/commands/db.rs b/src/commands/db.rs index 5b9a85a..2e86954 100644 --- a/src/commands/db.rs +++ b/src/commands/db.rs @@ -14,6 +14,7 @@ use std::io::Write; use std::path::PathBuf; use std::process::Command; use std::str::FromStr; +use std::convert::TryFrom; use anyhow::Context; use anyhow::Error; @@ -32,9 +33,11 @@ use log::info; use log::trace; use crate::config::Configuration; -use crate::db::models; use crate::db::DbConnectionConfig; +use crate::db::models; use crate::log::JobResult; +use crate::package::PackageVersion; +use crate::package::PackageVersionConstraint; use crate::package::Script; use crate::schema; @@ -691,7 +694,7 @@ fn releases(conn_cfg: DbConnectionConfig<'_>, config: &Configuration, matches: & let csv = matches.is_present("csv"); let conn = conn_cfg.establish_connection()?; let header = crate::commands::util::mk_header(["Package", "Version", "Date", "Path"].to_vec()); - let data = schema::jobs::table + let mut query = schema::jobs::table .inner_join(schema::packages::table) .inner_join(schema::artifacts::table) .inner_join(schema::releases::table @@ -701,6 +704,28 @@ fn releases(conn_cfg: DbConnectionConfig<'_>, config: &Configuration, matches: & .order_by(schema::packages::dsl::name.asc()) .then_order_by(schema::packages::dsl::version.asc()) .then_order_by(schema::releases::release_date.asc()) + .into_boxed(); + + if let Some(date) = crate::commands::util::get_date_filter("older_than", matches)? { + query = query.filter(schema::releases::release_date.lt(date)); + } + + if let Some(date) = crate::commands::util::get_date_filter("newer_than", matches)? { + query = query.filter(schema::releases::release_date.gt(date)); + } + + let package_name_regex_filter = matches.value_of("package_name_regex") + .map(crate::commands::util::mk_package_name_regex) + .transpose() + .context("Constructing package name regex")?; + + let package_version_filter = matches.value_of("package_version_constraint") + .map(PackageVersionConstraint::try_from) + .transpose() + .context("Parsing package version constraint") + .context("A valid package version constraint looks like this: '=1.0.0'")?; + + let data = query .select({ let art = schema::artifacts::all_columns; let pac = schema::packages::all_columns; @@ -710,8 +735,18 @@ fn releases(conn_cfg: DbConnectionConfig<'_>, config: &Configuration, matches: & }) .load::<(models::Artifact, models::Package, models::Release, models::ReleaseStore)>(&conn)? .into_iter() + .filter(|(_, package, _, _)| { + package_name_regex_filter.as_ref() + .map(|regex| regex.captures(&package.name).is_some()) + .unwrap_or(true) + }) + .filter(|(_, package, _, _)| { + package_version_filter.as_ref() + .map(|verf| verf.matches(&PackageVersion::from(package.version.clone()))) + .unwrap_or(true) + }) .filter_map(|(art, pack, rel, rstore)| { - let p = config.releases_directory().join(rstore.store_name).join(&art.path); + let p = config.releases_directory().join(rstore.store_name).join(&art.path); if p.is_file() { Some(vec![ |