#json #orm #embedded-database #file #embedded-file

joydb

An in-memory embedded database with persistence and multiple adapters (JSON, CSV, etc). Acts like a minimalistic ORM with zero setup. Simple, lightweight, and perfect for prototypes, small apps, or experiments.

3 releases

Uses new Rust 2024

new 0.0.3 Apr 13, 2025
0.0.2 Apr 13, 2025
0.0.1 Apr 12, 2025

#861 in Database interfaces

43 downloads per month

MIT license

49KB
1K SLoC

Joydb

An in-memory embedded database with persistence and multiple adapters (JSON, CSV, etc). Acts like a minimalistic ORM with zero setup. Simple, lightweight, and perfect for prototypes, small apps, or experiments. Not intended for serious production use, optimized for nothing but ergonomics.

Get started

Install prerequisites:

cargo install serde --features derive
cargo install joydb --features json

Example:

use joydb::{Joydb, Model, adapters::JsonAdapter};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, Model)]
struct User {
    id: u32,
    name: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Model)]
struct Post {
    id: u32,
    title: String,
}

// Define the state by listing the models
joydb::define_state! {
    AppState,
    models: [User, Post],
}

// Define your the database.
// Typewise it's essentially combination of the state and adapter.
type Db = Joydb<AppState, JsonAdapter>;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let db = Db::open("data.json")?;

    // Insert a new record
    db.insert(&User {
        id: 1,
        name: "Alice".to_owned(),
    })?;

    // Get a record by ID
    let alice = db.find::<User>(&1)?.unwrap();
    assert_eq!(alice.name, "Alice");
}

Similar projects

  • lowdb - JSON database for JavaScript
  • alkali - Python ORM that writes to disk (JSON, YAML, CSV, etc)

Dependencies

~0.3–1.3MB
~26K SLoC