Crate reindeer

source ·
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

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 Entity structs 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 removed
  • DeletionBehaviour::Error : Trying to remove this entity as related entities still exist will cause an error and abort
  • DeletionBehaviour::BreakLink : Remove this entity and the links with its related entites, leaving the other ones untouched

Structs

  • sled database struct. It can be copied and used accross threads and is a central item to store entities. This is a re-export of sled::Db.
  • Error type for reindeer
  • QueryBuilder is 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

  • Enum for use in relation description, defining how the database must behave if one end of the relation is removed.
  • Error kind enum for Reindeer-related errors.

Traits

  • Trait allowing values to be converted to Vec<u8>. This trait is not meant to be implemented, but you can if you need to.
  • AutoIncrementEntity is a trait aimed to automatically be implemented on Entities that have u32 as their Key type.
  • The Entity trait provides document store capabilities for any struct that implements it.

Functions

  • Opens a sled database to store Entities. The resulting Db object can be copied accross threads. This is a re-export of sled::open.

Type Definitions

  • Type definition to simplify the use of Result everywhere in the library

Derive Macros