Skip to content

vonnieda/dimple_db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DimpleDb

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.

Status

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.

Quick Start

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!

Sync Engine

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.

Sponsoring DimpleDb

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:

Inspiration and Research

Core Data

Encryption

S3 Compatible Storage

Distributed Systems

Local First

Similar Projects

Articles

License

DimpleDb is licensed under the MIT License.

About

DimpleDb is a reactive data store and sync engine for Rust, based on SQLite.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages