Dependencies
The code generated by Cornucopia has a few dependencies that you need to import into your project's Cargo.toml.
This section describes the role of each dependency. Dependencies come in three broad categories:
- Common required ones.
- Choosing between sync and async.
- Optional dependencies that extend Cornucopia's capabilities.
Required
- Postgres type utils:
postgres-typeswith thederivefeature enabled.
Choose one (sync or async)
Sync
- Client:
cornucopia_sync. - Driver:
postgres.
You can achieve synchronous connection pooling with r2d2-postgres without any special integration.
Async
- Client:
cornucopia_async. - Runtime:
tokio. - Driver:
tokio_postgres. - Async tools:
futures.
(Optional) Async connection pooling
Requires cornucopia_async's deadpool feature (enabled by default)
- Connection pool
deadpool-postgres.
(Optional) Extra types
You can enable additional support for additional PostgreSQL types by adding the corresponding crates and driver features.
| Crate | PostgreSQL | Rust | driver feature |
|---|---|---|---|
serde_json | Json JsonB | Value | with-serde_json-1 (*) |
time | Time Date Timestamp TimestampTZ | Date Time PrimitiveDateTime OffsetDateTime | with-time-0_3 |
uuid | Uuid | Uuid | with-uuid-1 |
eui48 | MacAddr | MacAddress | with-eui48-1 |
rust_decimal | Numeric | Decimal | (**) |
(*) In addition to the driver feature, the with-serde_json-1 feature must also be enabled on the Cornucopia client.
(**) Doesn't require any driver feature, but it does require enabling rust_decimal's db-postgres feature.
(Optional) Row serialization
serdewith thederivefeature enabled.
Full dependencies
The code block below shows what your dependencies might look like with every feature that async cornucopia supports enabled:
# Cargo.toml
[dependencies]
# Required
postgres-types = { version = "*", features = ["derive"] }
# Async
cornucopia_async = { version = "*", features = ["with-serde_json-1"] }
tokio = { version = "*", features = ["full"] }
tokio-postgres = { version = "*", features = [
"with-serde_json-1",
"with-time-0_3",
"with-uuid-1",
"with-eui48-1",
] }
futures = "*"
# Async connection pooling
deadpool-postgres = { version = "*" }
# Row serialization
serde = { version = "*", features = ["derive"] }
# Extra types
serde_json = "*"
time = "*"
uuid = "*"
eui48 = "*"
rust_decimal = { version = "*", features = ["db-postgres"] }
If you're generating sync code, your dependencies will look a bit different but this should give you a rough idea.
You should use numbered instead of wildcard * dependency versions, this is only for demonstration purposes. You can refer to the crate's examples if you're not sure which versions to use.