```rust use semilattice_database::*;
let dir = "./sl-test/";
if std::path::Path::new(dir).exists() { std::fs::removedirall(dir).unwrap(); std::fs::createdirall(dir).unwrap(); } else { std::fs::createdirall(dir).unwrap(); } let mut database = Database::new(dir).unwrap();
if let (Ok(collectionpersonid), Ok(collectionhistoryid)) = ( database.collectionidorcreate("person"), database.collectionidorcreate("history"), ) { if let Some(collectionperson) = database.collectionmut(collectionpersonid) { if let Ok(row) = collectionperson.update(&Operation::New { activity: Activity::Active, termbegin: Term::Default, termend: Term::Default, fields: vec![ KeyValue::new("name", "Joe"), KeyValue::new("birthday", "1972-08-02"), ], }) { let depend = CollectionRow::new(collectionpersonid, row); let mut pends = vec![]; if let Some(collectionhistory) = database.collectionmut(collectionhistoryid) { if let Ok(historyrow) = collectionhistory.update(&Operation::New { activity: Activity::Active, termbegin: Term::Default, termend: Term::Default, fields: vec![ KeyValue::new("date", "1972-08-02"), KeyValue::new("event", "Birth"), ], }) { pends.push(( "history".toowned(), CollectionRow::new(collectionhistoryid, historyrow), )); } if let Ok(historyrow) = collectionhistory.update(&Operation::New { activity: Activity::Active, termbegin: Term::Default, termend: Term::Default, fields: vec![ KeyValue::new("date", "1999-12-31"), KeyValue::new("event", "Mariage"), ], }) { pends.push(( "history".toowned(), CollectionRow::new(collectionhistoryid, historyrow), )); } } database.registerrelations(&depend, pends).unwrap(); } } if let (Some(person), Some(history)) = ( database.collection(collectionpersonid), database.collection(collectionhistoryid), ) { let search = database.search(person); if let Ok(result) = database.result(search, &vec![]) { for row in result { println!( "{},{}", std::str::fromutf8(person.fieldbytes(row, "name")).unwrap(), std::str::fromutf8(person.fieldbytes(row, "birthday")).unwrap() ); let search = database .search(history) .search(Condition::Depend( Some("history".toowned()), CollectionRow::new(collectionpersonid, row), )); for h in database.result(search, &vec![]).unwrap() { println!( " {} : {}", std::str::fromutf8(history.fieldbytes(h, "date")).unwrap(), std::str::fromutf8(history.field_bytes(h, "event")).unwrap() ); } } } } } ```