mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-11-26 23:33:02 +03:00
37 lines
952 B
Haskell
37 lines
952 B
Haskell
module Main.Queries where
|
|
|
|
import Main.Prelude hiding (def)
|
|
import qualified Hasql.Query as HQ
|
|
import qualified Hasql.Encoders as HE
|
|
import qualified Hasql.Decoders as HD
|
|
import qualified Main.Prelude as Prelude
|
|
|
|
|
|
def :: ByteString -> HQ.Query () ()
|
|
def sql =
|
|
HQ.statement sql Prelude.def Prelude.def False
|
|
|
|
plain :: ByteString -> HQ.Query () ()
|
|
plain sql =
|
|
HQ.statement sql mempty HD.unit False
|
|
|
|
dropType :: ByteString -> HQ.Query () ()
|
|
dropType name =
|
|
plain $
|
|
"drop type if exists " <> name
|
|
|
|
createEnum :: ByteString -> [ByteString] -> HQ.Query () ()
|
|
createEnum name values =
|
|
plain $
|
|
"create type " <> name <> " as enum (" <>
|
|
mconcat (intersperse ", " (map (\x -> "'" <> x <> "'") values)) <> ")"
|
|
|
|
selectList :: HQ.Query () ([] (Int64, Int64))
|
|
selectList =
|
|
HQ.statement sql mempty decoder True
|
|
where
|
|
sql =
|
|
"values (1,2), (3,4), (5,6)"
|
|
decoder =
|
|
HD.rowsList ((,) <$> HD.value HD.int8 <*> HD.value HD.int8)
|