7 releases
Uses new Rust 2024
new 0.0.7 | Apr 18, 2025 |
---|---|
0.0.6 | Apr 18, 2025 |
#344 in Database implementations
265 downloads per month
Used in joydb
8KB
65 lines
JSON file database and ORM for quick prototyping.
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::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
Dependencies
~190–620KB
~15K SLoC