{"id":20951368,"url":"https://github.com/lgug2z/diesel-autoincrement-new-struct","last_synced_at":"2025-05-14T03:33:02.842Z","repository":{"id":54249473,"uuid":"522104243","full_name":"LGUG2Z/diesel-autoincrement-new-struct","owner":"LGUG2Z","description":"Generate NewStructs for all your tables with autoincrementing IDs","archived":false,"fork":false,"pushed_at":"2022-08-07T22:44:51.000Z","size":4,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-09T11:27:58.405Z","etag":null,"topics":["database-schema","diesel-rs","orm","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/LGUG2Z.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}},"created_at":"2022-08-07T03:09:17.000Z","updated_at":"2023-08-29T21:33:42.000Z","dependencies_parsed_at":"2022-08-13T10:00:49.274Z","dependency_job_id":null,"html_url":"https://github.com/LGUG2Z/diesel-autoincrement-new-struct","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LGUG2Z%2Fdiesel-autoincrement-new-struct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LGUG2Z%2Fdiesel-autoincrement-new-struct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LGUG2Z%2Fdiesel-autoincrement-new-struct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LGUG2Z%2Fdiesel-autoincrement-new-struct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LGUG2Z","download_url":"https://codeload.github.com/LGUG2Z/diesel-autoincrement-new-struct/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225275675,"owners_count":17448389,"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":["database-schema","diesel-rs","orm","rust"],"created_at":"2024-11-19T00:58:35.360Z","updated_at":"2024-11-19T00:58:35.939Z","avatar_url":"https://github.com/LGUG2Z.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# diesel-autoincrement-new-struct\n\nStop copying and pasting structs with the `id` field removed just so you can\ninsert objects into tables with autoincrementing primary keys.\n\n## Motivation\n\nI mean really, who wants to do all that copying and pasting? Who wants to keep\nattributes and documentation in sync between two otherwise identical structs?\n\nThis whole idea came about after finding the excellent\n[`macro_rules_attribute`](https://github.com/danielhenrymantilla/macro_rules_attribute-rs)\ncrate by [Daniel Henry-Mantilla](https://github.com/danielhenrymantilla),\naka my personal Rust macro hero.\n\n## Example\n\n```rust\n#[macro_use]\nextern crate diesel_autoincrement_new_struct;\n\n// Alternatively, you can either import the prelude where needed:\n//\n// use diesel_increment_new_struct::prelude::*;\n//\n// Or even import apply and NewInsertable individually:\n//\n// use diesel_increment_new_struct::apply;\n// use diesel_increment_new_struct::NewInsertable;\n\nuse diesel::prelude::*;\n\ntable! {\n    users(id) {\n        id -\u003e Integer,\n        name -\u003e Text,\n    }\n}\n\n#[apply(NewInsertable!)]\n#[derive(Debug, Clone, Queryable, AsChangeset)]\n#[diesel(table_name = users)]\n/// This is a user\npub struct User {\n    /// This is the ID of the user\n    id: i32,\n    /// This is the name of the user\n    name: String\n}\n\n// The code below gets generated by `#[apply(NewInsertable!)]`\n\n#[derive(Debug, Clone, Queryable, AsChangeset)]\n#[derive(Insertable)]\n#[diesel(table_name = users)]\n/// This is a user\npub struct NewUser {\n    /// This is the name of the user\n    name: String\n}\n```\n\n## Notes\n\n- This crate doesn't re-export [Diesel](https://github.com/diesel-rs/diesel), so make sure you have `use diesel::prelude::*;` or `use diesel::Insertable;` in whichever files you use this macro\n- This crate requires at least whichever version or revision of Diesel where the `#[diesel(table_name = ...)]` attribute stopped taking a double quoted string\n\nThe `#[apply]` attribute should always be the topmost attribute above a struct,\nunless the struct that you want to use it on is also deriving `Identifiable`.\nIf that is the case, you should have that derive been the topmost attribute\nabove the struct so that it is excluded when generating the `NewStruct`, becuase\nobviously, without an `id`, it won't be `Identifiable`:\n\n```rust\n#[derive(Identifiable)]\n#[apply(NewInsertable!)]\n#[derive(Debug, Clone, Queryable, AsChangeset)]\n#[diesel(table_name = users)]\n/// This is a user\npub struct User {\n    /// This is the ID of the user\n    id: i32,\n    /// This is the name of the user\n    name: String\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flgug2z%2Fdiesel-autoincrement-new-struct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flgug2z%2Fdiesel-autoincrement-new-struct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flgug2z%2Fdiesel-autoincrement-new-struct/lists"}