{"id":18044638,"url":"https://github.com/pickfire/diesel-upsert","last_synced_at":"2025-08-20T12:45:21.273Z","repository":{"id":86155380,"uuid":"345691274","full_name":"pickfire/diesel-upsert","owner":"pickfire","description":"diesel upsert experiment","archived":false,"fork":false,"pushed_at":"2021-03-09T11:04:42.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T03:27:21.158Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/pickfire.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}},"created_at":"2021-03-08T14:52:38.000Z","updated_at":"2021-03-09T11:04:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"ebf98fa6-817a-47ab-953b-266bdd7fed80","html_url":"https://github.com/pickfire/diesel-upsert","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pickfire/diesel-upsert","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pickfire%2Fdiesel-upsert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pickfire%2Fdiesel-upsert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pickfire%2Fdiesel-upsert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pickfire%2Fdiesel-upsert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pickfire","download_url":"https://codeload.github.com/pickfire/diesel-upsert/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pickfire%2Fdiesel-upsert/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271321423,"owners_count":24739472,"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","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2024-10-30T18:10:01.927Z","updated_at":"2025-08-20T12:45:21.214Z","avatar_url":"https://github.com/pickfire.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"Diesel upsert experiment\n========================\n\nPrevious: https://github.com/pickfire/diesel-join-not-exist\nNext: https://github.com/pickfire/diesel-group-by\n\nThis time it requires diesel-git which isn't released.\n\nRust not able to recommend `users::table` when `hello::schema::users` is used\neven though it is a relative re-export.\n\n`on_conflict` gets runtime error instead of compile-time error when non\nprimary key or unique key is used. TODO\n\nI was wondering how upsert could be done but is still surprised that all these\ncould be made type-safe although there are a little bit of edge cases not being\ncovered.\n\nThe example I tested out here have 3 struct (based on the previous ones).\nsqlite was used for easy testing.\n\n    +---------+     +---------+     +---------+\n    | User    |\u003c-+  | Post    |     | Comment |\n    +---------+  |  +---------+     +---------+\n    | id      |  |  | id      |     | id      |\n    | name    |  |  | title   |     | body    |\n    |         |  |  | body    |\u003c----+ post_id |\n    |         |  |  | user_id +--+--+ user_id |\n    +---------+  |  +---------+  |  +---------+\n                 +---------------+\n\nI want to find all posts that does not have any comments. The query,\n\n```rust\nlet query = diesel::insert_into(users)\n    .values(\u0026user)\n    .on_conflict(id)\n    .do_update()\n    .set(name.eq(excluded(name)));\n```\n\nWhich results in the SQL query,\n\n```sql\nINSERT INTO `users` (`id`, `name`)\nVALUES (?, ?)\n   ON CONFLICT (`id`)\n   DO UPDATE SET `name` = excluded.`name` -- binds: [2, \"John\"]\n```\n\n## Get started\n\nRust, diesel_cli (with `sqlite` feature) is required.\n\n```\n$ diesel migration run\n$ cargo run --bin init  # populate database\n$ cargo run --bin hello  # multi join query\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpickfire%2Fdiesel-upsert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpickfire%2Fdiesel-upsert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpickfire%2Fdiesel-upsert/lists"}