Time and IDs

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

#ids#database#keys

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() → str

A new ULID, such as 01JBQ8E3X4ZK7M2N9P5R6S8T0V: later ones sort after earlier ones.

ulid_at(ms: int) → str

A ULID for a given time, in milliseconds since 1970 (as now() gives), for back-filling old rows.

ulid_time(id: str) → intor an error

When a ULID was made, in milliseconds since 1970.

ulid_valid(id: str) → bool

Whether id is a ULID.

Get it

$ quillo install ulid               # ulid.qwer into this folder$ quillo install ulid --example     # and its example, ulid.qwe

Or with curl:

$ curl -O https://quillolang.org/plugins/files/ulid.qwer$ curl -O https://quillolang.org/plugins/files/ulid.qwe

Then, in your program, all of it or only what you call:

main.qwe
use ulid.qweruse ulid, ulid_at from ulid      // Quillo 0.6: only these

It uses this crate, which cargo fetches the first time the plugin is built:

[dependencies]
ulid = "1"

Example

ulid.qwe
// 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

ulid.qwer
//! 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()}
Thread
88Useful? Like it, or add to its thread below.

Thread 0 posts

On ULIDs: questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.