hasql-lo

Large Object helpers for the Hasql ecosystem

BSD-3-CLAUSE License

Stars
5

Hasql Large Objects

This package contains helpers for using large objects with Hasql, and thus Postgres.

Example

{-# LANGUAGE OverloadedStrings #-}
module Lib
    ( someFunc
    ) where

import           Control.Monad.IO.Class
import           GHC.Int
import           Hasql.Connection (settings)
import qualified Hasql.Pool as P
import qualified Hasql.Transaction as HT

import           Hasql.LO
import           Hasql.LO.Types

-- | Composed Transactions
writeToNewLO :: HT.Transaction Int32
writeToNewLO = do
  oid <- createFromByteString Nothing "heya!"
  fd <- open oid WRITE
  o <- write fd "things"
  return oid

someFunc :: IO ()
someFunc = do
  let pgSettings = settings "localhost" 5432 "postgres" "password" "postgres"
  pool <- P.acquire (4, 10, pgSettings)
  result <- P.use pool $ do
    oid <- HT.run writeToNewLO HT.ReadCommitted HT.Write
    liftIO $ print oid
  print "done"