Crates.io | tinydb |
lib.rs | tinydb |
version | 1.0.0 |
source | src |
created_at | 2019-11-12 17:14:59.06087 |
updated_at | 2020-12-02 01:03:44.347793 |
description | A small-footprint, superfast database ✨ |
homepage | |
repository | https://github.com/Owez/tinydb |
max_upload_size | |
id | 180709 |
size | 35,727 |
NOTE: This project is not affiliated with the Python TinyDB, accidental naming error from when this project was started. See renaming for updates
TinyDB or tinydb
is a small-footprint, superfast database designed to be used in-memory and easily dumped/retrieved from a file when it's time to save ✨
This database aims to provide an easy frontend to an efficiant in-memory database (that can also be dumped to a file). It purposefully disallows duplicate items to be sorted due to constraints with hash tables.
A simple example of adding a structure then querying for it:
use serde::{Serialize, Deserialize};
use tinydb::Database;
#[derive(Debug, Eq, PartialEq, Hash, Serialize, Deserialize, Clone)]
struct ExampleStruct {
my_age: i32
}
fn main() {
let my_struct = ExampleStruct { my_age: 329 };
let mut my_db = Database::new("query_test", None, false);
my_db.add_item(my_struct.clone());
let results = my_db.query_item(|s: &ExampleStruct| &s.my_age, 329);
assert_eq!(results.unwrap(), &my_struct);
}
Simply add the following to your Cargo.toml
file:
[dependencies]
tinydb = "1"