#datalog #analysis #query #engine #node #programs #relation

datafrog

Lightweight Datalog engine intended to be embedded in other Rust programs

4 releases (stable)

2.0.1 Jan 2, 2019
2.0.0 Dec 27, 2018
1.0.0 Dec 5, 2018
0.1.0 May 24, 2018

#297 in Embedded development

Download history 16057/week @ 2024-06-09 15200/week @ 2024-06-16 15333/week @ 2024-06-23 15095/week @ 2024-06-30 15011/week @ 2024-07-07 16079/week @ 2024-07-14 15938/week @ 2024-07-21 15986/week @ 2024-07-28 15300/week @ 2024-08-04 15431/week @ 2024-08-11 14699/week @ 2024-08-18 15145/week @ 2024-08-25 15591/week @ 2024-09-01 14524/week @ 2024-09-08 14678/week @ 2024-09-15 13600/week @ 2024-09-22

60,446 downloads per month
Used in 11 crates (4 directly)

Apache-2.0/MIT

59KB
1K SLoC

datafrog

Datafrog is a lightweight Datalog engine intended to be embedded in other Rust programs.

Datafrog has no runtime, and relies on you to build and repeatedly apply the update rules. It tries to help you do this correctly. As an example, here is how you might write a reachability query using Datafrog (minus the part where we populate the nodes and edges initial relations).

extern crate datafrog;
use datafrog::Iteration;

fn main() {

    // Create a new iteration context, ...
    let mut iteration = Iteration::new();

    // .. some variables, ..
    let nodes_var = iteration.variable::<(u32,u32)>("nodes");
    let edges_var = iteration.variable::<(u32,u32)>("edges");

    // .. load them with some initial values, ..
    nodes_var.insert(nodes.into());
    edges_var.insert(edges.into());

    // .. and then start iterating rules!
    while iteration.changed() {
        // nodes(a,c)  <-  nodes(a,b), edges(b,c)
        nodes_var.from_join(&nodes_var, &edges_var, |_b, &a, &c| (c,a));
    }

    // extract the final results.
    let reachable: Vec<(u32,u32)> = variable.complete();
}

If you'd like to read more about how it works, check out this blog post.

Authorship

Datafrog was initially developed by Frank McSherry and was later transferred to the rust-lang-nursery organization. Thanks Frank!

No runtime deps