cornucopia 0.8.1

Generate type-checked Rust from your PostgreSQL queries.
Documentation

Cornucopia is a tool powered by 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.

The basic premise is thus to:

  1. Write your PostgreSQL queries.
  2. Use Cornucopia to generate Rust code.
  3. Use the generated code in your project.

Compared 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.

Here are some defining features:

  • SQL-first. Your SQL is the only source of truth. No intricate ORM.
  • Powerful query validation. Catch errors before runtime, with powerful (and pretty) diagnostics.
  • Supports custom user types (composites, domains, and enums) and one-dimensional arrays.
  • Sync and async driver support, with optional pooling.
  • Ergonomic non-allocating row mapping.
  • Granular type nullity control.
  • Available as a library and a CLI.

You can learn more about using Cornucopia by reading our book, or you can get a quickstart by looking at our examples.

MSRV

This crate uses Rust 2021 edition, which requires at least version 1.56.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.