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