Expand description
reindeer 🦌 is a small entity-based embedded database with a minimal no-SQL relationnal model, written in pure Rust.
It uses sled, serde
and bincode under the hood.
reindeer 🦌 lifts your sled!
It relies on a trait, Entity, to provide basic document store capabilities to any serde-serializable struct that implements it.
To use reindeer, add a key to identify any instance individually to your struct and implement the store_name,
get_key and set_key methods to implement
the reindeer::Entity trait.
You can then use
- the
Entity::savemethod to save your struct instance to the database - the
Entity::getmethod to get any entity from the database using its unique key - the
Entity::get_allmethod to get all entities from the database using its unique key - the
Entity::get_with_filtermethod to get all entities that match a condition (O(n)) - … And much more!
If the Key associated type is u32, then your entity can be auto-incremented
with save_next()
from the AutoIncrementEntity (which needs to be in scope)
Three types of relationships can be achieved :
- Sibling relationship : two or more
Entitystructs that share the same key type for which each entity has 0 or 1 counterpart in their sibling Entity stores (one-to-zero-or-one) - Parent-Child relationship : An entity has a collection of matching entities in another Entity Store (one-to-many)
- Free relationship : Any two entities can be linked together as a two-way link. (many-to-many)
Those provide integrity checks in the form of a DeletionBehaviour enum, that can either be :
DeletionBehaviour::Cascade: related entities are also removed if this one is removedDeletionBehaviour::Error: Trying to remove this entity as related entities still exist will cause an error and abortDeletionBehaviour::BreakLink: Remove this entity and the links with its related entites, leaving the other ones untouched
Structs§
- Db
sleddatabase struct. It can be copied and used accross threads and is a central item to store entities. This is a re-export ofsled::Db.- Error
- Error type for
reindeer - Query
Builder QueryBuilderis a convenient way to build query to target several conditions without the need to immediately serialize/deserialize data from disk. For simplicity’s sake, ids are expressed as&[u8]. To get the key of an entity using this type, just use&entity.get_key().as_bytes().
Enums§
- Deletion
Behaviour - Enum for use in relation description, defining how the database must behave if one end of the relation is removed.
- Error
Kind - Error kind enum for Reindeer-related errors.
Traits§
- AsBytes
- Trait allowing values to be converted to
Vec<u8>. This trait is not meant to be implemented, but you can if you need to. - Auto
Increment Entity AutoIncrementEntityis a trait aimed to automatically be implemented on Entities that haveu32as theirKeytype.- Entity
- The
Entitytrait provides document store capabilities for any struct that implements it.
Functions§
- open
- Opens a
sleddatabase to store Entities. The resulting Db object can be copied accross threads. This is a re-export ofsled::open.
Type Aliases§
- Result
- Type definition to simplify the use of Result everywhere in the library
Derive Macros§
- Deserialize
- Entity
- Derive macro for
reindeer’s 🦌Entitytrait. - Serialize