Expand description
§Kivis Database
A lightweight, type-safe database schema library for Rust with support for custom storage backends, automatic indexing, and foreign key relationships.
§Features
- Type-safe schema generation: Automatically derive database schemas from Rust structs
- Generic storage backend support: Work with any ordered key-value store
- Automatic key generation and indexing: Support for auto-increment keys and secondary indexes
- Foreign key relationships: Type-safe references between records
- Layered cache architectures: Compose multiple storage implementations
§Feature Flags
std(default): Enable standard library support (impliesalloc)alloc: EnableVecandStringsupport without requiring the full standard libraryatomic(default): Enable atomic transaction support (requiresalloc)memory-storage(default): Include in-memory storage implementationheapless: EnableUnifierDataimplementation forheapless::Vec<u8, N>, allowing fixed-capacity stack-allocated vectors for embedded environments
§Quick Start
use kivis::{Database, MemoryStorage, Record, manifest};
#[derive(Record, serde::Serialize, serde::Deserialize, Debug)]
struct User {
name: String,
email: String,
}
// Define the manifest for the database
manifest![MyDatabase: User];
let mut db = Database::<MemoryStorage, MyDatabase>::new(MemoryStorage::new())?;
let user = User {
name: "Alice".to_string(),
email: "alice@example.com".to_string(),
};
let user_key = db.put(user)?;Macros§
- generate_
member_ scopes - Helper macro to generate member scope list
- manifest
- Declarative macro to implement the Scope trait for multiple structs with a named manifest. Each struct gets its position in the array as its SCOPE value. Also generates an empty manifest struct and assigns it as the Manifest type.
- paste
- scope_
impl_ with_ index - Helper macro for
scope_implthat tracks the current index and manifest name
Structs§
- Buffer
Overflow Error - Buffer
Overflow Or - Database
- The
kivisdatabase type. All interactions with the database are done through this type. - Database
Transaction - A database transaction that accumulates low-level byte operations (writes and deletes) without immediately applying them to storage.
- Lexicographic
- OpsIter
Enums§
- BatchOp
- Represents a batch operation: either insert or delete.
- Buffer
Op - Database
Error - Errors that can occur while interacting with the database.
- Internal
Database Error - Internal errors that should never arise during normal operation of the database.
- Memory
Storage Error - Error type for
MemoryStorageoperations. - Transaction
Error - Errors that can occur during transaction buffer operations
Traits§
- Buffer
OpsContainer - Trait for containers that can hold transaction buffer operations.
- Database
Entry - The main trait of the crate, defines a database entry that can be stored with its indexes.
- Derive
Key - A trait defining how a key can be extracted from a record. This might be one of the fields, a composite key, a hash, random uuid or any other type of derivation. It shouldn’t be implemented for auto-incrementing keys.
- Incrementable
- A trait describing how a key can be auto-incremented, defined for numeric types.
- Index
- A trait defining an index in the database.
- Manifest
- Manifests
- Record
Key - A trait defining that the implementing type is a key of some record.
Each type can be a key of only one record type, which is defined by the
DatabaseEntrytrait. - Repository
- A trait defining a repository backend decoupled from serialization.
- Scope
- Storage
- A trait defining a storage backend for the database.
- String
Like - Unifiable
- Unifiable
Ref - Unifier
- Unifier
Data
Type Aliases§
- Memory
Storage - A memory-based storage implementation using a
BTreeMap.
Derive Macros§
- Record
- Derive macro for generating database record implementations.