ULIDs
Unique ids that sort by when they were made: 26 characters, safe in URLs, good primary keys.
Version 1.0.0 · 4 functions · 1 crate
Functions
What use ulid.qwer gives a program, with the types Quillo sees. To take only some, or under other names: use ulid, ulid_at from ulid (Quillo 0.6).
ulid() → strA new ULID, such as 01JBQ8E3X4ZK7M2N9P5R6S8T0V: later ones sort after earlier ones.
ulid_at(ms: int) → strA ULID for a given time, in milliseconds since 1970 (as now() gives), for back-filling old rows.
ulid_time(id: str) → intor an errorWhen a ULID was made, in milliseconds since 1970.
ulid_valid(id: str) → boolWhether id is a ULID.
Get it
$ quillo install ulid # ulid.qwer into this folder$ quillo install ulid --example # and its example, ulid.qweOr with curl:
$ curl -O https://quillolang.org/plugins/files/ulid.qwer$ curl -O https://quillolang.org/plugins/files/ulid.qweThen, in your program, all of it or only what you call:
use ulid.qweruse ulid, ulid_at from ulid // Quillo 0.6: only theseIt uses this crate, which cargo fetches the first time the plugin is built:
ulid = "1"Example
// Orders keyed by ULIDs: newest first is simply the ids in reverse.//// quillo run ulid.qwe then open http://localhost:8080/idsuse "ulid.qwer"route GET /ids { let a = ulid() let old = ulid_at(1767225600000) // 2026-01-01 { new: a, made_ms: ulid_time(a)?, old, old_ms: ulid_time(old)?, sorted: sort([a, old]) == [old, a], valid: ulid_valid(a) }}$ quillo run ulid.qwe$ curl 'localhost:8080/ids'Source
//! ULIDs: unique ids that sort by the time they were made, 26 characters, safe in URLs, a good primary key.//! version: 1.0.0//!//! [dependencies]//! ulid = "1"use std::time::{Duration, UNIX_EPOCH};use ulid::Ulid;/// A new ULID, such as `01JBQ8E3X4ZK7M2N9P5R6S8T0V`: later ones sort after earlier ones.pub fn ulid() -> String { Ulid::new().to_string()}/// A ULID for a given time, in milliseconds since 1970 (as `now()` gives), for back-filling old rows.pub fn ulid_at(ms: i64) -> String { Ulid::from_datetime(UNIX_EPOCH + Duration::from_millis(ms.max(0) as u64)).to_string()}/// When a ULID was made, in milliseconds since 1970.pub fn ulid_time(id: &str) -> Result<i64, String> { let u = Ulid::from_string(id.trim()).map_err(|e| e.to_string())?; Ok(u.timestamp_ms() as i64)}/// Whether `id` is a ULID.pub fn ulid_valid(id: &str) -> bool { Ulid::from_string(id.trim()).is_ok()}Related
cuid2.qwer · 1.0.0CUID2 ids: secure, collision-resistant, starting with a letter, of the length you choose, that give away neither the time nor a count; and a check that a string is one.7 views · 7 downloadsKSUID ksuid.qwer · 1.0.0KSUIDs, Segment's K-Sortable Unique IDs: 27 base62 characters sorted by the second they were made, with 128 random bits; made, read back and checked.8 views · 7 downloadsShort ids short_ids.qwer · 1.0.0Short ids for URLs made from your database's numbers and read back (Sqids): your own alphabet, a minimum length, no rude words, and typos never reaching another row.6 views · 8 downloadsSnowflake ids snowflake.qwer · 1.0.0Snowflake ids: 64-bit numbers that sort by time, unique across 1,024 servers with no coordination, with their time, server and sequence read back and the first id of a time for range queries.7 views · 7 downloadsTypeID typeid.qwer · 1.0.0TypeIDs such as user_01h455vb4pex5vsknk084sn02q: a type prefix and a UUIDv7 in base32, made, read back to their UUID and time, and checked against the type a URL expects.6 views · 7 downloadsUUID tools uuid_tools.qwer · 1.0.0UUIDs beyond the random uuid(): version 7 sorted by time for database keys, versions 5 and 3 that give the same id for the same name, and any UUID read with its version and time.7 views · 6 downloadsThread 0 posts
On ULIDs: questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.