module Database.PostgreSQL.Simple.Util
( existsTable
, withTransactionRolledBack
) where
import Control.Exception (finally)
import Database.PostgreSQL.Simple (Connection, Only (..), begin,
query, rollback)
existsTable :: Connection -> String -> IO Bool
existsTable con table =
fmap (not . null) (query con q (Only table) :: IO [[Int]])
where
q = "select count(relname) from pg_class where relname = ?"
withTransactionRolledBack :: Connection -> IO a -> IO a
withTransactionRolledBack con f =
begin con >> finally f (rollback con)