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