cornucopia
Cornucopia is a Rust code generator that creates type-safe database interfaces from PostgreSQL queries at compile time. It validates queries against a live database and produces a separate Rust crate with strongly-typed wrappers, eliminating SQL errors before deployment.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | cornucopia-rs/cornucopia |
| Owner | cornucopia-rs |
| Primary language | Rust |
| License | Apache-2.0 — OSI-approved |
| Stars | 1.1k |
| Forks | 71 |
| Open issues | 28 |
| Latest release | cornucopia-v1.0.0 (2026-05-20) |
| Last updated | 2026-06-25 |
| Source | https://github.com/cornucopia-rs/cornucopia |
What cornucopia is
Cornucopia performs compile-time validation of raw SQL queries against a PostgreSQL instance, then generates type-checked Rust bindings with support for custom types, arrays, and enums. It produces native Rust code compatible with sync/async patterns and connection pools, with performance parity to hand-written rust-postgres.
Get the cornucopia source
Clone the repository and explore it locally.
git clone https://github.com/cornucopia-rs/cornucopia.gitcd cornucopia# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Requires a live PostgreSQL database accessible during code generation; plan CI/CD pipeline accordingly to provision or mock the database.
- Generated code lives in a separate crate that must be kept in sync with SQL definitions; establish a workflow for regenerating when queries change.
- Version 1.0 merged significant codegen rewrites from the Clorinde fork; upgrading from 0.9.x requires migration. Review the migration guide and test thoroughly.
- SQL annotations (comments like `--! query_name`) are mandatory; ensure your SQL files follow the exact syntax or code generation will fail.
- Custom type mappings must be configured in the tool; standard types work out-of-the-box, but domain-specific types need explicit Rust struct definitions.
When to avoid it — and what to weigh
- Non-PostgreSQL Databases Required — Cornucopia is PostgreSQL-only. If you need MySQL, SQLite, or other RDBMS support, this tool will not fit.
- Schema-First or Dynamic Query Patterns — The tool requires static SQL queries known at code-generation time. Highly dynamic query construction or schema discovery patterns are unsupported.
- Live Database Availability During Build — Cornucopia must connect to a PostgreSQL instance during the code generation phase. CI/CD pipelines without database access will require workarounds.
- Minimal Overhead / Constraint on Dependencies — Adding a generated crate and its dependencies increases build complexity and binary size. If you need minimal deps, consider lightweight query builders instead.
License & commercial use
Licensed under Apache-2.0 and MIT dual licensing. Both are permissive OSI-approved licenses with clear terms.
Commercial use is permitted under both Apache-2.0 and MIT. No restrictions on proprietary or closed-source projects using the generated code. Contributions must follow dual-license terms per the Apache-2.0 CLA.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Strong |
| License clarity | Clear |
| Deployment complexity | Moderate |
| DEV.co fit | Good |
| Assessment confidence | High |
Cornucopia itself does not execute SQL; it parses and validates against a database. The generated code uses rust-postgres, which handles parameterized queries and prepared statements. Security depends on (1) using the tool correctly (parameterized queries, not string interpolation), (2) the security posture of the PostgreSQL instance used during code generation, and (3) proper management of database credentials in CI/CD. No known CVEs noted in provided data, but a security audit was not performed for this review.
Alternatives to consider
sqlc (Go)
Language-agnostic SQL-to-code generator with broader database support (PostgreSQL, MySQL, SQLite). Better if you use multiple languages or need non-Postgres databases.
Diesel (Rust ORM)
Rust-native, type-safe, with query builder DSL and migration system. Choose if you prefer ORM abstraction and don't need raw SQL control.
sqlx (Rust async/sync)
Lightweight, runtime-checked (not compile-time), works with async/sync. Good fit if you want less build-time complexity and can tolerate runtime validation.
Build on cornucopia with DEV.co software developers
Cornucopia bridges SQL and Rust type systems. Start with the book and examples, then plan your code-generation workflow. For guidance on integration into your CI/CD and schema evolution strategy, consult a Rust specialist.
Talk to DEV.coRelated on DEV.co
Explore the category and the services that help you build with it.
cornucopia FAQ
Can I use Cornucopia with MySQL or SQLite?
Do I need to install PostgreSQL to use generated Cornucopia code?
What happens if my database schema changes?
Is the generated code readable and modifiable?
Custom software development services
DEV.co is a software development agency delivering custom software development services to companies building on open source. Our software developers and web developers design, integrate, and ship production systems — spanning web development, APIs, AI, data, and cloud. If cornucopia is part of your open-source databases roadmap, our team can implement, customize, migrate, and maintain it.
Ready to add compile-time SQL safety to your Rust project?
Cornucopia bridges SQL and Rust type systems. Start with the book and examples, then plan your code-generation workflow. For guidance on integration into your CI/CD and schema evolution strategy, consult a Rust specialist.