on dev help sign in
examples
c026746Eitan Chatav
squeel-postgresql/exe/Example.hs+15−11
@@ -27,18 +27,22 @@ main = do
27 connectionString <- pure
27 connectionString <- pure
28 "host=localhost port=5432 dbname=exampledb"
28 "host=localhost port=5432 dbname=exampledb"
29 Char8.putStrLn $ "connecting to " <> connectionString
29 Char8.putStrLn $ "connecting to " <> connectionString
30− connection0 <- connectdb connectionString
30+ connection0 :: Connection '[] <- connectdb connectionString
31 Char8.putStrLn "setting up database"
31 Char8.putStrLn "setting up database"
32 connection1 <- flip execPQ connection0 $
32 connection1 <- flip execPQ connection0 $
33+ pqExec
33− pqExec ( createTable #students
34+ ( createTable #students
34− ( (text & notNull) `As` #name
35+ ( (text & notNull) `As` #name
35− :* Nil ) )
36+ :* Nil ) )
37+ & (pqThen . pqExec)
36− &>> createTable #table1
38+ ( createTable #table1
37− ( (int4 & notNull) `As` #col1
39+ ( (int4 & notNull) `As` #col1
38− :* (int4 & notNull) `As` #col2
40+ :* (int4 & notNull) `As` #col2
39− :* Nil )
41+ :* Nil ) )
42+ & (pqThen . pqExec)
40− &>> insertInto #table1 ( 1 `As` #col1 :* 2 `As` #col2 :* Nil )
43+ ( insertInto #table1 ( 1 `As` #col1 :* 2 `As` #col2 :* Nil ) )
44+ & (pqThen . pqExec)
41− &>> insertInto #table1 ( 3 `As` #col1 :* 4 `As` #col2 :* Nil )
45+ ( insertInto #table1 ( 3 `As` #col1 :* 4 `As` #col2 :* Nil ) )
42 Char8.putStrLn "querying"
46 Char8.putStrLn "querying"
43 connection2 <- flip execPQ connection1 $ do
47 connection2 <- flip execPQ connection1 $ do
44 Just result <- pqExecNil $ select $ starFrom #table1
48 Just result <- pqExecNil $ select $ starFrom #table1
@@ -59,7 +63,7 @@ main = do
59 Char8.putStrLn "tearing down database"
63 Char8.putStrLn "tearing down database"
60 connection3 :: Connection '[] <- flip execPQ connection2 $ pqExec
64 connection3 :: Connection '[] <- flip execPQ connection2 $ pqExec
61 (dropTable #table1 :: Statement '[] '[] Tables '["students" ::: StudentsColumns])
65 (dropTable #table1 :: Statement '[] '[] Tables '["students" ::: StudentsColumns])
62− &>> dropTable #students
66+ & (pqThen . pqExec) (dropTable #students)
63 finish connection3
67 finish connection3
64
68
65type Columns =
69type Columns =