Ulid mapping for diesel-rs. This crate contains custom mapping for the Ulid
implementation from rusty-ulid to diesel::sql_types::Uuid. With this adapter you can use these types in Diesel as regular Postgres UUID type.
cargo add diesel-ulid
or add:
diesel-ulid = 0.1.0
to your Cargo.toml
.
This is an adaptation of the Getting started section from diesel-rs.
Assuming you have the following schema.rs
file:
```rust
diesel::table! { posts (id) { id -> Uuid, title -> Varchar, body -> Text, published -> Bool, } } ```
you could use diesel-ulid as follows:
```rust use diesel::prelude::*; use diesel-ulid::DieselUlid;
pub struct Post { pub id: DieselUlid, pub title: String, pub body: String, pub published: bool, } ```
The Postgres UUID will be automatically mapped to a corresponding Ulid and vice-versa. This works because UUID and Ulid are both represented as 16 byte (128 bit) data struct.
Licensed under either of
at your option.
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.