Reputation: 1116
Given the websockets example how can I have Handler
related operations such as runDB
inside (e.g. runDB $ selectList ...
)
Here's a non working example of what I want to do:
chatStream :: WebSocketsT Handler ()
chatStream = do
users <- liftIO $ runDB $ selectList [] [] :: Handler [Entity User] -- This line is not working
sendTextData ("Welcome to the chat server, please enter your name." :: Text)
-- ....
Here's the error:
Couldn't match type ‘HandlerT App IO [Entity User]’
with ‘ReaderT
websockets-0.9.7.0:Network.WebSockets.Connection.Connection
Handler
t0’
Expected type: ReaderT
websockets-0.9.7.0:Network.WebSockets.Connection.Connection
Handler
t0
Actual type: Handler [Entity User]
In a stmt of a 'do' block:
users <- liftIO $ runDB $ selectList [] [] :: Handler [Entity User]
Upvotes: 2
Views: 85
Reputation: 1116
The answer is to use lift
and not liftIO
users <- lift $ (runDB $ selectList [] [] :: Handler [Entity User])
Upvotes: 1