Skip to main content

Crate kivis

Crate kivis 

Source
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 (implies alloc)
  • alloc: Enable Vec and String support without requiring the full standard library
  • atomic (default): Enable atomic transaction support (requires alloc)
  • memory-storage (default): Include in-memory storage implementation
  • heapless: Enable UnifierData implementation for heapless::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_impl that tracks the current index and manifest name

Structs§

BufferOverflowError
BufferOverflowOr
Database
The kivis database type. All interactions with the database are done through this type.
DatabaseTransaction
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.
BufferOp
DatabaseError
Errors that can occur while interacting with the database.
InternalDatabaseError
Internal errors that should never arise during normal operation of the database.
MemoryStorageError
Error type for MemoryStorage operations.
TransactionError
Errors that can occur during transaction buffer operations

Traits§

BufferOpsContainer
Trait for containers that can hold transaction buffer operations.
DatabaseEntry
The main trait of the crate, defines a database entry that can be stored with its indexes.
DeriveKey
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
RecordKey
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 DatabaseEntry trait.
Repository
A trait defining a repository backend decoupled from serialization.
Scope
Storage
A trait defining a storage backend for the database.
StringLike
Unifiable
UnifiableRef
Unifier
UnifierData

Type Aliases§

MemoryStorage
A memory-based storage implementation using a BTreeMap.

Derive Macros§

Record
Derive macro for generating database record implementations.