Nitrite started in 2017 as a small embedded document database for Java. No server, one file, put documents in and query them back. It grew to about 900 stars and found its way into desktop apps and Android apps. Then came a Flutter version. This year I finished the Rust one.
It is on crates.io as nitrite.
[dependencies]
nitrite = "1.0"
use nitrite::nitrite::Nitrite;
use nitrite::filter::field;
use nitrite::doc;
let db = Nitrite::builder().open_or_create(None, None)?;
let users = db.collection("users")?;
users.insert(doc!{ "name": "John Doe", "age": 30 })?;
for d in users.find(field("age").gt(18))? {
println!("{:?}", d);
}
What it does
- Collections of schemaless documents, or typed repositories with a derive macro
- Unique and non-unique indexes
- Full-text search, built on Tantivy
- Spatial queries on an R-tree
- ACID transactions
- In-memory storage, or on disk with Fjall
- Vector index and RAG store
What was different from Java
The Java version leans on a shared mutable store and lots of interfaces. In Rust I had to decide who owns what much earlier. Collections hand out cursors that borrow from the store, and that shaped the whole query API.
The storage layer was the biggest change. Java used MVStore and RocksDB. For Rust I picked Fjall, an LSM store written in pure Rust, so there is no C++ toolchain to fight on Windows.
Full-text search went from a hand-written index to Tantivy. It is faster and I deleted a lot of code.
Where it fits
If you want SQL, use SQLite. Nitrite is for when your data is already documents and you want indexes and queries without a schema or a server: desktop tools, CLI apps, local-first apps, game save data.
Code and docs: https://github.com/nitrite/nitrite-rust?utm_source=devto&utm_medium=community
What do you use for embedded storage in Rust today, and what is missing from it?

Top comments (0)