{"id":21900721,"url":"https://github.com/nwrenger/light-magic","last_synced_at":"2026-05-11T01:29:24.251Z","repository":{"id":241364592,"uuid":"806711537","full_name":"nwrenger/light-magic","owner":"nwrenger","description":"A lightweight, fast and easy-to-use implementation of a optionally encrypted/persistent in-memory database","archived":false,"fork":false,"pushed_at":"2024-10-06T20:44:27.000Z","size":101,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-15T19:54:09.347Z","etag":null,"topics":["easy-to-use","fast","in-memory-database","lightweight","macros"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/light-magic","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nwrenger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"nwrenger"}},"created_at":"2024-05-27T18:31:26.000Z","updated_at":"2025-02-06T19:47:27.000Z","dependencies_parsed_at":"2024-07-27T14:57:30.769Z","dependency_job_id":null,"html_url":"https://github.com/nwrenger/light-magic","commit_stats":null,"previous_names":["nwrenger/light-magic"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nwrenger%2Flight-magic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nwrenger%2Flight-magic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nwrenger%2Flight-magic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nwrenger%2Flight-magic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nwrenger","download_url":"https://codeload.github.com/nwrenger/light-magic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249145296,"owners_count":21219966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["easy-to-use","fast","in-memory-database","lightweight","macros"],"created_at":"2024-11-28T15:09:42.583Z","updated_at":"2026-05-11T01:29:24.246Z","avatar_url":"https://github.com/nwrenger.png","language":"Rust","funding_links":["https://github.com/sponsors/nwrenger"],"categories":[],"sub_categories":[],"readme":"# light-magic\n\n[![crates.io](https://img.shields.io/crates/v/light-magic.svg)](https://crates.io/crates/light-magic)\n[![crates.io](https://img.shields.io/crates/d/light-magic.svg)](https://crates.io/crates/light-magic)\n[![docs.rs](https://docs.rs/light-magic/badge.svg)](https://docs.rs/light-magic)\n\nA lightweight, fast and easy-to-use implementation of a `persistent or optionally encrypted in-memory database`.\n\n## Features\n\nPlease note that this database is highly optimized for read operations. Writing to the database is relatively slow when using `open` because each write operation involves writing data to the disk. These writes are done atomically, ensuring no data loss on a system-wide crash.\n\n- **Persistent Data Storage**: Data can be saved automatically and persistently to a formatted `JSON` file via `open`, or it can be operated in-memory using `open_in_memory`.\n- **Encrypted Persistent Data Storage**: Data can be also saved encrypted via the `encrypted` module using the same `open` method.\n- **Easy Table Markup**: Utilizes Rusts beautiful type system, structs and traits.\n- **Powerful Data Access Functions**: Utilize functions like `search` / `search_ordered` and the `join!` macro for efficient data searching and joining.\n- **Efficient Storage**: The database employs a custom `Table` data type, which uses the `BTreeMap` type from `std::collections` under the hood, for efficient storage and easy access of its tables.\n- **Parallel Access Support**: Access the database in parallel using `Arc\u003cAtomicDatabase\u003c_\u003e\u003e`.\n\n## Installation\n\nAdd this to your `Cargo.toml`:\n\n```toml\n[dependencies]\nlight_magic = \"0.8.2\"\n```\n\n## Feature Flags\n\n`light-magic` is feature-flag driven. By default, only the `atomic` module is enabled.\nYou can enable additional functionality in your `Cargo.toml`:\n\n- `atomic`: _Enabled by default_. Provides the basic atomic database with persistent JSON storage, type-safe tables, and the `DataStore` trait.\n- `encrypted`: Enables the `encrypted` module, adding Argon2id password-based key derivation, AES-256-GCM authenticated encryption (96-bit nonces), and compact bincode serialization on top of the atomic database.\n\n## Examples\n\nUsing it in an `axum` Server? Look here: [maud-magic-rs](https://github.com/nwrenger/maud-magic-rs). Otherwise, look at this general example:\n\n```rust\nuse light_magic::{\n    atomic::DataStore,\n    join,\n    serde::{Deserialize, Serialize},\n    table::{PrimaryKey, Table},\n};\n\n#[derive(Default, Debug, Serialize, Deserialize)]\nstruct Database {\n    users: Table\u003cUser\u003e,\n    permissions: Table\u003cPermission\u003e,\n    criminals: Table\u003cCriminal\u003e,\n    settings: Settings,\n}\n\nimpl light_magic::atomic::DataStore for Database {}\n// or with features = [\"encrypted\"]\n// impl light_magic::encrypted::EncryptedDataStore for Database {}\n\n#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]\nstruct User {\n    id: usize,\n    name: String,\n    kind: String,\n}\n\nimpl PrimaryKey for User {\n    type PrimaryKeyType = usize;\n\n    fn primary_key(\u0026self) -\u003e \u0026Self::PrimaryKeyType {\n        \u0026self.id\n    }\n}\n\n#[derive(Default, Debug, Clone, Serialize, Deserialize)]\nstruct Permission {\n    user_name: String,\n    level: Level,\n}\n\nimpl PrimaryKey for Permission {\n    type PrimaryKeyType = String;\n\n    fn primary_key(\u0026self) -\u003e \u0026Self::PrimaryKeyType {\n        \u0026self.user_name\n    }\n}\n\n#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]\nenum Level {\n    #[default]\n    Admin,\n}\n\n#[derive(Default, Debug, Clone, Serialize, Deserialize)]\nstruct Criminal {\n    user_name: String,\n    entry: String,\n}\n\nimpl PrimaryKey for Criminal {\n    type PrimaryKeyType = String;\n\n    fn primary_key(\u0026self) -\u003e \u0026Self::PrimaryKeyType {\n        \u0026self.user_name\n    }\n}\n\n#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]\nstruct Settings {\n    time: usize,\n    password: String,\n}\n\nfn main() {\n    let db = Database::open(\"./tests/test.json\");\n    // or with features = [\"encrypted\"]\n    // let db = Database::open(\"./tests/test.json\", \"somePassword\");\n\n     db.write().users.add(User {\n        id: 0,\n        name: String::from(\"Nils\"),\n        kind: String::from(\"Young\"),\n    });\n    println!(\"{:?}\", db.read().users.get(\u00260));\n    println!(\"{:?}\", db.read().users.search(|user| { user.name.contains(\"Nils\") }));\n\n    db.write().permissions.add(Permission {\n        user_name: String::from(\"Nils\"),\n        level: Level::Admin,\n    });\n    println!(\"{:?}\", db.read().permissions.get(\u0026String::from(\"Nils\")));\n    println!(\"{:?}\", db.read().permissions.search(|permission| { permission.level == Level::Admin }));\n\n    db.write().criminals.add(Criminal {\n        user_name: String::from(\"Nils\"),\n        entry: String::from(\"No records until this day! Keep ur eyes pealed!\"),\n    });\n    println!(\"{:?}\", db.read().criminals.get(\u0026String::from(\"Nils\")));\n    println!(\"{:?}\", db.read().criminals.search(|criminal| { criminal.entry.contains(\"No records\") }));\n\n    db.write().settings = Settings {\n        time: 1718744090,\n        password: String::from(\"password\"),\n    };\n    println!(\"{:?}\", db.read().settings);\n\n    let joined = join!(db.read(), \"Nils\", users =\u003e name, permissions =\u003e user_name, criminals =\u003e user_name);\n    println!(\"{:?}\", joined);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnwrenger%2Flight-magic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnwrenger%2Flight-magic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnwrenger%2Flight-magic/lists"}