Isn't that exactly what "every database ever" calls triggers?
From the Postgres docs: http://www.postgresql.org/docs/9.4/static/trigger-definition...
> A trigger is a specification that the database should automatically execute a particular function whenever a certain type of operation is performed. Triggers can be attached to tables, views, and foreign tables.
Even NoSQL DB's like redis or riak have the ability to execute user-supplied Lua resp. Erlang.
http://docs.basho.com/riak/latest/dev/advanced/commit-hooks/