Fix index chaining; tests passing

This commit is contained in:
Josh Hansen 2023-09-20 15:02:52 -07:00
parent 68b581ee98
commit 645159f256
3 changed files with 29 additions and 4 deletions

View file

@ -52,7 +52,9 @@ Removed ./people/:state:id/WA/1
+ cargo run --quiet -- del -v ./people:id 3
Removed ./people:id/3
Removed ./people/Janella
Removed ./people/:state:id/FL/3
+ cargo run --quiet -- del -v ./people/:state:id CA 0
Removed ./people:id/0
Removed ./people/Wulfrum
Removed ./people/:state:id/CA/0
+ cargo run --quiet -- get -a -w state=CA -f name ./people/:state:id

View file

@ -9,7 +9,7 @@ use std::path::Path;
use walkdir::WalkDir;
use crate::declare_indices;
use crate::declare_closure_indices;
use crate::parser::xattr::Xattr;
use crate::paths::sub_idx_path;
@ -38,8 +38,14 @@ pub enum IdxErr {
},
}
/// Create a new index of the data in `src`, locating the index in `dest`.
/// The new index uses `keys` as its primary key
/**
* Create a new index of the data in `src`, locating the index in `dest`, or a subdirectory of `src` by default.
*
* The new index uses `keys` as its primary key.
*
* `dest` will have `src` and all _its_ related indices as related indices; and `src` and all its related indices
* will be updated to include `dest` as an alternate index.
*/
pub fn idx(src: &PathBuf, dest: Option<&PathBuf>, keys: &Key, verbose: bool) -> Result<()> {
if keys.is_empty() {
panic!("No keys were provided to index by");
@ -95,7 +101,7 @@ pub fn idx(src: &PathBuf, dest: Option<&PathBuf>, keys: &Key, verbose: bool) ->
init(&dest, &keys, false)?;
declare_indices(src, &dest)
declare_closure_indices(src, &dest)
}
#[cfg(test)]

View file

@ -389,6 +389,23 @@ pub fn declare_indices<P1: AsRef<Path>, P2: AsRef<Path>>(dir1: P1, dir2: P2) ->
index_list_push(dir2, dir1)
}
/// Mark `dir1`, `dir2`, the indices of `dir1`, and the indices of `dir2`
/// all as indices of each other.
pub fn declare_closure_indices<P1: AsRef<Path>, P2: AsRef<Path>>(dir1: P1, dir2: P2) -> Result<()> {
let info1 = table_info(&dir1)?
.ok_or_else(|| IndexListPushErr::TargetTableInfoNotFound(dir1.as_ref().into()))?;
let info2 = table_info(&dir2)?
.ok_or_else(|| IndexListPushErr::TargetTableInfoNotFound(dir2.as_ref().into()))?;
for path1 in info1.indices.values() {
for path2 in info2.indices.values() {
declare_indices(path1, path2)?;
}
}
Ok(())
}
#[cfg(test)]
mod test {
use std::{