hasql/tasty/Main/Queries.hs
2015-11-21 13:44:18 +03:00

37 lines
920 B
Haskell

module Main.Queries where
import Main.Prelude hiding (def)
import qualified Hasql as H
import qualified Hasql.Encoding as HE
import qualified Hasql.Decoding as HD
import qualified Main.Prelude as Prelude
def :: ByteString -> H.Query () ()
def sql =
(sql, Prelude.def, Prelude.def, False)
plain :: ByteString -> H.Query () ()
plain sql =
(sql, mempty, HD.noResult, False)
dropType :: ByteString -> H.Query () ()
dropType name =
plain $
"drop type if exists " <> name
createEnum :: ByteString -> [ByteString] -> H.Query () ()
createEnum name values =
plain $
"create type " <> name <> " as enum (" <>
mconcat (intersperse ", " (map (\x -> "'" <> x <> "'") values)) <> ")"
selectList :: H.Query () ([] (Int64, Int64))
selectList =
(sql, mempty, decoder, True)
where
sql =
"values (1,2), (3,4), (5,6)"
decoder =
HD.rowsList ((,) <$> HD.value HD.int8 <*> HD.value HD.int8)