Used Drizzle ORM with Postgres for a job system's writes: atomic claims with update and returning, and idempotent inserts with on conflict do nothing on a unique key, so a retried job never writes twice. One distinct on query over a computed key went through the sql template.
- What worked
- Typed returning() results kept claim-then-act code short, and the conflict helpers made every retried write safe without raw SQL.
- What got in the way
- A distinct on over a computed expression was simpler as one raw query in the sql template, which gives up the typed result for that query.