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
8 changes: 4 additions & 4 deletions postgres-websockets.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ library
, bytestring >= 0.11.5 && < 0.13
, either >= 5.0.1.1 && < 5.1
, envparse >= 0.5.0 && < 0.7
, hasql >= 1.9 && < 1.10
, hasql >= 1.10 && < 1.20
, hasql-notifications >= 0.2.4.0 && < 0.3
, hasql-pool ^>= 1.3
, hasql-pool ^>= 1.4
, http-types >= 0.12.3 && < 0.13
, jose >= 0.11 && < 0.13
, lens >= 5.2.3 && < 5.4
Expand Down Expand Up @@ -94,8 +94,8 @@ test-suite postgres-websockets-test
, postgres-websockets
, hspec >= 2.7.1 && < 2.12
, aeson >= 2.0 && < 2.3
, hasql >= 1.9 && < 1.10
, hasql-pool ^>= 1.3
, hasql >= 1.10 && < 1.20
, hasql-pool ^>= 1.4
, hasql-notifications >= 0.2.4.0 && < 0.3
, http-types >= 0.9
, time >= 1.8.0.2 && < 2
Expand Down
5 changes: 2 additions & 3 deletions src/PostgresWebsockets/Context.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import Control.AutoUpdate
import Data.Time.Clock (UTCTime, getCurrentTime)
import qualified Hasql.Pool as P
import qualified Hasql.Pool.Config as P
import qualified Hasql.Connection.Setting as C
import qualified Hasql.Connection.Setting.Connection as C
import qualified Hasql.Connection.Settings as C
import PostgresWebsockets.Broadcast (Multiplexer)
import PostgresWebsockets.Config (AppConfig (..))
import PostgresWebsockets.HasqlBroadcast (newHasqlBroadcaster)
Expand All @@ -37,7 +36,7 @@ mkContext conf@AppConfig {..} shutdownServer = do
<*> newHasqlBroadcaster shutdown configListenChannel configRetries configReconnectInterval pgSettings
<*> mkGetTime
where
config = P.settings [P.staticConnectionSettings [C.connection $ C.string $ decodeUtf8 pgSettings]]
config = P.settings [P.staticConnectionSettings $ C.connectionString $ decodeUtf8 pgSettings]
shutdown =
maybe
shutdownServer
Expand Down
12 changes: 6 additions & 6 deletions src/PostgresWebsockets/HasqlBroadcast.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import Data.Aeson (Value (..), decode)
import qualified Data.Aeson.Key as Key
import qualified Data.Aeson.KeyMap as JSON
import Data.Either.Combinators (mapBoth)
import Hasql.Connection (Connection, ConnectionError)
import Hasql.Connection (Connection)
import Hasql.Errors (ConnectionError)
import qualified Hasql.Connection as HC
import qualified Hasql.Connection.Setting as HC
import qualified Hasql.Connection.Setting.Connection as HC
import qualified Hasql.Connection.Settings as HC
import qualified Hasql.Decoders as HD
import qualified Hasql.Encoders as HE
import Hasql.Notifications
Expand All @@ -33,7 +33,7 @@ import qualified Hasql.Statement as H
import PostgresWebsockets.Broadcast

acquire :: ByteString -> IO (Either ConnectionError Connection)
acquire settings = HC.acquire [HC.connection $ HC.string $ decodeUtf8 settings]
acquire settings = HC.acquire $ HC.connectionString $ decodeUtf8 settings
-- | Returns a multiplexer from a connection URI, keeps trying to connect in case there is any error.
-- This function also spawns a thread that keeps relaying the messages from the database to the multiplexer's listeners
newHasqlBroadcaster :: IO () -> Text -> Int -> Maybe Int -> ByteString -> IO Multiplexer
Expand Down Expand Up @@ -122,15 +122,15 @@ newHasqlBroadcasterForChannel onConnectionFailure ch checkInterval getCon = do

isListening :: Connection -> Text -> IO Bool
isListening con ch = do
resultOrError <- H.run session con
resultOrError <- HC.use con session
pure $ fromRight False resultOrError
where
session = H.statement chPattern isListeningStatement
chPattern = "listen%" <> ch <> "%"

isListeningStatement :: H.Statement Text Bool
isListeningStatement =
H.Statement sql encoder decoder True
H.preparable sql encoder decoder
where
sql = "select exists (select * from pg_stat_activity where datname = current_database() and query ilike $1);"
encoder = HE.param $ HE.nonNullable HE.text
Expand Down
Loading