on dev help sign in
connect poll & compile
commit6d0a671c9aabb78b8bb760788046c7262cd1ae10 authorEitan Chatav <eitan.chatav@gmail.com> dateTue 15 Aug 2017, 11:40 (9 years ago) parentf452847
3 files changed+64−57
squeal-postgresql/exe/Example.hs+54−53 squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+9−3 squeal-postgresql/test/Squeal/PostgreSQL/StatementSpec.hs+1−1
squeal-postgresql/exe/Example.hs+54−53
@@ -1,3 +1,4 @@
1+{-# OPTIONS_GHC -fno-warn-unused-imports #-}
12{-# LANGUAGE
23 DataKinds
34 , DeriveGeneric
@@ -23,13 +24,13 @@ import Squeal.PostgreSQL
2324import qualified Data.ByteString.Char8 as Char8
2425import qualified GHC.Generics as GHC
2526
26−type Schema =
27− '[ "students" ::: '["name" ::: 'Required ('NotNull 'PGtext)]
28− , "table1" :::
29− '[ "col1" ::: 'Required ('NotNull 'PGint4)
30− , "col2" ::: 'Required ('NotNull 'PGint4)
31− ]
32− ]
27+-- type Schema =
28+-- '[ "students" ::: '["name" ::: 'Required ('NotNull 'PGtext)]
29+-- , "table1" :::
30+-- '[ "col1" ::: 'Required ('NotNull 'PGint4)
31+-- , "col2" ::: 'Required ('NotNull 'PGint4)
32+-- ]
33+-- ]
3334
3435data Table1Row = Table1Row { col1 :: Int32, col2 :: Int32 }
3536 deriving (Show, GHC.Generic)
@@ -39,49 +40,49 @@ instance HasDatatypeInfo Table1Row
3940main :: IO ()
4041main = do
4142 Char8.putStrLn "squeal"
42− connectionString <- pure
43− "host=localhost port=5432 dbname=exampledb"
44− Char8.putStrLn $ "connecting to " <> connectionString
45− connection0 <- connectdb connectionString
46− Char8.putStrLn "setting up schema"
47− connection1 <- runPQ (connection0 :: Connection '[]) $ pqExec $
48− createTable #students ((text & notNull) `As` #name :* Nil ) []
49− >>>
50− createTable #table1
51− ((int4 & notNull) `As` #col1 :* (int4 & notNull) `As` #col2 :* Nil) []
52− connection2 <- runPQ (connection1 :: Connection Schema) $ do
53− let
54− manipulation :: Manipulation Schema
55− '[ 'Required ('NotNull 'PGint4)
56− , 'Required ('NotNull 'PGint4)
57− , 'Required ('NotNull 'PGint4)
58− , 'Required ('NotNull 'PGint4)
59− ] '[]
60− manipulation =
61− insertInto #table1
62− ( Values
63− (param (Proxy @1) `As` #col1 :* param (Proxy @2) `As` #col2 :* Nil)
64− [param (Proxy @3) `As` #col1 :* param (Proxy @4) `As` #col2 :* Nil]
65− ) Conflict (Returning Nil)
66− liftBase $ Char8.putStrLn "manipulating"
67− _ <- pqExecParams manipulation (1::Int32,2::Int32,3::Int32,4::Int32)
68− liftBase $ Char8.putStrLn "querying"
69− Just result <- pqExecNil . query $
70− selectStar (from (Table (#table1 `As` #table1)))
71− value00 <- getValue (RowNumber 0) (columnNumber @0) result
72− value01 <- getValue (RowNumber 0) (columnNumber @1) result
73− value10 <- getValue (RowNumber 1) (columnNumber @0) result
74− value11 <- getValue (RowNumber 1) (columnNumber @1) result
75− row0 <- getRow (RowNumber 0) result
76− row1 <- getRow (RowNumber 1) result
77− liftBase $ do
78− print (value00 :: Int32)
79− print (value01 :: Int32)
80− print (value10 :: Int32)
81− print (value11 :: Int32)
82− print (row0 :: Table1Row)
83− print (row1 :: Table1Row)
84− Char8.putStrLn "tearing down schema"
85− connection3 <- runPQ (connection2 :: Connection Schema) $ pqExec $
86− dropTable #table1 >>> dropTable #students
87− finish (connection3 :: Connection '[])
43+ -- connectionString <- pure
44+ -- "host=localhost port=5432 dbname=exampledb"
45+ -- Char8.putStrLn $ "connecting to " <> connectionString
46+ -- connection0 <- connectdb connectionString
47+ -- Char8.putStrLn "setting up schema"
48+ -- connection1 <- runPQ (connection0 :: Connection '[]) $ pqExec $
49+ -- createTable #students ((text & notNull) `As` #name :* Nil ) []
50+ -- >>>
51+ -- createTable #table1
52+ -- ((int4 & notNull) `As` #col1 :* (int4 & notNull) `As` #col2 :* Nil) []
53+ -- connection2 <- runPQ (connection1 :: Connection Schema) $ do
54+ -- let
55+ -- manipulation :: Manipulation Schema
56+ -- '[ 'Required ('NotNull 'PGint4)
57+ -- , 'Required ('NotNull 'PGint4)
58+ -- , 'Required ('NotNull 'PGint4)
59+ -- , 'Required ('NotNull 'PGint4)
60+ -- ] '[]
61+ -- manipulation =
62+ -- insertInto #table1
63+ -- ( Values
64+ -- (param (Proxy @1) `As` #col1 :* param (Proxy @2) `As` #col2 :* Nil)
65+ -- [param (Proxy @3) `As` #col1 :* param (Proxy @4) `As` #col2 :* Nil]
66+ -- ) Conflict (Returning Nil)
67+ -- liftBase $ Char8.putStrLn "manipulating"
68+ -- _ <- pqExecParams manipulation (1::Int32,2::Int32,3::Int32,4::Int32)
69+ -- liftBase $ Char8.putStrLn "querying"
70+ -- Just result <- pqExecNil . query $
71+ -- selectStar (from (Table (#table1 `As` #table1)))
72+ -- value00 <- getValue (RowNumber 0) (columnNumber @0) result
73+ -- value01 <- getValue (RowNumber 0) (columnNumber @1) result
74+ -- value10 <- getValue (RowNumber 1) (columnNumber @0) result
75+ -- value11 <- getValue (RowNumber 1) (columnNumber @1) result
76+ -- row0 <- getRow (RowNumber 0) result
77+ -- row1 <- getRow (RowNumber 1) result
78+ -- liftBase $ do
79+ -- print (value00 :: Int32)
80+ -- print (value01 :: Int32)
81+ -- print (value10 :: Int32)
82+ -- print (value11 :: Int32)
83+ -- print (row0 :: Table1Row)
84+ -- print (row1 :: Table1Row)
85+ -- Char8.putStrLn "tearing down schema"
86+ -- connection3 <- runPQ (connection2 :: Connection Schema) $ pqExec $
87+ -- dropTable #table1 >>> dropTable #students
88+ -- finish (connection3 :: Connection '[])
squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+9−3
@@ -154,6 +154,8 @@ class Monad pq => MonadPQ schema pq | pq -> schema where
154154 => list x -> Manipulation schema params ys -> pq ()
155155 forPrepared_ = flip traversePrepared_
156156
157+ connectPoll :: pq LibPQ.PollingStatus
158+
157159instance MonadBase IO io => MonadPQ schema (PQ schema schema io) where
158160
159161 manipulateParams
@@ -197,6 +199,10 @@ instance MonadBase IO io => MonadPQ schema (PQ schema schema io) where
197199 LibPQ.exec conn ("DEALLOCATE " <> temp <> ";")
198200 return ((), Connection conn)
199201
202+ connectPoll = undefined--PQ $ \ (Connection conn) -> do
203+ -- pollingStatus <- liftBase $ connectPoll conn
204+ -- return (pollingStatus, Connection conn)
205+
200206instance Monad m => Applicative (PQ schema schema m) where
201207 pure x = PQ $ \ conn -> pure (x, conn)
202208 (<*>) = pqAp
@@ -233,12 +239,12 @@ finish :: MonadBase IO io => Connection schema -> io ()
233239finish = liftBase . LibPQ.finish . unConnection
234240
235241withConnection
236− :: MonadBaseControl IO io
242+ :: forall schema io x
243+ . MonadBaseControl IO io
237244 => ByteString
238245 -> (Connection schema -> io x)
239246 -> io x
240−withConnection connString action =
241− bracket (connectdb connString) finish action
247+withConnection connString = bracket (connectdb connString) finish
242248
243249newtype Result (xs :: [(Symbol,ColumnType)])
244250 = Result { unResult :: LibPQ.Result }
squeal-postgresql/test/Squeal/PostgreSQL/StatementSpec.hs+1−1
@@ -20,7 +20,7 @@ import Squeal.PostgreSQL.Schema
2020spec :: Spec
2121spec = do
2222 let
23− qry `queryRenders` str = query qry `manipulationRenders` str
23+ qry `queryRenders` str = queryStatement qry `manipulationRenders` str
2424 definition `definitionRenders` str =
2525 renderDefinition definition `shouldBe` str
2626 manipulation `manipulationRenders` str =