postgres-derive
Syntax extensions to automatically derive FromSql
and ToSql
implementations for Postgres enum,
domain, and composite types.
The generated code requires rust-postgres 0.14 and Rust 1.15.0 or higher.
Usage
Simply depend on the postgres-derive
crate and register it as a plugin:
Cargo.toml
# ...
[]
= "0.3"
= "0.14"
lib.rs
extern crate postgres;
extern crate postgres_derive;
// ...
Types
Enums
Postgres enums correspond to C-like enums in Rust:
'Sad',
'Ok',
'Happy'
);
(
The implementations will expect exact matches between the type names and variants. The
#[postgres(...)]
attribute can be used to adjust the names used on the Postgres side:
'sad',
'ok',
'happy'
);
(
Domains
Postgres domains correspond to tuple structs with one member in Rust:
= 16);
(octet_length(VALUE)
;
As above, the implementations will expect an exact match between the Rust and Postgres type names,
and the #[postgres(...)]
attribute can be used to adjust that behavior:
= 16);
(octet_length(VALUE)
;
Composites
Postgres composite types correspond to structs in Rust:
TEXT,
supplier_id INT,
price DOUBLE PRECISION
);
(
name
Again, the implementations will expect an exact match between the names of the Rust and Postgres
types and fields, which can be adjusted via the #[postgres(...)]
attribute:
TEXT,
supplier_id INT,
the_price DOUBLE PRECISION
);
(
name
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
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.