| Crates.io | tidesdb-rs |
| lib.rs | tidesdb-rs |
| version | 0.1.2 |
| created_at | 2026-01-03 17:56:11.12747+00 |
| updated_at | 2026-01-03 17:56:11.12747+00 |
| description | Rust wrapper for TidesDB, a fast and efficient key-value storage engine |
| homepage | |
| repository | https://github.com/0x6flab/tidesdb-rs |
| max_upload_size | |
| id | 2020531 |
| size | 2,220,750 |
Rust wrapper for TidesDB, a fast and efficient key-value storage engine library written in C.
Note: This repository uses tidesdb as a git submodule.
When cloning this repository, use the --recursive flag to include the TidesDB submodule:
git clone --recursive https://github.com/0x6flab/tidesdb-rs.git
If you've already cloned without the --recursive flag:
git submodule update --init --recursive
To update the TidesDB submodule to the latest version:
cd tidesdb
git fetch origin
git checkout origin/master
cd ..
git add tidesdb
git commit -m "Update tidesdb submodule"
Check out the examples directory for comprehensive examples demonstrating various features:
# Run a specific example
cargo run --example basic
# Build all examples
cargo build --examples
# See all available examples
ls examples/
For detailed instructions, see the examples README.
The features of TidesDB-rs are the same as the TidesDB C library.
You need to following C libraries installed on your system:
liblz4-dev (or lz4-devel on some systems)libzstd-dev (or zstd-devel)libsnappy-dev (or snappy-devel)zlib1g-dev (or zlib-devel)sudo apt-get install liblz4-dev libzstd-dev libsnappy-dev zlib1g-dev
sudo dnf install lz4-devel zstd-devel snappy-devel zlib-devel
brew install lz4 zstd snappy
use std::fs;
use tidesdb_rs::{ColumnFamilyConfig, Config, Database};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let db_path = "example_db";
let _ = fs::remove_dir_all(db_path);
let config = Config::new(db_path)?;
println!("Opening database at: {}", db_path);
let db = Database::open(config)?;
println!();
let cf_config = ColumnFamilyConfig::new();
db.create_column_family("users", &cf_config)?;
println!("Created column family: users");
println!();
let cf = db.get_column_family("users")?;
println!("Writing data...");
let mut txn = db.begin_transaction()?;
txn.put(&cf, b"user:1", b"John Doe")?;
txn.put(&cf, b"user:2", b"Jane Smith")?;
txn.put(&cf, b"user:3", b"Bob Johnson")?;
txn.commit()?;
println!("Inserted 3 users");
println!();
println!("Reading data...");
let txn = db.begin_transaction()?;
if let Some(value) = txn.get(&cf, b"user:1")? {
println!("user:1 -> {}", String::from_utf8_lossy(&value));
}
if let Some(value) = txn.get(&cf, b"user:2")? {
println!("user:2 -> {}", String::from_utf8_lossy(&value));
}
if let Some(value) = txn.get(&cf, b"user:3")? {
println!("user:3 -> {}", String::from_utf8_lossy(&value));
}
match txn.get(&cf, b"user:999")? {
Some(_) => println!("user:999 -> Unexpectedly found!"),
None => println!("user:999 -> Not found (expected)"),
}
println!();
println!("Successfully demonstrated basic operations");
Ok(())
}
use tidesdb_rs::{IsolationLevel};
// Serializable isolation for strong consistency
let txn = db.begin_transaction_with_isolation(IsolationLevel::Serializable)?;
txn.put(&cf, b"account", b"balance:100")?;
txn.commit()?;
use tidesdb_rs::{ColumnFamilyConfig, CompressionAlgorithm};
let cf_config = ColumnFamilyConfig::new()
.with_compression(CompressionAlgorithm::Lz4)
.with_bloom_filter(true, 0.01); // 1% false positive rate
db.create_column_family("compressed_cf", &cf_config)?;
// Set a key that expires in 60 seconds
let mut txn = db.begin_transaction()?;
txn.put_with_ttl(&cf, b"temp_key", b"temp_value", 60)?;
txn.commit()?;
let mut txn = db.begin_transaction()?;
txn.put(&cf, b"key1", b"value1")?;
txn.savepoint("checkpoint1")?;
txn.put(&cf, b"key2", b"value2")?;
// Rollback to checkpoint
txn.rollback_to_savepoint("checkpoint1")?;
txn.commit()?;
// List all column families
let cfs = db.list_column_families()?;
for cf_name in &cfs {
println!("CF: {}", cf_name);
}
// Drop a column family
db.drop_column_family("old_cf")?;
// Manually trigger compaction
let cf = db.get_column_family("my_cf")?;
cf.compact()?;
// Manually flush memtable to disk
cf.flush()?;
Database - Main database handleColumnFamily - Column family handleTransaction - Transaction handleConfig - Database configurationColumnFamilyConfig - Column family configurationIsolationLevel - Transaction isolation levelsCompressionAlgorithm - Compression algorithmsError - Error typenew(path) - Create config with database pathwith_log_level(level) - Set logging levelwith_flush_threads(count) - Set number of flush threadswith_compaction_threads(count) - Set number of compaction threadswith_block_cache_size(size) - Set block cache sizewith_max_open_sstables(count) - Set max open SSTablesnew() - Create default configwith_compression(algo) - Set compression algorithmwith_bloom_filter(enabled, fpr) - Enable bloom filter with false positive ratewith_ttl(ttl) - Set default TTLAll functions return a Result<T, Error>. The Error type includes:
Memory - Memory allocation failureInvalidArgs - Invalid argumentsNotFound - Key not foundIo - I/O errorCorruption - Data corruption detectedExists - Resource already existsConflict - Transaction conflictTooLarge - Value too largeMemoryLimit - Memory limit exceededInvalidDb - Invalid database stateUnknown - Unknown errorThis crate provides safe Rust wrappers around TidesDB C API:
Contributions are welcome! Please feel free to submit a Pull Request.