@@ -9,7 +9,6 @@
10module Main (main) where
10module Main (main) where
12−import Control.Category ((>>>))
13import Control.Monad.Base
12import Control.Monad.Base
14import Control.Monad.Except
13import Control.Monad.Except
15import Control.Monad.Trans.Maybe
14import Control.Monad.Trans.Maybe
@@ -28,45 +27,38 @@ main = do
28 "host=localhost port=5432 dbname=exampledb"
27 "host=localhost port=5432 dbname=exampledb"
29 Char8.putStrLn $ "connecting to " <> connectionString
28 Char8.putStrLn $ "connecting to " <> connectionString
30 connection0 <- connectdb connectionString
29 connection0 <- connectdb connectionString
31− Char8.putStrLn "creating tables"
30+ Char8.putStrLn "creating database"
32− connection1 <- flip execPQ connection0 $ pqExec $
31+ connection1 <- flip execPQ connection0 $
33− createTable #students
32+ pqExec ( createTable #students
34 ( (text & notNull) `As` #name
33 ( (text & notNull) `As` #name
35− :* Nil )
34+ :* Nil ) )
37− createTable #table1
35+ &>> createTable #table1
38 ( (int4 & notNull) `As` #col1
36 ( (int4 & notNull) `As` #col1
39 :* (int4 & notNull) `As` #col2
37 :* (int4 & notNull) `As` #col2
39+ &>> insertInto #table1 ( 1 `As` #col1 :* 2 `As` #col2 :* Nil )
40+ &>> insertInto #table1 ( 3 `As` #col1 :* 4 `As` #col2 :* Nil )
41+ Char8.putStrLn "querying"
41 connection2 <- flip execPQ connection1 $ do
42 connection2 <- flip execPQ connection1 $ do
42− _insertTable1Result <- pqExec $
43− insertInto #table1 ( 1 `As` #col1 :* 2 `As` #col2 :* Nil )
45− insertInto #table1 ( 3 `As` #col1 :* 4 `As` #col2 :* Nil )
46− Just selectTable1Result <- flip pqExecParams Nil $
47− (select $ starFrom #table1 :: Statement '[] Columns Tables Tables)
43+ Just result <- pqExecParams (select (starFrom #table1)) Nil
48− Just (Right value00) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
44+ runMaybeT . runExceptT . flip runValue result $ do
49− getValue (RowNumber 0) colNum0
45+ value00 <- getValue (RowNumber 0) colNum0
50− Just (Right value01) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
51− getValue (RowNumber 0) colNum1
46+ value01 <- getValue (RowNumber 0) colNum1
52− Just (Right value10) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
53− getValue (RowNumber 1) colNum0
47+ value10 <- getValue (RowNumber 1) colNum0
54− Just (Right value11) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
55− getValue (RowNumber 1) colNum1
48+ value11 <- getValue (RowNumber 1) colNum1
56− Just (Right row0) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
57− getRow (RowNumber 0)
49+ row0 <- getRow (RowNumber 0)
58− Just (Right row1) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
59− getRow (RowNumber 1)
50+ row1 <- getRow (RowNumber 1)
60− liftBase $ do
51+ liftBase $ do
61− print (value00 :: Int32)
52+ print (value00 :: Int32)
62− print (value01 :: Int32)
53+ print (value01 :: Int32)
63− print (value10 :: Int32)
54+ print (value10 :: Int32)
64− print (value11 :: Int32)
55+ print (value11 :: Int32)
65− print (row0 :: NP I '[Int32,Int32])
56+ print (row0 :: NP I '[Int32,Int32])
66− print (row1 :: NP I '[Int32,Int32])
57+ print (row1 :: NP I '[Int32,Int32])
58+ Char8.putStrLn "tearing down database"
67− connection3 :: Connection '[] <- flip execPQ connection2 $ pqExec $
59+ connection3 :: Connection '[] <- flip execPQ connection2 $ pqExec
68 (dropTable #table1 :: Statement '[] '[] Tables '["students" ::: StudentsColumns])
60 (dropTable #table1 :: Statement '[] '[] Tables '["students" ::: StudentsColumns])
69− >>> dropTable #students
61+ &>> dropTable #students
70 finish connection3
62 finish connection3
72type Columns =
64type Columns =