PostgreSQL supports returning data from data manipulation queries (docs: https://www.postgresql.org/docs/current/dml-returning.html). The most interesting part is about retrieving the inserted row id, offering a race-free mechanism that is both lightweight and easy to use.
Pear DB has this concept of queries being either on the "read" or the "write" side, with distinct code paths handling responses and also a regex filter thrown in for good measure on the "read" side.
I'm not seeing any non-hacky ways myself to implement a way to handle this feature, but I suppose a discussion on the matter wouldn't hurt.