Skip to main content

join/
join.rs

1//! Demonstrates how to combine relations on shared attributes with the `JOIN` operation.
2
3use darwen::{
4    heading,
5    prelude::{Relation, RelationBuilder, ScalarType},
6    tuple,
7};
8
9fn castaways() -> Relation {
10    RelationBuilder::new()
11        .with_heading(heading!(number = ScalarType::Integer, name = ScalarType::String).unwrap())
12        .with_body(vec![
13            tuple!(number = 4, name = "Monica").unwrap(),
14            tuple!(number = 8, name = "Erica").unwrap(),
15            tuple!(number = 15, name = "Rita").unwrap(),
16            tuple!(number = 16, name = "Tina").unwrap(),
17        ])
18        .build()
19        .unwrap()
20}
21
22fn hatch() -> Relation {
23    RelationBuilder::new()
24        .with_heading(heading!(number = ScalarType::Integer, element = ScalarType::String).unwrap())
25        .with_body(vec![
26            tuple!(number = 8, element = "Oxygen").unwrap(),
27            tuple!(number = 15, element = "Phosphorus").unwrap(),
28            tuple!(number = 23, element = "Vanadium").unwrap(),
29        ])
30        .build()
31        .unwrap()
32}
33
34fn main() {
35    let castaways = castaways();
36    let hatch = hatch();
37
38    println!("{}", castaways.join(&hatch).unwrap());
39}