A modern embedded database. Written in Rust, usable on servers and phones from any C-compatible language.
let db = sled::open(path)?; // as in fs::open
db.insert(k, v)?; // as in BTreeMap::insert
db.get(&k)?; // as in BTreeMap::get
for kv in db.range(k..) {} // as in BTreeMap::range
db.remove(&k)?; // as in BTreeMap::remove
drop(db); // fsync and close file
Embedded databases are useful in several cases:
- you want to store data on disk, without facing the complexity of files
- you want to be simple, without operating an external database
- you want to be fast, without paying network costs
- using disk storage as a building block in your system
- API similar to a threadsafe
BTreeMap<[u8], [u8]>
- fully serializable multi-key and multi-Tree transactions
- fully atomic single-key operations, including compare and swap and update and fetch
- zero-copy reads
- write batch support
- subscription/watch semantics on key prefixes
- multiple keyspaces
- merge operators
- forward and reverse iterators
- a crash-safe monotonic ID generator capable of generating over 100 million unique ID's per second
- zstd compression (use the
compression
build feature) - cpu-scalable lock-free implementation
- SSD-optimized log-structured storage
- prefix encoded and suffix truncated keys reducing the storage cost of complex keys