on dev help sign in
unscope my heart
dcb0870Eitan Chatav
squeel-postgresql/exe/Example.hs+5−7
@@ -1,9 +1,7 @@
1{-# LANGUAGE
1{-# LANGUAGE
2 DataKinds
2 DataKinds
3− , MagicHash
4 , OverloadedLabels
3 , OverloadedLabels
5 , OverloadedStrings
4 , OverloadedStrings
6− , ScopedTypeVariables
7 , TypeApplications
5 , TypeApplications
8 , TypeOperators
6 , TypeOperators
9#-}
7#-}
@@ -29,9 +27,9 @@ main = do
29 connectionString <- pure
27 connectionString <- pure
30 "host=localhost port=5432 dbname=exampledb"
28 "host=localhost port=5432 dbname=exampledb"
31 Char8.putStrLn $ "connecting to " <> connectionString
29 Char8.putStrLn $ "connecting to " <> connectionString
32− connection0 :: Connection '[] <- connectdb connectionString
30+ connection0 <- connectdb connectionString
33 Char8.putStrLn "setting up database"
31 Char8.putStrLn "setting up database"
34− connection1 :: Connection Tables <- flip execPQ connection0 $ pqExec $
32+ connection1 <- flip execPQ (connection0 :: Connection '[]) $ pqExec $
35 createTable #students
33 createTable #students
36 ( (text & notNull) `As` #name
34 ( (text & notNull) `As` #name
37 :* Nil )
35 :* Nil )
@@ -41,7 +39,7 @@ main = do
41 :* (int4 & notNull) `As` #col2
39 :* (int4 & notNull) `As` #col2
42 :* Nil )
40 :* Nil )
43 Char8.putStrLn "querying"
41 Char8.putStrLn "querying"
44− connection2 :: Connection Tables <- flip execPQ connection1 $ do
42+ connection2 <- flip execPQ (connection1 :: Connection Tables) $ do
45 for_ [I i :* I (i+1) :* Nil | i <- [1::Int32,3..9]] $ pqExecParams
43 for_ [I i :* I (i+1) :* Nil | i <- [1::Int32,3..9]] $ pqExecParams
46 (insertInto #table1 (param1 `As` #col1 :* param2 `As` #col2 :* Nil))
44 (insertInto #table1 (param1 `As` #col1 :* param2 `As` #col2 :* Nil))
47 Just result <- pqExecNil . query $
45 Just result <- pqExecNil . query $
@@ -61,9 +59,9 @@ main = do
61 print (row0 :: NP I '[Int32,Int32])
59 print (row0 :: NP I '[Int32,Int32])
62 print (row1 :: NP I '[Int32,Int32])
60 print (row1 :: NP I '[Int32,Int32])
63 Char8.putStrLn "tearing down database"
61 Char8.putStrLn "tearing down database"
64− connection3 :: Connection '[] <- flip execPQ connection2 $ pqExec $
62+ connection3 <- flip execPQ (connection2 :: Connection Tables) $ pqExec $
65 dropTable #table1 >>> dropTable #students
63 dropTable #table1 >>> dropTable #students
66− finish connection3
64+ finish (connection3 :: Connection '[])
67
65
68type Columns =
66type Columns =
69 '[ "col1" ::: 'Required ('NotNull 'PGInt4)
67 '[ "col1" ::: 'Required ('NotNull 'PGInt4)
squeel-postgresql/src/Squeel/PostgreSQL/PQ.hs+2−1
@@ -38,7 +38,8 @@ import Squeel.PostgreSQL.Binary
38import Squeel.PostgreSQL.Statement
38import Squeel.PostgreSQL.Statement
39import Squeel.PostgreSQL.Schema
39import Squeel.PostgreSQL.Schema
40
40
41+newtype Connection (db :: [(Symbol,[(Symbol,ColumnType)])]) =
41−newtype Connection db = Connection { unConnection :: LibPQ.Connection }
42+ Connection { unConnection :: LibPQ.Connection }
42
43
43newtype PQ
44newtype PQ
44 (db0 :: [(Symbol,[(Symbol,ColumnType)])])
45 (db0 :: [(Symbol,[(Symbol,ColumnType)])])