store_query/
store_query.rs

1use hotpot_db::*;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Serialize, Deserialize)]
5struct Person {
6    name: String,
7    age: u8,
8}
9
10fn main() -> Result<(), hotpot_db::Error> {
11    let mut pot = HotPot::new();
12
13    // lets make a new collection
14    pot.create_collection("address_book")?;
15
16    // well make a new item we want to store
17    let person = Person {
18        name: String::from("david holtz"),
19        age: 26,
20    };
21
22    // we insert the object into the collection!
23    pot.insert::<Person>("address_book", &person)?;
24
25    // before we query we can add an index to speed things up
26    pot.add_index_to_collection("address_book", "name", "naming_index")?;
27
28    // finally we can query
29    let query = QueryBuilder::new()
30        .collection("address_book")
31        .kind(QueryKind::Object)
32        .key("name")
33        .comparison("=")
34        .string("david holtz")
35        .finish();
36
37    let results = pot.execute(query);
38    println!("{:#?}", results);
39
40    Ok(())
41}