Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import System.IO
import System.Exit (die)

import Hasql.Connection
import Hasql.Connection.Setting
import Hasql.Connection.Setting.Connection
import Hasql.Notifications

main :: IO ()
main = do
hSetBuffering stdout NoBuffering
hSetBuffering stderr NoBuffering

dbOrError <- acquire "postgres://localhost/db_name"
dbOrError <- acquire [ connection $ string "postgres://localhost/db_name" ]
case dbOrError of
Right db -> do
let channelToListen = toPgIdentifier "sample-channel"
listen db channelToListen
waitForNotifications (\channel _ -> print $ "Just got notification on channel " <> channel) db
_ -> die "Could not open database connection"

4 changes: 2 additions & 2 deletions hasql-notifications.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ library
build-depends: base >= 4.7 && < 5
, bytestring >= 0.10.8.2 && < 0.13
, text >= 2 && < 2.2
, hasql-pool >= 1.2 && < 1.3
, hasql-pool >= 1.3 && < 1.4
, postgresql-libpq >= 0.9 && < 1.0
, hasql >= 0.19 && < 1.9
, hasql >= 1.9 && < 1.10

default-language: Haskell2010
ghc-options: -Wall
Expand Down
8 changes: 6 additions & 2 deletions src/Hasql/Notifications.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ notify con channel mesg =
-- import System.Exit (die)
--
-- import Hasql.Connection
-- import Hasql.Connection.Setting
-- import Hasql.Connection.Setting.Connection
-- import Hasql.Notifications
--
-- main :: IO ()
-- main = do
-- dbOrError <- acquire "postgres://localhost/db_name"
-- dbOrError <- acquire [ connection $ string "postgres://localhost/db_name" ]
-- case dbOrError of
-- Right db -> do
-- let channelToListen = toPgIdentifier "sample-channel"
Expand Down Expand Up @@ -160,6 +162,8 @@ executeOrPanic cmd pqCon = do
-- import System.Exit (die)
--
-- import Hasql.Connection
-- import Hasql.Connection.Setting
-- import Hasql.Connection.Setting.Connection
-- import Hasql.Notifications
--
-- notificationHandler :: ByteString -> ByteString -> IO()
Expand All @@ -169,7 +173,7 @@ executeOrPanic cmd pqCon = do
--
-- main :: IO ()
-- main = do
-- dbOrError <- acquire "postgres://localhost/db_name"
-- dbOrError <- acquire [ connection $ string "postgres://localhost/db_name" ]
-- case dbOrError of
-- Right db -> do
-- let channelToListen = toPgIdentifier "sample-channel"
Expand Down
4 changes: 3 additions & 1 deletion test/Hasql/NotificationsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Control.Concurrent.MVar
import Control.Monad (void)
import Data.ByteString
import Hasql.Connection
import Hasql.Connection.Setting
import Hasql.Connection.Setting.Connection
import Hasql.Notifications
import System.Exit (die)
import Test.Hspec
Expand All @@ -20,7 +22,7 @@ spec = do
describe "send and receive notification" $
describe "when I send a notification to channel my handler is listening to" $
it "should call our notification handler" $ do
dbOrError <- acquire "postgres://postgres:roottoor@localhost/hasql_notifications_test"
dbOrError <- acquire [ connection $ string "postgres://postgres:roottoor@localhost/hasql_notifications_test"]
case dbOrError of
Right db -> do
let channelToListen = toPgIdentifier "test-channel"
Expand Down
Loading