postgrest-ws- PostgREST extension to map LISTEN/NOTIFY messages to Websockets

Safe HaskellNone



This module provides a function to produce a Multiplexer from a Hasql Connection. The producer issues a LISTEN command upon Open commands and UNLISTEN upon Close.



newHasqlBroadcaster :: Connection -> IO Multiplexer Source #

Returns a multiplexer from a connection, listen for different database notification channels using that connection.

To listen on channels *chat*

  import Protolude
  import PostgRESTWS.HasqlBroadcast
  import PostgRESTWS.Broadcast
  import Hasql.Connection

  main = do
   conOrError <- H.acquire "postgres:/localhosttest_database"
   let con = either (panic . show) id conOrError :: Connection
   multi <- newHasqlBroadcaster con

   onMessage multi "chat" (ch ->
     forever $ fmap print (atomically $ readTChan ch)

acquire :: Settings -> IO (Either ConnectionError Connection) #

Acquire a connection using the provided settings encoded according to the PostgreSQL format.

relayMessages :: Multiplexer -> IO () Source #

Reads the messages from the producer and relays them to the active listeners in their respective channels.

relayMessagesForever :: Multiplexer -> IO ThreadId Source #

Opens a thread that relays messages from the producer thread to the channels forever