Created
September 26, 2019 13:20
-
-
Save EncodePanda/843b07d8734d112b3f658a9f04a0c4ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveAnyClass #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import Control.Applicative | |
import Control.Monad | |
import Database.PostgreSQL.Simple | |
import GHC.Generics (Generic) | |
data User = User { uid :: Int, login :: String} | |
deriving (Generic, FromRow, Show) | |
main :: IO () | |
main = do | |
conn <- connect defaultConnectInfo { | |
connectDatabase = "haskell", | |
connectUser = "rabbit" | |
} | |
putStrLn "2 + 2" | |
mapM_ print =<< ( query_ conn "select 2 + 2" :: IO [Only Int] ) | |
mapM_ print =<< ( query_ conn "select uid, login from users" :: IO [(Int, String)]) | |
mapM_ print =<< ( query_ conn "select * from users" :: IO [User]) | |
res <- query_ conn "select u1.*, u2.* from users as u1, users as u2" | |
void $ forM res $ \case | |
(User uid1 login1) :. (User uid2 login2) -> putStrLn (login1 ++ "-" ++ login2) | |
-- resolver: lts-14.5 | |
-- packages: | |
-- - . | |
-- nix: | |
-- pure: false | |
-- enable: true | |
-- packages: [ postgresql ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment