{"id":43311718,"url":"https://github.com/lockbook/db-rs","last_synced_at":"2026-02-01T21:20:01.923Z","repository":{"id":65814954,"uuid":"588396377","full_name":"lockbook/db-rs","owner":"lockbook","description":"An ergonomic, embedded, single-threaded database for Rustaceans.","archived":false,"fork":false,"pushed_at":"2026-01-26T22:17:06.000Z","size":131,"stargazers_count":7,"open_issues_count":5,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-27T09:36:54.547Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://crates.io/crates/db-rs","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lockbook.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-01-13T02:29:36.000Z","updated_at":"2026-01-26T22:17:15.000Z","dependencies_parsed_at":"2024-02-22T19:56:38.635Z","dependency_job_id":"656b3e2f-a6b0-456c-bb80-ffbc7b0e39aa","html_url":"https://github.com/lockbook/db-rs","commit_stats":null,"previous_names":["lockbook/db-rs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lockbook/db-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lockbook%2Fdb-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lockbook%2Fdb-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lockbook%2Fdb-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lockbook%2Fdb-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lockbook","download_url":"https://codeload.github.com/lockbook/db-rs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lockbook%2Fdb-rs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28991734,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T20:57:35.821Z","status":"ssl_error","status_checked_at":"2026-02-01T20:57:29.580Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2026-02-01T21:20:01.111Z","updated_at":"2026-02-01T21:20:01.911Z","avatar_url":"https://github.com/lockbook.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# db-rs\n\nAn ergonomic, embedded, single-threaded database for Rustaceans.\n\n### Strengths\n\n-   Define a schema in Rust.\n-   Use **your** types in the database as long as they implement `Serialize` and `Deserialize`. You don't have to fuss around\n    with converting your data to database-specific types.\n-   All your database interactions are typesafe. When you type `db.`, your tooling will suggest a list of your tables. When you\n    select a table, you'll be greeted with that table-type's contract populated with your types. No need to wrap your db\n    in a handwritten type safe contract.\n-   Supports a variety of simple data-structures, including LookupTables, Lists, and many more. Implementing your own\n    table types is trivial.\n-   All table mutations are persisted to an append only log using the fast \u0026 compact bincode representation of your types.\n-   You can `begin_transaction()`s to express atomic updates to multiple tables.\n\n### Quickstart\n\nAdd the following to your `Cargo.toml`:\n\n```toml\ndb-rs = \"0.2.1\"\ndb-rs-derive = \"0.2.1\"\n```\n\nDefine your schema:\n\n```rust\nuse db_rs_derive::Schema;\nuse db_rs::{Single, List, LookupTable};\n\n#[derive(Schema)]\nstruct SchemaV1 {\n    owner: Single\u003cUsername\u003e,\n    admins: List\u003cUsername\u003e,\n    users: LookupTable\u003cUsername, Account\u003e,\n}\n```\n\nInitialize your DB:\n\n```rust\nuse db_rs::Db;\nuse db_rs::Config;\n\nlet mut db = SchemaV1::init(Config::in_folder(\"/tmp/test/\"))?;\ndb.owner.insert(\"Parth\".to_string())?;\n\nprintln!(\"{}\", db.owner.data().unwrap());\n```\n\n### Table Types\n\nEach table has an in-memory representation and a corresponding log entry format. For instance\n[List]'s in memory format is a [Vec], and you can look at it's corresponding [list::LogEntry]\nto see how writes will be written to disk.\n\nTables that start with `Lookup` have a `HashMap` as part of their in memory format.\n[LookupTable] is the most general form, while [LookupList] and [LookupSet] are specializations\nfor people who want `HashMap\u003cK, Vec\u003cV\u003e\u003e` or `HashMap\u003cK, HashSet\u003cV\u003e\u003e`. Their reason for\nexistence is better log performance in the case of small modifications to the `Vec` or\n`HashSet` in question (see [lookup_list::LogEntry] or [lookup_set::LogEntry]).\n\n\n### Log Compaction\n\nAt any point you can call [Db::compact_log] on your database. This will atomically write a\ncompact representation of all your current tables. For example if there's a key in a\nLookupTable that was written to many times, the compact representation will only contain the\nlast value. Each table type descibes it's own compact representation.\n\nIf your database is in an `Arc\u003cMutex\u003e\u003e` you can additionally use the [BackgroundCompacter]\nwhich will perform compactions periodically in a separate thread.\n\n### TXs and Batch Writing\n\nYou can [Db::begin_transaction] which will allow you to express batch operations that can be\ndiscarded as a set if your program is interrupted. Presently there is no way to abort a\ntransaction. TXs are also a mechanism for batch writing, log entries are kept in memory until\nthe transaction completes and written once to disk.\n\n### Active areas of thought and research\n\n-   Because the db implementation (like redis) is single threaded, it forces you to achieve application throughput via low\n    latency rather than concurrency. Currently, this suits our needs. Simply being embedded gives us more than enough\n    throughput compared to something like Postgres. For use in a server-style setting put the database in\n    an `Arc\u003cMutex\u003c\u003e\u003e`.\n-   The database offers no tools at the moment to define integrity constraints beyond what the Rust type system implicitly\n    enforces (non-null for instance). At the moment for us, this is simply an application side concern.\n\n### Features\n\n`clone` - derive clone on all table types. Consistency between cloned database is not provided.\nUseful in testing situations.\n\n### Used by\n\n-   [Lockbook](https://github.com/lockbook/lockbook)\n\n\nLicense: BSD-3-Clause\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flockbook%2Fdb-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flockbook%2Fdb-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flockbook%2Fdb-rs/lists"}