module Database.PostgreSQL.PQTypes.Notification (
Channel(..)
, Notification(..)
, listen
, unlisten
, unlistenAll
, notify
) where
import Data.Text (Text)
import Prelude
import Data.Monoid.Utils
import Database.PostgreSQL.PQTypes.Class
import Database.PostgreSQL.PQTypes.Internal.Notification
import Database.PostgreSQL.PQTypes.SQL.Raw
import Database.PostgreSQL.PQTypes.Utils
listen :: MonadDB m => Channel -> m ()
listen (Channel chan) = runQuery_ $ "LISTEN" <+> chan
unlisten :: MonadDB m => Channel -> m ()
unlisten (Channel chan) = runQuery_ $ "UNLISTEN" <+> chan
unlistenAll :: MonadDB m => m ()
unlistenAll = runSQL_ "UNLISTEN *"
notify :: MonadDB m => Channel -> Text -> m ()
notify (Channel chan) payload = runQuery_
$ rawSQL "SELECT pg_notify($1, $2)" (unRawSQL chan, payload)