DSH-0.8.2.1: examples/Example01.hs
{-# LANGUAGE MonadComprehensions #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE ViewPatterns #-}
module Main where
import qualified Prelude as P
import Database.DSH
import Database.DSH.Compiler
import Database.HDBC.PostgreSQL
ints :: Q [Integer]
ints = toQ [1 .. 10]
query1 :: Q [(Integer,Integer)]
query1 = [ pair i1 i2
| i1 <- ints
, i2 <- ints
]
query2 :: Q [(Integer,Integer)]
query2 = [ pair i1 i2
| (view -> (i1,i2)) <- query1
, i1 == i2
]
getConn :: IO Connection
getConn = connectPostgreSQL "user = 'giorgidz' password = '' host = 'localhost' dbname = 'giorgidz'"
runQ :: (Show a,QA a) => Q a -> IO ()
runQ q = getConn P.>>= \conn -> (fromQ conn q P.>>= P.print) P.>> disconnect conn
main :: IO ()
main = runQ ints P.>> runQ query1 P.>> runQ query2