diesel-derive-enum
This crate allows one to automatically derive the Diesel boilerplate necessary to use Rust enums directly with Postgres databases.
It is a fairly literal translation of this code from the Diesel test suite.
Example usage:
// define your enum
// This is the name of the type within the database
// define your table
table!
// define a struct with which to populate/query the table
SQL to create corresponding table:
'foo', 'bar', 'baz_quxx');
-- Note: the postgres ENUM values must correspond to snake_cased Rust enum variant names
(
id SERIAL PRIMARY KEY,
my_enum my_type NOT NULL
);
(
Now we can insert and retrieve MyEnum directly:
let data = vec!;
let connection = establish.unwrap;
let inserted = insert_into
.values
.get_results
.unwrap;
assert_eq!;
See this test for a full working example.
License
Licensed under either of these:
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)