Skip to content

Instantly share code, notes, and snippets.

@tfausak
Last active October 25, 2017 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfausak/bdafb1184c72680f255e91d4a9a52848 to your computer and use it in GitHub Desktop.
Save tfausak/bdafb1184c72680f255e91d4a9a52848 to your computer and use it in GitHub Desktop.
import qualified Data.Text
import qualified Data.Text.Encoding
import qualified Hasql.Batch
import qualified Hasql.Connection
import qualified Hasql.DecodeResult
import qualified Hasql.Statement
main :: IO ()
main = do
let utf8 = Data.Text.Encoding.encodeUtf8 . Data.Text.pack
let host = utf8 "127.0.0.1"
let port = 5432
let settings = Hasql.Connection.TCPConnectionSettings host port
let username = utf8 "postgres"
let password = mempty
let database = Just (utf8 "postgres")
let handler = print
putStrLn "Connecting ..."
connectionResult <- Hasql.Connection.open settings username password database handler
connection <- case connectionResult of
Left problem -> fail (show problem)
Right connection -> pure connection
putStrLn "Connected."
let template = utf8 "select 1"
let encoder = mempty
let decoder = Hasql.DecodeResult.ignore
let statement = Hasql.Statement.prepared template encoder decoder
let batch = Hasql.Batch.statement statement ()
putStrLn "Querying ..."
-- This statement hangs forever.
sessionResult <- Hasql.Connection.batch connection batch
case sessionResult of
Left problem -> fail (show problem)
Right unit -> pure unit
putStrLn "Queried."
putStrLn "Closing ..."
Hasql.Connection.close connection
putStrLn "Closed."
name: hasql-example
version: 0.0.0
executables:
hasql-example:
dependencies:
- base
- hasql
- text
ghc-options:
- -rtsopts
- -threaded
- -Wall
main: Main.hs
resolver: ghc-8.2.1
extra-deps:
- aeson-1.2.3.0
- attoparsec-0.13.2.0
- base-compat-0.9.3
- base-orphans-0.6
- base-prelude-1.2.0.1
- basement-0.0.3
- bifunctors-5.4.2
- binary-parser-0.5.5
- bug-1.0.1
- bytestring-strict-builder-0.4.5
- cabal-doctest-1.0.2
- case-insensitive-1.2.0.10
- cereal-0.5.4.0
- charset-0.3.7.1
- comonad-5.0.2
- contravariant-1.4
- cryptohash-md5-0.11.100.1
- cryptohash-sha1-0.11.100.1
- cryptonite-0.22
- data-bword-0.1.0.1
- data-checked-0.3
- data-default-class-0.1.2.0
- data-dword-0.3.1.1
- data-endian-0.1.1
- data-serializer-0.3
- data-textual-0.3.0.2
- deque-0.2
- distributive-0.5.3
- dlist-0.8.0.3
- entropy-0.3.8
- exceptions-0.8.3
- focus-0.1.5.2
- foldl-1.3.2
- foundation-0.0.16
- free-4.12.4
- hashable-1.2.6.1
- hasql-0.20.0.1
- integer-logarithms-1.0.2
- list-t-1.0.0.1
- loch-th-0.2.1
- managed-1.0.5
- math-functions-0.2.1.0
- memory-0.14.8
- mmorph-1.1.0
- monad-control-1.0.2.2
- mtl-2.2.1
- mwc-random-0.13.6.0
- network-2.6.3.2
- network-info-0.2.0.8
- network-ip-0.3.0.2
- parsec-3.1.11
- parsers-0.12.7
- partial-handler-1.0.2
- persistent-vector-0.1.1
- placeholders-0.1
- postgresql-binary-0.12.1
- prelude-extras-0.4.0.3
- primitive-0.6.2.0
- profunctors-5.2.1
- random-1.1
- scanner-0.2
- scientific-0.3.5.2
- semigroupoids-5.2.1
- semigroups-0.18.3
- slave-thread-1.0.2
- StateVar-1.1.0.4
- stm-2.4.4.1
- stm-containers-0.2.16
- tagged-0.8.5
- text-1.2.2.2
- text-latin1-0.3
- text-printer-0.5
- th-abstraction-0.2.6.0
- time-locale-compat-0.1.1.3
- transformers-base-0.4.4
- transformers-compat-0.5.1.4
- type-hint-0.1
- unordered-containers-0.2.8.0
- uuid-1.3.13
- uuid-types-1.0.3
- vector-0.12.0.1
- vector-builder-0.3.3.1
- vector-th-unbox-0.2.1.6
- void-0.7.2
flags:
time-locale-compat:
old-locale: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment