CrepeDB
A versioned and forkable embedded Key-Value database. It aims to be used as storage for blockchain applications.
CrepeDB provides a multi-version concurrency control (MVCC) database with snapshot isolation. It supports forking database snapshots and maintains version history efficiently.
Features
- Versioned Storage: Track changes across multiple versions
- Snapshot Isolation: Create and read from consistent snapshots
- Fork Support: Create new branches from any snapshot
- Table Types: Support both versioned and basic (non-versioned) tables
- High Performance: Optimized for fast reads and writes
- Multi Backend Support: Use different storage backends
- ACID Transactions: Full transactional support
Supported Backends
CrepeDB supports multiple storage backends:
- redb - A simple, portable, high-performance embedded key-value database
- rocksdb - A high-performance embedded database based on RocksDB
- mdbx - A fast, compact, powerful embedded transactional key-value database
Installation
Add crepedb to your Cargo.toml with the desired backend feature:
# Using cargo add (redb is enabled by default)
# Or specify a different backend
Or manually in Cargo.toml:
[]
# Default: redb backend is enabled
= { = "0.1" }
# Or enable a specific backend
= { = "0.1", = ["backend-redb"] }
= { = "0.1", = ["backend-rocksdb"] }
= { = "0.1", = ["backend-mdbx"] }
# Enable multiple backends
= { = "0.1", = ["backend-redb", "backend-rocksdb"] }
Usage
Basic Example
use CrepeDB;
use RedbDatabase;
// Create a database with a backend
let backend = memory?;
let db = new;
// Create root snapshot
let wtxn = db.write?;
wtxn.create_versioned_table?;
let root = wtxn.commit?;
// Write data
let wtxn = db.write?;
let mut table = wtxn.open_table?;
table.set?;
let snapshot1 = wtxn.commit?;
// Read data
let rtxn = db.read?;
let table = rtxn.open_table?;
let value = table.get?;
assert_eq!;
Table Types
CrepeDB supports two types of tables:
-
Versioned Tables: Track all changes across snapshots. Each write creates a new version entry. Reads can retrieve data from any snapshot in the version history.
wtxn.create_versioned_table?; -
Basic Tables: Store data directly with no version tracking. Updates overwrite previous values. More efficient for data that doesn't need version history.
wtxn.create_basic_table?;
Forking Snapshots
You can create multiple branches from the same snapshot:
// Create branch 1 from root
let wtxn1 = db.write?;
let mut table1 = wtxn1.open_table?;
table1.set?;
let branch1 = wtxn1.commit?;
// Create branch 2 from root (independent of branch1)
let wtxn2 = db.write?;
let mut table2 = wtxn2.open_table?;
table2.set?;
let branch2 = wtxn2.commit?;
// Each branch maintains its own data
let rtxn1 = db.read?;
let table1 = rtxn1.open_table?;
assert_eq!;
let rtxn2 = db.read?;
let table2 = rtxn2.open_table?;
assert_eq!;
Using Different Backends
Redb Backend
use CrepeDB;
use RedbDatabase;
// In-memory database
let backend = memory?;
// Persistent database
let backend = open?;
RocksDB Backend
use CrepeDB;
use RocksdbDatabase;
let backend = open_or_create?;
MDBX Backend
use CrepeDB;
use MdbxDatabase;
let backend = open_or_create?;
Command Line Tools (WIP)
You can use the crepedb command line tool to read and manage databases. See the tool documentation for more information.
Install the tool:
Documentation
For more detailed documentation, see:
- Design Document - Architecture and design details
- API Documentation - Full API reference
License
Licensed under the Apache License, Version 2.0.