use sled::transaction::Transactional; #[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] pub struct Book { title: String, page_count: u32, description: Option, } impl house::query::Queryable for Book { fn query_terms(&self) -> Vec { vec![ house::query::Term { field: "title", value: self.title.as_bytes() }, ] } } fn main() { env_logger::init(); let db = sled::Config::new().temporary(true).open().unwrap(); let store: house::Store = house::StoreBuilder::default() .with_db(db.clone()) .with_tree_name("books".as_bytes()) .finish() .unwrap(); let book = Book { title: "The Great Gatsby".into(), page_count: 200, description: Some("About a man and some other stuff".into()), }; println!("{:?}", &book); let id = store.create(&book).unwrap(); println!("{:?}", store.find(id).unwrap()); let mut book = house::Object { id, inner: book }; book.title = "The Greatest".into(); store.update(&book).unwrap(); let found_book = store .filter(house::query::StrEquals("title", "The Greatest")) .unwrap() .first() .unwrap() .unwrap(); println!("{:?}", &found_book); let new_book = store.new(Book { title: "The Greatest".into(), page_count: 600, description: Some("Other stuff".into()), }).unwrap(); store.delete_multi(&[found_book.id]).unwrap(); store.transaction(|store| { if let None = store .filter(house::query::StrEquals("title", "The Greatest")) .unwrap() .first() .unwrap() { store.update(&new_book).unwrap(); } Ok(()) }).unwrap(); let books = store.all().unwrap(); dbg!(books); // let found_books = store // .filter(house::query::StrEquals("title", "The Greatest")) // .unwrap() // .first() // .unwrap(); // println!("{:?}", &found_books); }