{-# LANGUAGE OverloadedStrings #-}
module Hasql.Migration.Util
( existsTable
) where
import Hasql.Statement
import qualified Hasql.Encoders as Encoders
import qualified Hasql.Decoders as Decoders
import Hasql.Transaction (statement, Transaction)
import Data.Text (Text)
import Data.Default.Class
existsTable :: Text -> Transaction Bool
existsTable table =
fmap (not . null) $ statement table q
where
q = Statement sql (Encoders.param def) (Decoders.rowList (Decoders.column Decoders.int8)) False
sql = "select relname from pg_class where relname = $1"