{"id":13429139,"url":"https://github.com/vincent-herlemont/native_db","last_synced_at":"2025-03-16T03:31:08.672Z","repository":{"id":163219310,"uuid":"638634894","full_name":"vincent-herlemont/native_db","owner":"vincent-herlemont","description":"Drop-in embedded database in Rust","archived":false,"fork":false,"pushed_at":"2024-04-07T14:26:41.000Z","size":553,"stargazers_count":245,"open_issues_count":15,"forks_count":9,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-07T15:31:37.546Z","etag":null,"topics":["android","cross-platform","database","embedded-database","ios","kv-store","mobile","orm","real-time","rust"],"latest_commit_sha":null,"homepage":"","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/vincent-herlemont.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2023-05-09T19:14:39.000Z","updated_at":"2024-04-15T02:30:57.163Z","dependencies_parsed_at":null,"dependency_job_id":"4f58ffe5-52e6-43b1-8a96-aa5f4832e65f","html_url":"https://github.com/vincent-herlemont/native_db","commit_stats":null,"previous_names":["vincent-herlemont/native_db","vincent-herlemont/struct_db"],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vincent-herlemont%2Fnative_db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vincent-herlemont%2Fnative_db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vincent-herlemont%2Fnative_db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vincent-herlemont%2Fnative_db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vincent-herlemont","download_url":"https://codeload.github.com/vincent-herlemont/native_db/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243822312,"owners_count":20353496,"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":["android","cross-platform","database","embedded-database","ios","kv-store","mobile","orm","real-time","rust"],"created_at":"2024-07-31T02:00:28.165Z","updated_at":"2025-03-16T03:31:08.667Z","avatar_url":"https://github.com/vincent-herlemont.png","language":"Rust","funding_links":[],"categories":["PGO Showcases","Rust","Applications"],"sub_categories":["Databases","Database"],"readme":"# Native DB\n\n[![](https://github.com/vincent-herlemont/native_db/actions/workflows/build_test_linux.yml/badge.svg)](https://github.com/vincent-herlemont/native_db/actions/workflows/build_test_linux.yml)\n[![](https://github.com/vincent-herlemont/native_db/actions/workflows/build_test_macos.yml/badge.svg)](https://github.com/vincent-herlemont/native_db/actions/workflows/build_test_macos.yml)\n[![](https://github.com/vincent-herlemont/native_db/actions/workflows/build_test_windows.yml/badge.svg)](https://github.com/vincent-herlemont/native_db/actions/workflows/build_test_windows.yml)\n[![](https://github.com/vincent-herlemont/native_db/actions/workflows/build_test_ios.yml/badge.svg)](https://github.com/vincent-herlemont/native_db/actions/workflows/build_test_ios.yml)\n[![)](https://github.com/vincent-herlemont/native_db/actions/workflows/build_test_android.yml/badge.svg)](https://github.com/vincent-herlemont/native_db/actions/workflows/build_test_android.yml)\n\n\n[![Crates.io](https://img.shields.io/crates/v/native_db)](https://crates.io/crates/native_db)\n[![Documentation](https://docs.rs/native_db/badge.svg)](https://docs.rs/native_db)\n[![License](https://img.shields.io/crates/l/native_db)](LICENSE)\n\nHere's a drop-in, fast, embedded database for multi-platform apps (server, desktop, mobile). Sync Rust types effortlessly. Enjoy! 😌🍃.\n\n# Features\n\n- Simple API 🦀.\n- Support for **multiple indexes** (primary, secondary, unique, non-unique, optional).\n- Fast, see [`sqlite` vs `redb` vs `native_db`](./benches/README.md) benchmarks.\n- Transparent serialization/deserialization using [native_model](https://github.com/vincent-herlemont/native_model). You can use any serialization library you want (`bincode`, `postcard`, your own etc.).\n- Ensure query **type safety** to prevent unexpected results caused by selecting with an incorrect type.\n- **Automatic model migration** 🌟.\n- **Thread-safe** and fully **ACID-compliant** transactions provided by [redb](https://github.com/cberner/redb).\n- **Real-time** subscription with filters for `insert`, `update` and `delete` operations.\n- Compatible with all Rust types (`enum`, `struct`, `tuple` etc.).\n- **Hot snapshots**.\n\n# Installation\n\nAdd this to your `Cargo.toml`:\n```toml\n[dependencies]\nnative_db = \"0.8.1\"\nnative_model = \"0.6.1\" # (optional on the `main` branch)\n```\n\n# Status\n\nActive development. The API is not stable yet and may change in the future.\n\n# How to use?\n\n- [Documentation API](https://docs.rs/native_db/latest/native_db/#api)\n- [Quick Start](https://docs.rs/native_db/latest/native_db/#quick_start)\n- Full example with Tauri: [native_db_tauri_vanilla](https://github.com/vincent-herlemont/native_db_tauri_vanilla)\n\n# Projects using Native DB\n\n- [polly-scheduler](https://github.com/dongbin86/polly-scheduler)\n- [Oku](https://okubrowser.github.io)\n\nIf you want to propose your project or company that uses Native DB, please open a PR.\n\n# Example\n\n```rust\nuse serde::{Deserialize, Serialize};\nuse native_db::*;\nuse native_db::native_model::{native_model, Model};\nuse once_cell::sync::Lazy;\n\n#[derive(Serialize, Deserialize, PartialEq, Debug)]\n#[native_model(id = 1, version = 1)]\n#[native_db]\nstruct Item {\n    #[primary_key]\n    id: u32,\n    #[secondary_key]\n    name: String,\n}\n\n// Define the models\n// The lifetime of the models needs to be longer or equal to the lifetime of the database.\n// In many cases, it is simpler to use a static variable but it is not mandatory.\nstatic MODELS: Lazy\u003cModels\u003e = Lazy::new(|| {\n    let mut models = Models::new();\n    models.define::\u003cItem\u003e().unwrap();\n    models\n});\n\nfn main() -\u003e Result\u003c(), db_type::Error\u003e {\n    // Create a database in memory\n    let mut db = Builder::new().create_in_memory(\u0026MODELS)?;\n    \n    // Insert data (open a read-write transaction)\n    let rw = db.rw_transaction()?;\n    rw.insert(Item { id: 1, name: \"red\".to_string() })?;\n    rw.insert(Item { id: 2, name: \"green\".to_string() })?;\n    rw.insert(Item { id: 3, name: \"blue\".to_string() })?;\n    rw.commit()?;\n    \n    // Open a read-only transaction\n    let r = db.r_transaction()?;\n    // Retrieve data with id=3 \n    let retrieve_data: Item = r.get().primary(3_u32)?.unwrap();\n    println!(\"data id='3': {:?}\", retrieve_data);\n    // Iterate items with name starting with \"red\"\n    for item in r.scan().secondary::\u003cItem\u003e(ItemKey::name)?.start_with(\"red\")? {\n        println!(\"data name=\\\"red\\\": {:?}\", item);\n    }\n    \n    // Remove data (open a read-write transaction)\n    let rw = db.rw_transaction()?;\n    rw.remove(retrieve_data)?;\n    rw.commit()?;\n    Ok(())\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvincent-herlemont%2Fnative_db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvincent-herlemont%2Fnative_db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvincent-herlemont%2Fnative_db/lists"}