Copyright(c) digitally induced GmbH 2020
Safe HaskellNone





watchInsertOrUpdateTable :: (?modelContext :: ModelContext) => ByteString -> IO () -> IO (Async ()) Source #

Calls a callback every time something is inserted, updated or deleted in a given database table.

In the background this function creates a database trigger to notify this function about table changes using pg_notify. When there are existing triggers, it will silently recreate them. So this will most likely not fail.

This function returns a Async. Call cancel on the async to stop watching the database.


watchInsertOrUpdateTable "projects" do
    putStrLn "Something changed in the projects table"

Now insert something into the projects table. E.g. by running make psql and then running INSERT INTO projects (id, name) VALUES (DEFAULT, 'New project'); You will see that "Something changed in the projects table" is printed onto the screen.

createNotificationTrigger :: ByteString -> ByteString Source #

Returns the sql code to set up a database trigger. Mainly used by watchInsertOrUpdateTable.

eventName :: ByteString -> ByteString Source #

Returns the event name of the event that the pg notify trigger dispatches