@@ -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 '[])