Skip to main content

restrict/
restrict.rs

1//! Demonstrates how to filter a relation with the `RESTRICT` operation.
2
3use darwen::prelude::{Predicate, Relation, RelationBuilder, Scalar, ScalarType};
4use darwen::{heading, tuple, AttributeName, Expression};
5
6fn users() -> Relation {
7    RelationBuilder::new()
8        .with_heading(heading!(name = ScalarType::String, age = ScalarType::Integer).unwrap())
9        .with_body(vec![
10            tuple!(name = "Monica", age = 18).unwrap(),
11            tuple!(name = "Erica", age = 19).unwrap(),
12            tuple!(name = "Rita", age = 20).unwrap(),
13            tuple!(name = "Tina", age = 21).unwrap(),
14            tuple!(name = "Sandra", age = 22).unwrap(),
15            tuple!(name = "Mary", age = 23).unwrap(),
16            tuple!(name = "Jessica", age = 18).unwrap(),
17        ])
18        .build()
19        .unwrap()
20}
21
22fn main() {
23    let users = users();
24
25    println!(
26        "{}",
27        users
28            .restrict(&Predicate::gt(
29                Expression::Attribute(AttributeName::from("age")),
30                Expression::Const(Scalar::Integer(20))
31            ))
32            .unwrap()
33    )
34}