Skip to content

Instantly share code, notes, and snippets.

@begriffs
Created January 24, 2016 08:20
Show Gist options
  • Select an option

  • Save begriffs/c632b5e3abe0984d2483 to your computer and use it in GitHub Desktop.

Select an option

Save begriffs/c632b5e3abe0984d2483 to your computer and use it in GitHub Desktop.
another situation that causes the command in progress error
module Lib
( someFunc
) where
import Control.Monad
import Data.Int
import Data.Monoid
import Data.Functor.Contravariant
import Hasql.Connection
import Hasql.Session
import Hasql.Query
import qualified Hasql.Decoders as HD
import qualified Hasql.Encoders as HE
someFunc :: IO ()
someFunc = void $
acquire "postgres://j@localhost:5432/demo1" >>= \case
Left err -> error $ show err
Right c -> do
print =<< run txSum c
run (sql "RAISE division_by_zero;") c
print =<< run txSum c
txSum :: Session Int64
txSum = do
sql "begin;"
s <- query (1,1) selectSum
sql "end;"
return s
selectSum :: Query (Int64, Int64) Int64
selectSum =
statement sql encoder decoder True
where
sql = "select ($1 + $2)"
encoder =
contramap fst (HE.value HE.int8) <>
contramap snd (HE.value HE.int8)
decoder =
HD.singleRow (HD.value HD.int8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment