#ulid #uuid #identifier #sortable

diesel-ulid

Diesel-rs & tokio_postgres adapter for Ulid (rusty-ulid) to Postgres UUIDs

8 releases

0.3.2 Jul 9, 2024
0.3.1 Aug 25, 2023
0.3.0 Jul 27, 2023
0.2.0 Jul 10, 2023
0.1.3-rc.1 Apr 13, 2023

#318 in Database interfaces

Download history 105/week @ 2024-07-28 2/week @ 2024-08-04 9/week @ 2024-08-11 4/week @ 2024-09-15 29/week @ 2024-09-22 54/week @ 2024-09-29 30/week @ 2024-10-06 32/week @ 2024-10-13 71/week @ 2024-10-20 49/week @ 2024-10-27 49/week @ 2024-11-03

216 downloads per month
Used in 2 crates

MIT/Apache

19KB
345 lines

Rust License CI Codecov docs.rs Dependency status Safety Dance


diesel-ulid

Ulid mapping for diesel-rs and . 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 and tokio_postgres as regular Postgres UUID type.

Import

cargo add diesel-ulid

or add:

diesel-ulid = 0.3.1

to your Cargo.toml. While this crate was iniated for diesel-rs it can also be used with the rust-postgres driver. You can use the postgres or diesel feature to enable the corresponding adapter.

Usage

This is an adaptation of the Getting started section from diesel-rs.

Assuming you have the following schema.rs file:


diesel::table! {
    posts (id) {
        id -> Uuid,
        title -> Varchar,
        body -> Text,
        published -> Bool,
    }
}

you could use diesel-ulid as follows:

use diesel::prelude::*;
use diesel_ulid::DieselUlid as Ulid;

#[derive(Queryable)]
pub struct Post {
    pub id: Ulid,
    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.

License

Licensed under either of

at your option.

Licensing

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.

Dependencies

~2.6–10MB
~93K SLoC