hn.today

Introducing Temporal Resources | Ash Framework

ash-hq.org9 points1 comments
Screenshot of Introducing Temporal Resources | Ash Framework

Temporal resources are an experimental feature for Ash that makes time-aware data trivial to use: add a temporal block with a valid_at period and the framework exposes a single as_of option that lets reads, writes, filters, relationships, aggregates and calculations operate as of any instant (including the future) without rewriting normal application code. Examples use a collaborative pixel canvas where painting actions become time-scoped rows; passing as_of returns the canvas at that moment, writing with as_of inserts history or schedules future changes, related loads and aggregates respect the same moment, and calculations like now()/ago() are evaluated relative to the requested instant. Temporal inline mode for AshPaperTrail records change metadata on each temporal row so history can be loaded without separate version tables.

Under the hood it leverages PostgreSQL application-time periods (tstzrange) and primary keys declared WITHOUT OVERLAPS so each record is represented by contiguous, non-overlapping periods and writes split periods rather than overwrite rows. The design follows SQL:2011 FOR PORTION OF semantics; until that SQL form is available in Postgres, AshPostgres simulates it by locking, splitting ranges and retrying if concurrent transactions interfere. That simulation requires PostgreSQL 18+, includes a retry loop capped at 25 attempts and can emit a new deadlock-like error in rare contention cases, so the feature remains experimental with known sharp edges.

Read on ash-hq.org1 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Web

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.