#graph-database #key-value-database #directed-graph #library #graph-node #semilattice

semilattice-database

数据通过有向图连接,每个节点都有一个任意定义的关键值。数据库不是一个树

61 个版本 (34 个破坏性更新)

0.110.0 2024年2月13日
0.108.0 2024年2月6日
0.98.0 2023年12月26日
0.93.0 2023年11月29日
0.31.0 2022年11月23日

#716数据库接口

Download history 6/week @ 2024-05-13 20/week @ 2024-05-20 30/week @ 2024-05-27 23/week @ 2024-06-03 23/week @ 2024-06-10 14/week @ 2024-06-17 20/week @ 2024-06-24 55/week @ 2024-07-01 7/week @ 2024-07-08 33/week @ 2024-07-15 11/week @ 2024-07-22 22/week @ 2024-07-29 20/week @ 2024-08-05

每月86 次下载
8 个Crates中(2 个直接) 使用

MIT/Apache

38KB
928

semilattice-database

示例

use std::sync::Arc;

use semilattice_database::*;
use versatile_data::FieldName;

let dir = "./sl-test/";

if std::path::Path::new(dir).exists() {
    std::fs::remove_dir_all(dir).unwrap();
    std::fs::create_dir_all(dir).unwrap();
} else {
    std::fs::create_dir_all(dir).unwrap();
}
futures::executor::block_on(async {
    let mut database = Database::new(dir.into(), None, 10);

    let collection_person_id = database.collection_id_or_create("person");
    let collection_history_id = database.collection_id_or_create("history");
    let collection_person = database.collection_mut(collection_person_id).unwrap();

    let id_name = FieldName::new("name".into());
    let id_birthday = FieldName::new("birthday".into());

    let row = collection_person
        .insert(
            Activity::Active,
            Term::Default,
            Term::Default,
            [
                (id_name.clone(), "Joe".into()),
                (id_birthday.clone(), "1972-08-02".into()),
            ]
            .into(),
        )
        .await;

    let depend = CollectionRow::new(collection_person_id, row);
    let mut pends = vec![];

    let collection_history = database.collection_mut(collection_history_id).unwrap();

    let id_date = FieldName::new("date".into());
    let id_event = FieldName::new("event".into());

    let history_row = collection_history
        .insert(
            Activity::Active,
            Term::Default,
            Term::Default,
            [
                (id_date.clone(), "1972-08-02".into()),
                (id_event.clone(), "Birth".into()),
            ]
            .into(),
        )
        .await;
    pends.push((
        Arc::new("history".to_owned()),
        CollectionRow::new(collection_history_id, history_row),
    ));
    let history_row = collection_history
        .insert(
            Activity::Active,
            Term::Default,
            Term::Default,
            [
                (id_date.clone(), "1999-12-31".into()),
                (id_event.clone(), "Mariage".into()),
            ]
            .into(),
        )
        .await;
    pends.push((
        Arc::new("history".to_owned()),
        CollectionRow::new(collection_history_id, history_row),
    ));
    database.register_relations(&depend, pends).await;

    if let (Some(person), Some(history)) = (
        database.collection(collection_person_id),
        database.collection(collection_history_id),
    ) {
        let result = database
            .search(collection_person_id)
            .result(&database)
            .await;
        for row in result.rows().into_iter() {
            println!(
                "{},{}",
                std::str::from_utf8(person.field_bytes(*row, &id_name)).unwrap(),
                std::str::from_utf8(person.field_bytes(*row, &id_birthday)).unwrap()
            );
            for h in database
                .search(collection_history_id)
                .search(Condition::Depend(
                    Some(Arc::new("history".into())),
                    CollectionRow::new(collection_person_id, *row),
                ))
                .result(&database)
                .await
                .rows()
                .into_iter()
            {
                println!(
                    " {} : {}",
                    std::str::from_utf8(history.field_bytes(*h, &id_date)).unwrap(),
                    std::str::from_utf8(history.field_bytes(*h, &id_event)).unwrap()
                );
            }
        }
    }
});

依赖

~4–10MB
~91K SLoC