DimpleDb is a reactive data store and sync engine for Rust, based on SQLite.
- Plain SQL for queries, schemas, and migrations.
- Simple query-to-struct mapping with serde.
- Automatic change tracking.
- Reactive queries with live updates.
- Multi-author encrypted sync via any S3 compatible endpoint.
DimpleDb is designed for storing and syncing user data across devices in local-first applications, and is inspired by Apple's Core Data + CloudKit.
DimpleDb is ALPHA and should not yet be used for production data. Please report any issues you run into.
DimpleDb is a side quest for my main project, a local first music player called Dimple. Dimple needs fast local storage that syncs and so DimpleDb is born.
use dimple_db::{Db, sync::SyncEngine};
use serde::{Serialize, Deserialize};
use rusqlite_migration::{Migrations, M};
// Entities are serde compatible Rust structs
#[derive(Serialize, Deserialize, Default)]
struct Todo {
id: String,
text: String,
completed: bool,
}
// Open or create a database
let db = Db::open("myapp.db")?;
// Migrations via rusqlite_migration
let migrations = Migrations::new(vec![
M::up("CREATE TABLE Todo (
id TEXT PRIMARY KEY,
text TEXT NOT NULL,
completed BOOLEAN NOT NULL DEFAULT 0
);"),
]);
db.migrate(&migrations)?;
// Save a todo
let todo = db.save(&Todo {
text: "Build cool app".to_string(),
completed: false,
..Default::default()
})?;
// Query todos
let todos: Vec<Todo> = db.query("SELECT * FROM Todo WHERE completed = 0", ())?;
// Query subscribe to get updates
let _sub = db.query_subscribe("SELECT * FROM Todo WHERE completed = 0", (), |todos| {
println!("Todos updated: {:?}", todos);
})?;
// Setup encrypted sync to S3
let sync = SyncEngine::builder()
.s3("https://s3.amazonaws.com", "bucket", "us-east-1", "KEY", "SECRET")?
.encrypted("passphrase")
.build()?;
// Sync with other devices
sync.sync(&db)?;For more, check out the examples!
DimpleDb's sync engine is implemented as a distributed change log ordered by UUIDv7. It is designed to use simple file storage with no API requirements to avoid cloud vendor lock-in.
The primary target is S3 compatible storage. Connectors are also included for in memory and local file storage. Changes are pushed and pulled in MessagePack files, which are encrypted with age.
Merge conflicts are automatically resolved last-write-wins at the attribute level.
See more about the design in SYNC_ENGINE.md.
If you like DimpleDb, and would like to help me keep working on it, please consider helping with one of the methods below. Open Source is my full time job and only source of income, and every single bit helps me keep working on open source software full time:
- BTC: 3FMNgdEjbVcxVoAUtgFFpzsuccnU9KMuhx
- ETH: 0xf1CE557bE8645dC70e78Cbb601bAF2b3649169A0
- DOGE: DGNKBH3AN4pUnHs9ZNQpC42ABzJG4mVF3t
- Paypal: [email protected]
- Github: https://github.com/vonnieda
- Venmo: @Jason-vonNieda-1
- Ko-Fi: https://ko-fi.com/vonnieda
- Buy Me a Coffee: https://www.buymeacoffee.com/vonnieda
- Something missing or wrong? Let me know!
- Want to sponsor me? Get in touch!
- Ordering Distributed Events
- Hybrid Logical Clocks
- Logical Physical Clocks
- UUIDv7: Timestamp ordered UUIDs
- Merklizing the key/value store for fun and profit
- Iroh gives you an API for dialing by public key
- Riffle Systems
- Riffle: Reactive Relational State for Local-First Applications
- Willow
- Willow Compared
- Willow Sideloading
- https://transactional.blog/blog/2024-data-replication-design-spectrum
- https://transactional.blog/talk/enough-with-all-the-raft
- https://raft.github.io/
- RxDB
- Dexie.js
- WatermelonDB
- Drift
- Electric SQL
- LiveStore
- TinyBase
- Dolthub
- Evolu
- Syncrotron
- SQLite Sync
- OrbitDB
- OrbitDB
- GuardianDB
DimpleDb is licensed under the MIT License.