TinyBase

TinyBase is a small but highly performant embedded DB based on sled with full indexing and constraint support.

Example

TinyDB has indexes which allow for fast querying based on a specific key. It also allows for constraints based on specific indexes. ```rust

[derive(Serialize, Deserialize, Debug, Clone)]

struct Person { name: String, last_name: String, }

fn main() { let db = TinyBase::new(Some("./people"), true); let persontable: Table = db.opentable("people").unwrap();

let name_idx = person_table
    .create_index("name", |record| record.name.to_owned())
    .unwrap();

let lastname_idx = person_table
    .create_index("last_name", |record| record.last_name.to_owned())
    .unwrap();

person_table
    .constraint(Constraint::unique(&name_idx))
    .unwrap();

person_table
    .constraint(Constraint::check(|person| !person.name.contains(".")))
    .unwrap();

init_example_data(&person_table);

println!(
    "{:#?}",
    QueryBuilder::new(&person_table)
        .by(&name_idx, "John".to_string())
        .by(&lastname_idx, "Jones".to_string())
        .update(
            QueryOperator::Or,
            Person {
                name: "Kevin".to_string(),
                last_name: "Spacey".to_string()
            }
        )
        .unwrap()
);

}

fn initexampledata(persontable: &Table) { persontable .insert(Person { name: "John".tostring(), lastname: "Smith".to_string(), }) .unwrap();

person_table
    .insert(Person {
        name: "Bill".to_string(),
        last_name: "Smith".to_string(),
    })
    .unwrap();

person_table
    .insert(Person {
        name: "Coraline".to_string(),
        last_name: "Jones".to_string(),
    })
    .unwrap();

} ```