RedDb
RedDb is an embedded fast, lightweight, and secure in-memory data store with persistance in different serde-compatible formats (json, ron, yaml). RedDb has an easy to use API for finding, updating and deleting your data.
Quickstart
Add RedDb to your Cargo.toml specifing what serializer you want to use:
[]
= "0.2.0"
= ["json_ser"] # Json serialization / deserialization
= ["ron_ser"] # Ron serialization / deserialization
= ["yaml_ser"] # Yaml serialization / deserialization
use ;
Why
RedDb is the migration of a side project originally written in NodeJs that was designed to store objects in memory (with hd persistance) and do searchs on them.
When
If you are looking for a some short of Key/Value you will find better options. If you are looking for an embedded fast, lightweight and easy to use in-memory data store with persistance, RedDb could be a good choice.
API
Data
Data is serialized and deserialized in different serde-compatible formats (json, ron, yaml) and wrapped into the Document struct as follows:
Since data field is a generic you can store any kind of data you want. As you will see on the API, Document<T> is the default return type for most operations.
Persistance
RedDb's persistence uses an append-only format (AOF) so all write operations are added to to the end of the database file. The database is automatically compacted in just one line per object/record everytime you start the database in your application.
The API provides bulk-like write operations (insert & update) for vectors of data that are faster to persist due to hd sync operations. Use them instead iterate over the *_one() methods you'll see on the API.
Inserting Data
RedDb use uuid identifiers as unique ids. An uuid will be returned when you insert a record.
Insert one
let my_struct = MyStruct ;
let doc: = store.insert_one?;
println!;
// 94d69737-4b2e-4985-aaa1-e28bbff2e6d0
Insert
If you want to insert a vector of data insert() is more suitable and faster to persists than iterate over insert_one() method due to the nature of the AOF persistance.
let my_docs = vec!;
let docs: = db.insert?;
Finding Data
There are two ways to find your data. By it's uuid or looking into the database what data matches your query.
Find one
Performs a search by uuid.
let my_struct = MyStruct ;
let inserted_doc : = db.insert_one?;
let doc: = db.find_one?;
Find
Look into the database for data matching your query.
let one = MyStruct ;
let two = MyStruct ;
let three = MyStruct ;
let many = vec!;
let inserted_doc : = db.insert?;
let docs: = db.find?;
Updating Data
Update data is pretty straightforward. You can update data
Update one
Update one record, using it's uuid as search param.
let my_struct = MyStruct ;
let new_value = MyStruct ;
let inserted_doc : = db.insert_one?;
let updated: bool = db.update_one)?;
Update
You can update all data in the databas that matches your query param. Update will return the number of updated documents.
let search = MyStruct ;
let new_value = MyStruct ;
let updated: usize = store.update?;
Deleting Data
Delete one
Delete a record by it's uuid.
let my_struct = MyStruct ;
let doc: = db.insert_one?;
let deleted : bool = db.delete_one)?;
Delete
Like in update method, this method will lookup into the database which data matches your query and then delete it.
let search = MyStruct ;
let deleted = store.delete?;
println!;
// 1
License
This library is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or opensource.org/licenses/MIT)
at your option.