Copyright(c) digitally induced GmbH 2020
Safe HaskellNone

IHP.PGNotify

Description

 
Synopsis

Documentation

watchInsertOrUpdateTable :: (?modelContext :: ModelContext) => Text -> 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.

Example:

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 :: Text -> Text Source #

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

eventName :: Text -> Text Source #

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