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-types with the derive feature enabled.

Choose one (sync or async)

Sync

  • Client: cornucopia_sync.
  • Driver: postgres.

Info

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.

CratePostgreSQLRustdriver feature
serde_jsonJson JsonBValuewith-serde_json-1 (*)
timeTime Date Timestamp TimestampTZDate Time PrimitiveDateTime OffsetDateTimewith-time-0_3
uuidUuidUuidwith-uuid-1
eui48MacAddrMacAddresswith-eui48-1
rust_decimalNumericDecimal(**)

(*) 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

  • serde with the derive feature 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.

Note

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.