Diesel PGRX
Integration layer enabling Diesel ORM to work with custom Rust types defined in PGRX PostgreSQL extensions. The crate provides a derive macro that implements Diesel's serialization traits (ToSql and FromSql) using PGRX's binary protocol, which internally uses CBOR serialization via serde_cbor. This allows types decorated with PGRX's PostgresType and #[pg_binary_protocol] to be seamlessly queried through Diesel. Additional backend support includes SQLite using the same CBOR serialization format.
Usage
Add this to your Cargo.toml:
[]
= "0.1"
= { = "2.2", = ["postgres"] }
= { = "1.0", = ["derive"] }
After building your PGRX extension, install it in PostgreSQL:
CREATE EXTENSION your_extension;
Derive DieselPGRX for types that implement serde::Serialize and serde::Deserialize. The type must also use PGRX's PostgresType and pg_binary_protocol attributes:
Additional PGRX Derives
PGRX provides optional derives for comparison and hashing operations. When using these, implement the corresponding Rust traits:
Feature Flags
postgres(not default): Enables PostgreSQL backend support with binary protocol serializationsqlite(not default): Enables SQLite backend support using CBOR-encoded BINARY typepgrx: Used for documentation tests only
Note on serde_cbor
The serde_cbor crate is archived but remains the CBOR implementation used by PGRX. No known issues exist, and it will be used until PGRX adopts an alternative.