| Crates.io | herosal-ourdb |
| lib.rs | herosal-ourdb |
| version | 0.1.1 |
| created_at | 2025-12-13 07:10:18.732293+00 |
| updated_at | 2025-12-14 13:33:46.666371+00 |
| description | A lightweight, efficient key-value database with history tracking capabilities |
| homepage | |
| repository | https://github.com/threefoldtech/sal |
| max_upload_size | |
| id | 1982688 |
| size | 120,499 |
OurDB is a lightweight, efficient key-value database implementation that provides data persistence with history tracking capabilities. This Rust implementation offers a robust and performant solution for applications requiring simple but reliable data storage.
use ourdb::{OurDB, OurDBConfig, OurDBSetArgs};
use std::path::PathBuf;
fn main() -> Result<(), ourdb::Error> {
// Create a new database
let config = OurDBConfig {
path: PathBuf::from("/tmp/ourdb"),
incremental_mode: true,
file_size: None, // Use default (500MB)
keysize: None, // Use default (4 bytes)
};
let mut db = OurDB::new(config)?;
// Store data (with auto-generated ID in incremental mode)
let data = b"Hello, OurDB!";
let id = db.set(OurDBSetArgs { id: None, data })?;
println!("Stored data with ID: {}", id);
// Retrieve data
let retrieved = db.get(id)?;
println!("Retrieved: {}", String::from_utf8_lossy(&retrieved));
// Update data
let updated_data = b"Updated data";
db.set(OurDBSetArgs { id: Some(id), data: updated_data })?;
// Get history (returns most recent first)
let history = db.get_history(id, 2)?;
for (i, entry) in history.iter().enumerate() {
println!("History {}: {}", i, String::from_utf8_lossy(entry));
}
// Delete data
db.delete(id)?;
// Close the database
db.close()?;
Ok(())
}
OurDB supports two operating modes:
incremental_mode: false): You must provide IDs explicitly when storing data.incremental_mode: true): IDs are auto-generated when not provided.path: Directory for database storageincremental_mode: Whether to use auto-increment modefile_size: Maximum file size (default: 500MB)keysize: Size of lookup table entries (2-6 bytes)
OurDB consists of three main components:
Each record in the backend storage includes:
Additional documentation is available in the repository:
The repository includes several examples to demonstrate OurDB usage:
basic_usage.rs: Simple operations with OurDBadvanced_usage.rs: More complex features including both operation modesbenchmark.rs: Performance benchmarking toolRun an example with:
cargo run --example basic_usage
cargo run --example advanced_usage
cargo run --example benchmark
OurDB is designed for efficiency and minimal overhead. The benchmark example can be used to evaluate performance on your specific hardware and workload.
Typical performance metrics on modern hardware:
This project is licensed under the MIT License.