semilattice-database

Example

```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, None);

let collectionpersonid=database.collectionidorcreate("person"); let collectionhistoryid=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) { let 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, history_row), ));

        let history_row = collection_history.update(&Operation::New {
            activity: Activity::Active,
            term_begin: Term::Default,
            term_end: Term::Default,
            fields: vec![
                KeyValue::new("date", "1999-12-31"),
                KeyValue::new("event", "Mariage"),
            ],
        });
        pends.push((
            "history".to_owned(),
            CollectionRow::new(collection_history_id, history_row),
        ));
    }
    database.register_relations(&depend, pends).unwrap();
}

} if let (Some(person), Some(history)) = ( database.collection(collectionpersonid), database.collection(collectionhistoryid), ) { let search = database.search(person); if let Ok(result) = search.result(&database) { 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() ); } } } }

```