[][src]Struct codd::Database

pub struct Database { /* fields omitted */ }

Stores data in relation instances and implements incremental view maintenance over them.

Example:

use codd::{Database, expression::Select};

// create a new database:
let mut db = Database::new();

// add a new relation "numbers" with tuples of type `u32` to `db`:
let numbers = db.add_relation::<u32>("numbers").unwrap();

// create a view for odd numbers in `numbers`:
let odds = db.store_view(Select::new(numbers.clone(), |i| i % 2 == 1)).unwrap();

// insert some items in `numbers`:
db.insert(&numbers, vec![4, 8, 15, 16, 23, 42].into()).unwrap();

// query `db` for `numbers` and `odds`:
let numbers_data = db.evaluate(&numbers).unwrap();
let odds_data = db.evaluate(&odds).unwrap();

assert_eq!(vec![4, 8, 15, 16, 23, 42], numbers_data.into_tuples());
assert_eq!(vec![15, 23], odds_data.into_tuples());

// go nuts:
db.insert(&numbers, vec![8, 888, 23, 1001, 8008, 101].into()).unwrap();

// query `db` again:
let numbers_data = db.evaluate(&numbers).unwrap();
let odds_data = db.evaluate(&odds).unwrap();

assert_eq!(vec![4, 8, 15, 16, 23, 42, 101, 888, 1001, 8008], numbers_data.into_tuples());
assert_eq!(vec![15, 23, 101, 1001], odds_data.into_tuples());

Implementations

impl Database[src]

pub fn new() -> Self[src]

Creates a new empty database.

pub fn evaluate<T, E>(&self, expression: &E) -> Result<Tuples<T>, Error> where
    T: Tuple,
    E: ExpressionExt<T>, 
[src]

Evaluates expression in the database and returns the result in a Tuples object.

pub fn add_relation<T>(&mut self, name: &str) -> Result<Relation<T>, Error> where
    T: Tuple + 'static, 
[src]

Adds a new relation instance identified by name to the database and returns a Relation object that can be used to access the instance.

pub fn insert<T>(
    &self,
    relation: &Relation<T>,
    tuples: Tuples<T>
) -> Result<(), Error> where
    T: Tuple + 'static, 
[src]

Inserts tuples in the Instance corresponding to relation.

pub fn store_view<T, E, I>(
    &mut self,
    expression: I
) -> Result<View<T, E>, Error> where
    T: Tuple + 'static,
    E: ExpressionExt<T> + 'static,
    I: IntoExpression<T, E>, 
[src]

Stores a new view over expression and returns a View objeect that can be evaluated as a view.

Trait Implementations

impl Clone for Database[src]

impl Default for Database[src]

Auto Trait Implementations

impl !RefUnwindSafe for Database

impl !Send for Database

impl !Sync for Database

impl Unpin for Database

impl !UnwindSafe for Database

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.