{"id":13502915,"url":"https://github.com/cornucopia-rs/cornucopia","last_synced_at":"2025-05-14T23:02:39.004Z","repository":{"id":36976742,"uuid":"478045535","full_name":"cornucopia-rs/cornucopia","owner":"cornucopia-rs","description":"Generate type-checked Rust from your PostgreSQL.","archived":false,"fork":false,"pushed_at":"2024-08-20T14:17:21.000Z","size":1704,"stargazers_count":958,"open_issues_count":69,"forks_count":54,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-15T01:57:21.158Z","etag":null,"topics":["database","postgres","postgresql","rust","sql"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cornucopia-rs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2022-04-05T08:49:03.000Z","updated_at":"2025-04-12T10:08:15.000Z","dependencies_parsed_at":"2024-06-29T09:48:39.538Z","dependency_job_id":"b944a044-330c-4524-aa23-fd42d6debfc8","html_url":"https://github.com/cornucopia-rs/cornucopia","commit_stats":{"total_commits":565,"total_committers":8,"mean_commits":70.625,"dds":"0.40176991150442476","last_synced_commit":"50987297f68b9d4db3f110960aa5f970d47337ea"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornucopia-rs%2Fcornucopia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornucopia-rs%2Fcornucopia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornucopia-rs%2Fcornucopia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornucopia-rs%2Fcornucopia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cornucopia-rs","download_url":"https://codeload.github.com/cornucopia-rs/cornucopia/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243354,"owners_count":22038045,"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","postgres","postgresql","rust","sql"],"created_at":"2024-07-31T22:02:29.976Z","updated_at":"2025-05-14T23:02:38.885Z","avatar_url":"https://github.com/cornucopia-rs.png","language":"Rust","readme":"\u003cdiv align=\"center\"\u003e \u003cimg src=\"https://raw.githubusercontent.com/cornucopia-rs/cornucopia/main/assets/logo.svg\" width=200 /\u003e \u003c/div\u003e\n\u003ch1 align=\"center\"\u003eCornucopia\u003c/h1\u003e\n\u003cdiv align=\"center\"\u003e\n \u003cstrong\u003e\n   Generate type-checked  Rust from your SQL\n \u003c/strong\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003c!-- Downloads --\u003e\n  \u003ca href=\"https://crates.io/crates/cornucopia\"\u003e\n    \u003cimg src=\"https://img.shields.io/crates/d/cornucopia.svg?style=flat-square\"\n      alt=\"Download\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- Version --\u003e\n  \u003ca href=\"https://crates.io/crates/cornucopia\"\u003e\n    \u003cimg src=\"https://img.shields.io/crates/v/cornucopia.svg?style=flat-square\"\n    alt=\"Crates.io version\" /\u003e\n  \u003c/a\u003e\n\n  \u003c!-- Book --\u003e\n  \u003ca href=\"https://cornucopia-rs.netlify.app/book/index.html\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/book-latest-blue?logo=mdbook\u0026style=flat-square\" alt=\"book\"\u003e\n  \u003c/a\u003e\n\n  \u003c!-- Docs --\u003e\n  \u003ca href=\"https://docs.rs/cornucopia/latest/cornucopia/\"\u003e\n    \u003cimg alt=\"docs.rs\" src=\"https://img.shields.io/docsrs/cornucopia?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \n  \u003c!-- Dependencies --\u003e\n  \u003ca href=\"https://deps.rs/repo/github/cornucopia-rs/cornucopia\"\u003e\n    \u003cimg src=\"https://deps.rs/repo/github/cornucopia-rs/cornucopia/status.svg?style=flat-square\"\n    alt=\"Crates.io version\" /\u003e\n  \u003c/a\u003e\n \n  \u003cbr/\u003e\n\n  \u003c!-- License --\u003e\n  \u003ca href=\"https://github.com/cornucopia-rs/cornucopia#License\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/License-APACHE--2.0%2FMIT-blue?style=flat-square\" alt=\"License\"\u003e\n  \u003c/a\u003e\n\n  \u003c!-- Chat --\u003e\n  \u003ca href=\"https://discord.gg/nYwUmQDHBZ\"\u003e\n    \u003cimg src=\"https://img.shields.io/discord/987088069280825401?label=chat\u0026logo=discord\u0026style=flat-square\" alt=\"Chat\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ch4\u003e\n    \u003ca href=\"https://cornucopia-rs.netlify.app/\"\u003e\n      Homepage\n    \u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"examples/basic_async/README.md\"\u003e\n      Example\n    \u003c/a\u003e\n  \u003c/h4\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\nCornucopia is a tool powered by [`rust-postgres`](https://github.com/sfackler/rust-postgres) designed to generate type-checked Rust interfaces from your PostgreSQL queries. It works by preparing your queries against an actual database and then running an extensive validation suite on them. Once the queries are prepared and validated, Rust code is generated into a module, which can be imported and used in your project. \n\nThe basic premise is thus to:\n1. Write your PostgreSQL queries.\n2. Use Cornucopia to generate Rust code.\n3. Use the generated code in your project.\n\nCompared to other Rust database interfaces, Cornucopia's approach has the benefits of being simple to understand while also generating code that is both ergonomic and free of heavy macros or complex generics. Since Cornucopia generates plain Rust structs, you can also easily build upon the generated items.\n\nHere are some defining features:\n* SQL-first. Your SQL is the only source of truth. No intricate ORM.\n* Powerful query validation. Catch errors before runtime, with powerful (and pretty) diagnostics.\n* Supports custom user types (composites, domains, and enums) and one-dimensional arrays.\n* Sync and async driver support, with optional pooling.\n* Ergonomic non-allocating row mapping.\n* Granular type nullity control.\n* Available as a library and a CLI.\n* As close to native `rust-postgres` performance as we can make it.\n\nYou can learn more about using Cornucopia by reading our [book](https://cornucopia-rs.netlify.app/book/index.html), or you can get a quickstart by looking at our [examples](https://cornucopia-rs.netlify.app/book/examples.html).\n\n## A quick taste of Cornucopia\nThe [book](https://cornucopia-rs.netlify.app/book/index.html) is the place to go to get more in-depth explanations, but here is the simplest of tasters to give you an idea.\n\nLet's say you have the following PostgreSQL queries\n```sql\n-- queries/some_query_file.sql\n\n--! authors\nSELECT first_name, last_name, country FROM Authors;\n\n--! insert_author\nINSERT INTO Authors(first_name, last_name, country) \nVALUES (:first_name, :last_name, :country)\n```\nNotice the query annotations (`--! authors`, `--! insert_authors`) and the named bind parameters (`:first_name`, etc.).\n\nThen, after generating the Rust code with Cornucopia's CLI, you can import it into your project like so:\n```rust\nmod cornucopia;\nuse cornucopia::{authors, insert_author};\n```\n\nFinally here is an example usage of these queries:\n```rust\ninsert_author.bind(\u0026client, \"Agatha\", \"Christie\", \"England\");\n\nlet all_authors = authors().bind(\u0026client).all();\n\nfor author in all_authors {\n  println!(\"[{}] {}, {}\", \n    author.country, \n    author.last_name.to_uppercase(), \n    author.first_name\n  )\n}\n```\nYou can customize pretty much every aspect of your queries easily with Cornucopia (custom parameters and row structs, renaming, nullity control, etc.), so please head over to the [book](https://cornucopia-rs.netlify.app/book/index.html) if you're interested to learn more.\n\n## MSRV\nThis crate uses Rust 2021 edition, which requires at least version 1.62.1.\n\n## License\n\nLicensed under either of\n * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\nat your option.\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any\nadditional terms or conditions.\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcornucopia-rs%2Fcornucopia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcornucopia-rs%2Fcornucopia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcornucopia-rs%2Fcornucopia/lists"}