Database

Struct Database 

Source
pub struct Database { /* private fields */ }

Implementations§

Source§

impl Database

Source

pub fn new() -> Self

Examples found in repository?
examples/database.rs (line 17)
14fn main() {
15    // Construct an empty database
16    // and add some facts about the world.
17    let mut db = Database::new();
18    db_facts! {
19        db {
20            food("Beef");
21            food("Fish");
22            food("Hamburger");
23            food("Pizza");
24            food("Salad");
25            food("Stone soup");
26            food("Veggies");
27
28            drink("Beer");
29            drink("Red wine");
30            drink("Water");
31            drink("White wine");
32
33            goes_well_with("Beef", "Beer");
34            goes_well_with("Beef", "Red wine");
35            goes_well_with("Fish", "White wine");
36            goes_well_with("Hamburger", "Beer");
37            goes_well_with("Pizza", "Red wine");
38            goes_well_with("Stone soup", "Water");
39            goes_well_with("Veggies", "White wine");
40
41            is_vegetarian("Beef", false);
42            is_vegetarian("Fish", "some say so");
43            is_vegetarian("Hamburger", "canbe");
44            is_vegetarian("Pizza", "canbe");
45            is_vegetarian("Salad", true);
46            is_vegetarian("Stone soup", true);
47            is_vegetarian("Veggies", true);
48        }
49    }
50
51    // Share database
52    let db = Arc::new(db);
53
54    // run a simple query
55    let food_: Vec<_> = run!(q, food(&db, q)).collect();
56    println!("All the food we like: {:?}", food_);
57
58    // run another simple query
59    let veggie: Vec<_> = run!(q, is_vegetarian(&db, q, true)).collect();
60    println!("Vegetarian food: {:?}", veggie);
61
62    // run a combined query
63    let wine_and_veggie: Vec<_> = run!(
64        q,
65        is_vegetarian(&db, q, true),
66        goes_well_with(&db, q, "White wine"),
67    )
68    .collect();
69    println!(
70        "Vegetarian food that goes well with white wine: {:?}",
71        wine_and_veggie
72    );
73
74    // run a query with alternatives
75    let any_wine: Vec<_> = run!(
76        q,
77        disj! {
78            goes_well_with(&db, q, "Red wine");
79            goes_well_with(&db, q, "White wine")
80        }
81    )
82    .collect();
83    println!("Food that goes well with wine: {:?}", any_wine);
84}
Source

pub fn insert(&mut self, table_name: &str, row: Vec<Value>)

Source

pub fn query( &self, table_name: &str, ) -> impl Iterator<Item = impl Iterator<Item = &Value> + '_> + '_

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.