Darwen
Darwen is an in-memory engine for relational algebra inspired by The Third Manifesto of Date, Codd, and Darwen.
This is the final version of the library. Further development is not planned, because the project is educational.
Example
use ;
let users = new
.with_heading
.with_body
.build?;
let adults = users.restrict?;
let expected = new
.with_heading
.with_body
.build?;
assert_eq!;
# Ok::
Implemented Operations
RESTRICT/SELECTION (σ)
Example - cargo run --example restrict
σ age > 20 (people)
people
| name | age |
|---|---|
| Ann | 19 |
| Bob | 24 |
Output
| name | age |
|---|---|
| Bob | 24 |
PROJECT (π)
Example - cargo run --example project
π name (people)
people
| name | age |
|---|---|
| Ann | 19 |
| Bob | 24 |
Output
| name |
|---|
| Ann |
| Bob |
RENAME (ρ)
Example - cargo run --example rename
ρ person_name/name (people)
people
| name |
|---|
| Ann |
| Bob |
Output
| person_name |
|---|
| Ann |
| Bob |
UNION (⋃)
Example - cargo run --example union
a ⋃ b
a
| value |
|---|
| foo |
| bar |
b
| value |
|---|
| bar |
| baz |
Output
| value |
|---|
| foo |
| bar |
| baz |
DIFFERENCE (−)
Example - cargo run --example difference
a − b
a
| value |
|---|
| foo |
| bar |
| baz |
b
| value |
|---|
| bar |
Output
| value |
|---|
| foo |
| baz |
PRODUCT (×)
Example - cargo run --example product
colors × sizes
colors
| color |
|---|
| red |
| blue |
sizes
| size |
|---|
| S |
| M |
Output
| color | size |
|---|---|
| red | S |
| red | M |
| blue | S |
| blue | M |
JOIN (⋈)
Example - cargo run --example join
users ⋈ cities
users
| id | name |
|---|---|
| 1 | Ann |
| 2 | Bob |
cities
| id | city |
|---|---|
| 1 | Rome |
| 3 | Oslo |
Output
| id | name | city |
|---|---|---|
| 1 | Ann | Rome |
INTERSECT (∩)
Example - cargo run --example intersect
a ∩ b
a
| value |
|---|
| foo |
| bar |
b
| value |
|---|
| bar |
| baz |
Output
| value |
|---|
| bar |
Sources
- The Third Manifesto - the foundational manifesto of relational databases
- TutorialD - a practical implementation of relational algebra
- BNF for TutorialD from RelDB project