use nebari::{
tree::{Root, Versioned},
Error,
};
fn main() -> Result<(), Error> {
let roots = nebari::Config::default_for("simple-database.nebari").open()?;
let tree_one = roots.tree(Versioned::tree("one"))?;
tree_one.set("hello", "world")?;
let tree_two = roots.tree(Versioned::tree("two"))?;
assert!(tree_two.get("hello".as_bytes())?.is_none());
let transaction = roots.transaction(&[Versioned::tree("one"), Versioned::tree("two")])?;
{
let mut tx_tree_one = transaction.tree::<Versioned>(0).unwrap();
tx_tree_one.set("hello", "everyone")?;
assert_eq!(
tree_one.get("hello".as_bytes())?.as_deref(),
Some("world".as_bytes())
);
let mut tx_tree_two = transaction.tree::<Versioned>(1).unwrap();
tx_tree_two.set("another tree", "another value")?;
}
transaction.commit()?;
assert_eq!(
tree_one.get("hello".as_bytes())?.as_deref(),
Some("everyone".as_bytes())
);
Ok(())
}