@@ -30,32 +30,29 @@ main = do
3030 "host=localhost port=5432 dbname=exampledb"
3131 Char8.putStrLn $ "connecting to " <> connectionString
3232 connection0 <- connectdb connectionString
33− Char8.putStrLn "setting up database"
33+ Char8.putStrLn "setting up schema"
3434 connection1 <- runPQ (connection0 :: Connection '[]) $ pqExec $
35− createTable #students
36− ( (text & notNull) `As` #name
37− :* Nil ) []
35+ createTable #students ((text & notNull) `As` #name :* Nil ) []
3836 >>>
3937 createTable #table1
40− ( (int4 & notNull) `As` #col1
41− :* (int4 & notNull) `As` #col2
42− :* Nil ) []
43− Char8.putStrLn "querying"
44− connection2 <- runPQ (connection1 :: Connection Tables) $ do
38+ ((int4 & notNull) `As` #col1 :* (int4 & notNull) `As` #col2 :* Nil) []
39+ connection2 <- runPQ (connection1 :: Connection Schema) $ do
4540 let
46− statement :: Manipulation Tables
41+ manipulation :: Manipulation Schema
4742 '[ 'Required ('NotNull 'PGInt4)
4843 , 'Required ('NotNull 'PGInt4)
4944 , 'Required ('NotNull 'PGInt4)
5045 , 'Required ('NotNull 'PGInt4)
5146 ] '[]
52− statement =
47+ manipulation =
5348 insertInto #table1
54− (Values
55− (param1 `As` #col1 :* param2 `As` #col2 :* Nil)
56− [param3 `As` #col1 :* param4 `As` #col2 :* Nil] )
57− Conflict ReturningNil
58− _ <- pqExecParams statement (1::Int32,2::Int32,3::Int32,4::Int32)
49+ ( Values
50+ (param (Proxy @1) `As` #col1 :* param (Proxy @2) `As` #col2 :* Nil)
51+ [param (Proxy @3) `As` #col1 :* param (Proxy @4) `As` #col2 :* Nil]
52+ ) Conflict ReturningNil
53+ liftBase $ Char8.putStrLn "manipulating"
54+ _ <- pqExecParams manipulation (1::Int32,2::Int32,3::Int32,4::Int32)
55+ liftBase $ Char8.putStrLn "querying"
5956 Just result <- pqExecNil . query $
6057 selectStar (from (Table (#table1 `As` #table1)))
6158 value00 <- getValue (RowNumber 0) (columnNumber @0) result
@@ -69,21 +66,21 @@ main = do
6966 print (value01 :: Int32)
7067 print (value10 :: Int32)
7168 print (value11 :: Int32)
72− print (row0 :: ColumnsRecord)
73− print (row1 :: ColumnsRecord)
74− Char8.putStrLn "tearing down database"
75− connection3 <- runPQ (connection2 :: Connection Tables) $ pqExec $
69+ print (row0 :: Table1Row)
70+ print (row1 :: Table1Row)
71+ Char8.putStrLn "tearing down schema"
72+ connection3 <- runPQ (connection2 :: Connection Schema) $ pqExec $
7673 dropTable #table1 >>> dropTable #students
7774 finish (connection3 :: Connection '[])
7875
79−type Columns =
80− '[ "col1" ::: 'Required ('NotNull 'PGInt4)
81− , "col2" ::: 'Required ('NotNull 'PGInt4)
82− ]
83−data ColumnsRecord = ColumnsRecord { col1 :: Int32, col2 :: Int32 }
76+data Table1Row = Table1Row { col1 :: Int32, col2 :: Int32 }
8477 deriving (Show, GHC.Generic)
85−instance Generic ColumnsRecord
86−instance FromRow Columns ColumnsRecord
78+instance Generic Table1Row
8779
88−type StudentsColumns = '["name" ::: 'Required ('NotNull 'PGText)]
89−type Tables = '["students" ::: StudentsColumns, "table1" ::: Columns]
80+type Schema =
81+ '[ "students" ::: '["name" ::: 'Required ('NotNull 'PGText)]
82+ , "table1" :::
83+ '[ "col1" ::: 'Required ('NotNull 'PGInt4)
84+ , "col2" ::: 'Required ('NotNull 'PGInt4)
85+ ]
86+ ]