module Hasql.Migration.Util
( existsTable
) where
import Hasql.Query
import qualified Hasql.Encoders as Encoders
import qualified Hasql.Decoders as Decoders
import Hasql.Transaction (query, Transaction)
import Data.Text (Text)
import Data.Default.Class
existsTable :: Text -> Transaction Bool
existsTable table =
fmap (not . null) $ query table q
where
q = statement sql (Encoders.value def) (Decoders.rowsList (Decoders.value Decoders.int8)) False
sql = "select count(relname) from pg_class where relname = $1"