RouchDB
A local-first document database for Rust with CouchDB replication protocol support.
RouchDB is the Rust equivalent of PouchDB — it stores JSON documents locally and syncs bidirectionally with CouchDB and compatible servers.
Features
- Local-first — works offline, syncs when connected
- CouchDB replication protocol — bidirectional sync with CouchDB 2.x/3.x
- Multiple storage backends — in-memory, persistent (redb), or remote (CouchDB HTTP)
- Conflict resolution — deterministic winner selection, conflicts preserved for application-level resolution
- Mango queries —
$eq,$gt,$regex,$elemMatch, and more - Map/reduce views — with built-in
_sum,_count,_statsreducers - Changes feed — one-shot, live streaming, selector/filter/doc_ids filtering
- Attachments — binary data stored alongside documents, inline Base64 support
- Design documents & views — Rust-native ViewEngine with map/reduce
- Plugin system — before_write, after_write, on_destroy hooks
- Partitioned databases — scoped queries by ID prefix
- Pure Rust — no C dependencies (redb instead of LevelDB/SQLite)
Quick Start
Add to your Cargo.toml:
[]
= "0.1"
= "1"
= { = "1", = ["macros", "rt-multi-thread"] }
use Database;
async
Querying
Mango Selectors
use ;
let result = db.find.await?;
Map/Reduce
use ;
let result = query_view.await?;
Replication
Sync with CouchDB or between any two databases:
let local = open?;
let remote = http;
// One-way
local.replicate_to.await?;
local.replicate_from.await?;
// Bidirectional
local.sync.await?;
Storage Backends
| Backend | Constructor | Use Case |
|---|---|---|
| Memory | Database::memory("name") |
Testing, ephemeral data |
| Redb | Database::open("path.redb", "name") |
Persistent local storage |
| HTTP | Database::http("http://...") |
Remote CouchDB |
All backends implement the same Adapter trait — swap storage without changing application code.
Crate Structure
RouchDB is a workspace of 9 crates:
| Crate | Description |
|---|---|
rouchdb |
Umbrella crate with Database API |
rouchdb-core |
Traits, types, revision tree, merge algorithm, collation |
rouchdb-adapter-memory |
In-memory storage adapter |
rouchdb-adapter-redb |
Persistent storage via redb |
rouchdb-adapter-http |
CouchDB HTTP client adapter with cookie auth |
rouchdb-changes |
Changes feed and live streaming |
rouchdb-replication |
CouchDB replication protocol |
rouchdb-query |
Mango queries and map/reduce views |
rouchdb-views |
Design documents and persistent view engine |
Documentation
Development
# Run tests
# Lint
# Integration tests (require CouchDB)
License
MIT