stateless@pg_once

v0.1.0Created a year agoBy stateless

pg_once

pg_once is a lightweight PostgreSQL extension that adds run‑once / idempotency‑key semantics with a default 24‑hour TTL and optional JSON response caching.

Quick install (dbdev client)

select dbdev.install('pg_once');
create extension pg_once version '0.1.0';

API

FunctionPurpose
pg_once_start(key text, resource text, ttl interval default '24 hours') → jsonbReserve or check an idempotency key.
pg_once_commit(key text, response jsonb)Mark the key as completed and cache a response.
pg_once_fail(key text)Mark the key as failed.
pg_once_cleanup() → integerPurge expired keys (TTL).

Example

-- Reserve key
select pg_once_start('order#42', 'orders') \gset

\if :pg_once_start_status = 'accepted'
  -- do work here ...
  select pg_once_commit('order#42', '{"ok":true}'::jsonb);
\endif

License

MIT

Install

  1. Install the dbdev CLI
  2. Generate migration:
dbdev add -o ./migrations -s extensions -v 0.1.0 package -n "stateless@pg_once"

Downloads

  • 0 all time downloads
  • 0 downloads in the last 30 days
  • 0 downloads in the last 90 days
  • 0 downloads in the last 180 days