1{-# OPTIONS_GHC -fno-warn-partial-type-signatures #-}
6 , MultiParamTypeClasses
9 , PartialTypeSignatures
12 , TypeSynonymInstances
15module Main (main,col1,col2) where
17import Control.Category ((>>>))
18import Control.Monad.Base
19import Data.Function ((&))
22import Generics.SOP hiding (from)
23import Squeal.PostgreSQL
25import qualified Data.ByteString.Char8 as Char8
26import qualified GHC.Generics as GHC
29 '[ "students" ::: '["name" ::: 'Required ('NotNull 'PGtext)]
31 '[ "col1" ::: 'Required ('NotNull 'PGint4)
32 , "col2" ::: 'Required ('NotNull 'PGint4)
36data Row = Row { col1 :: Int32, col2 :: Int32 }
37 deriving (Show, GHC.Generic)
39instance HasDatatypeInfo Row
43 Char8.putStrLn "squeal"
44 connectionString <- pure
45 "host=localhost port=5432 dbname=exampledb"
46 Char8.putStrLn $ "connecting to " <> connectionString
47 connection0 <- connectdb connectionString
48 Char8.putStrLn "setting up schema"
49 connection1 <- flip execPQ (connection0 :: Connection '[]) $ define $
50 createTable #students ((text & notNull) `As` #name :* Nil ) []
53 ((int4 & notNull) `As` #col1 :* (int4 & notNull) `As` #col2 :* Nil) []
54 connection2 <- flip execPQ (connection1 :: Connection Schema) $ do
56 insert :: Manipulation Schema '[_,_,_,_] '[]
60 (param @1 `As` #col1 :* param @2 `As` #col2 :* Nil)
61 [param @3 `As` #col1 :* param @4 `As` #col2 :* Nil]
62 ) Conflict (Returning Nil)
63 liftBase $ Char8.putStrLn "manipulating"
64 _insertResult <- manipulateParams insert
65 (1::Int32,2::Int32,3::Int32,4::Int32)
66 liftBase $ Char8.putStrLn "querying"
68 selectStar (from (Table (#table1 `As` #table1)))
69 value00 <- getValue (RowNumber 0) (columnNumber @0) result
70 value01 <- getValue (RowNumber 0) (columnNumber @1) result
71 value10 <- getValue (RowNumber 1) (columnNumber @0) result
72 value11 <- getValue (RowNumber 1) (columnNumber @1) result
73 row0 <- getRow (RowNumber 0) result
74 row1 <- getRow (RowNumber 1) result
75 rows <- getRows result
77 print (value00 :: Int32)
78 print (value01 :: Int32)
79 print (value10 :: Int32)
80 print (value11 :: Int32)
84 Char8.putStrLn "tearing down schema"
85 connection3 <- flip execPQ (connection2 :: Connection Schema) $ define $
86 dropTable #table1 >>> dropTable #students
87 finish (connection3 :: Connection '[])
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list