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. Pure Rust, no C dependencies.
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 (memory + redb backends)
- 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
- CouchDB-compatible HTTP server — browse databases with Fauxton, use any CouchDB client
- CLI tool — inspect, query, and modify redb databases from the terminal
- Pure Rust — no C dependencies (redb instead of LevelDB/SQLite)
Quick Start
Add to your Cargo.toml:
[]
= "0.3"
= "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?;
Live Replication
use Duration;
use ;
let = local.replicate_to_live;
while let Some = rx.recv.await
handle.cancel;
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.
HTTP Server & Fauxton
RouchDB includes a CouchDB-compatible HTTP server with the Fauxton web dashboard:
# Install the server
# Download Fauxton (optional, requires Node.js >= 10)
# Start the server
# Open Fauxton in your browser
The server exposes 25+ CouchDB-compatible REST endpoints — documents, queries, changes feed, attachments, security, design docs, Mango indexes, and more — so any CouchDB client (Fauxton, PouchDB, curl) can connect to it.
Options:
rouchdb-server <path.redb> [OPTIONS]
Options:
-p, --port <PORT> Port to listen on [default: 5984]
--host <HOST> Host to bind to [default: 127.0.0.1]
--db-name <NAME> Database name [default: filename without extension]
CLI Tool
A command-line tool for inspecting, querying, and modifying redb database files:
Reading
Writing
Operations
Add --pretty (or -p) to any command for formatted JSON output.
Crate Structure
RouchDB is a workspace of 11 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 |
rouchdb-server |
CouchDB-compatible HTTP server with Fauxton |
rouchdb-cli |
Command-line tool for database inspection and CRUD |
Documentation
Development
# Run tests
# Lint
# Integration tests (require CouchDB)
License
MIT