Conversions to and from Postgres types.
This crate is used by the tokio-postgres
and postgres
crates. You normally don't need to depend directly on it
unless you want to define your own ToSql
or FromSql
definitions.
Derive
If the derive
cargo feature is enabled, you can derive ToSql
and FromSql
implementations for custom Postgres
types. Explicitly, modify your Cargo.toml
file to include the following:
[]
= { = "0.X.X", = ["derive"] }
Enums
Postgres enums correspond to C-like enums in Rust:
'Sad',
'Ok',
'Happy'
);
(
#
use ;
#
Domains
Postgres domains correspond to tuple structs with one member in Rust:
= 16);
(octet_length(VALUE)
#
use ;
#
;
Newtypes
The #[postgres(transparent)]
attribute can be used on a single-field tuple struct to create a
Rust-only wrapper type that will use the [ToSql
] & [FromSql
] implementation of the inner
value :
#
use ;
#
;
Composites
Postgres composite types correspond to structs in Rust:
TEXT,
supplier_id INT,
price DOUBLE PRECISION
);
(
name
#
use ;
#
Naming
The derived implementations will enforce exact matches of type, field, and variant names between the Rust and
Postgres types. The #[postgres(name = "...")]
attribute can be used to adjust the name on a type, variant, or
field:
'sad',
'ok',
'happy'
);
(
#
use ;
#