[−][src]Crate tinydb
About
A small-footprint database implamentation, originally designed for the Zeno code editor. This database does not accept duplicates and will not save a second identical item.
Under the surface, tinydb uses a HashSet-based table that works in a similar fashion to SQL-like/Grid based databases.
Disclaimer
This project is not intended to be used inside of any critical systems due to the nature of dumping/recovery. If you are using this crate as a temporary and in-memory only database, it should preform at a reasonable speed (as it uses HashSet underneath).
Essential operations
Some commonly-used operations for the Database structure.
Operation | Implamentation |
---|---|
Create database | Database::new |
Create database from file | Database::from |
Query for item | Database::query_item |
Contains specific item | Database::contains |
Update/replace item | Database::update_item |
Delete item | Database::remove_item |
Get all items | Database::read_db |
Dump database | Database::dump_db |
Examples
Adding an item then deleting the same item by finding it in the database:
use tinydb::Database; /// A structure to test the capabilities of TinyDB. This requires [Hash], /// [Eq], [Serialize] and [Deserialize] (final two being for file operations). #[derive(Hash, Eq)] struct ExampleStruct { age: i32, other_int: i8 } fn main() { let mut db = Database::new( String::from("test-db"), None, false ); // Creates the database. db.add_item( ExampleStruct { age: 595, other_int: 34 } ); // Adds an item to the database. let got_item = db.query_item( |s: ExampleStruct| s.age, 595 ).unwrap(); // Returns the item with [ExampleStruct::age] of 595. db.remove_item(got_item).unwrap(); // Will remove the item found from the database }
Modules
error | Contains various items related to errors inside of TinyDB. |
Structs
Database | The primary database structure, allowing storage of a generic type with dumping/saving options avalible. |