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

§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)?;

Re-exports§

pub use super::*;

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§

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.
LexicographicString
MemoryStorageError
Error type for MemoryStorage operations.

Enums§

DatabaseError
Errors that can occur while interacting with the database.
InternalDatabaseError
Internal errors that should never arise during normal operation of the database.

Traits§

AtomicStorage
A trait defining atomic operations for storage backends.
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.
KeyBytes
A trait for converting keys to and from byte representations.
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.
Scope
Storage
A trait defining a storage backend for the database.

Type Aliases§

DeserializationError
MemoryStorage
A memory-based storage implementation using a BTreeMap.
SerializationError
Error type for serialization operations, re-exported from the bincode crate.

Derive Macros§

Record
Derive macro for generating database record implementations.