#index #sorting #uuid #readable #oid #explode #double-click-copyable

oid2

An id schema that is compatible with uuid, lexicographcally sorted (won't explode database indexes), readable, and double-click-copyable

1 unstable release

0.1.0 Apr 15, 2023

#2132 in Database interfaces

MIT license

9KB
185 lines

oid

An id scheme. Why another one?

  • lexicographically sortable - uuidv4 is not sorted and will explode database indexes. Like ulid, oid is lexicographically sortable.
  • named - oid can be prefixed with a name, like team_0da0fa0e02cssbhkanf04c_srb0
  • short-codable - oid can be written in shortform like team_srb0
  • double-click-copyable - try double clicking this uuid: a827f03c-f5b0-40ef-8d53-3fb3cdf4e055. Then try this oid: team_0da0fa0e02cssbhkanf04c_srb0

Usage

label!(Team, "team");
label!(User, "usr");
label!(Transaction, "tx");

fn main() {
    let id = Team::oid();
    // e.g. id: team_0da0fa0e02cssbhkanf04c_srb0
    println!("id: {}", id);
    // e.g. id: team_srb0
    // e.g. uuid: a827f03c-f5b0-40ef-8d53-3fb3cdf4e055
    println!("short: {}", id.short());
    println!("uuid: {}", id.uuid());
    
    // We didn't use a Label, so it's simply missing.
    let id = new_oid();
    // e.g. id: 0da0fa0e02cssbhkanf04c_srb0
    println!("id: {}", id);
}

Roadmap

  • Create a postgres extension to store oids as u128, but have it display in human readable form.

Dependencies

~1–15MB
~187K SLoC