on efdb2eb help sign in
82 lines 2.7 kB history raw
1{-# LANGUAGE
2 DataKinds
3 , MagicHash
4 , OverloadedLabels
5 , OverloadedStrings
6 , TypeOperators
7#-}
9module Main (main) where
11import Control.Category ((>>>))
12import Control.Monad.Base
13import Data.Function ((&))
14import Data.Int
15import Data.Monoid
16import Generics.SOP
17import Squeel.PostgreSQL
19import qualified Data.ByteString.Char8 as Char8
21main :: IO ()
22main = do
23 Char8.putStrLn "squeel"
24 connectionString <- pure
25 "host=localhost port=5432 dbname=exampledb"
26 Char8.putStrLn $ "connecting to " <> connectionString
27 connection0 <- connectdb connectionString
28 Char8.putStrLn "creating tables"
29 connection1 <- flip execPQ connection0 $ pqExec $
30 createTable #students
31 ( (text & notNull) `As` #name
32 :* Nil )
33 >>>
34 createTable #table1
35 ( (int4 & notNull) `As` #col1
36 :* (int4 & notNull) `As` #col2
37 :* Nil )
38 connection2 <- flip execPQ connection1 $ do
39 _insertTable1Result <- pqExec $
40 insertInto #table1 ( 1 `As` #col1 :* 2 `As` #col2 :* Nil )
41 >>>
42 insertInto #table1 ( 3 `As` #col1 :* 4 `As` #col2 :* Nil )
43 Just selectTable1Result <- flip pqExecParams Nil $
44 (select $ starFrom #table1 :: Statement '[] Columns Tables Tables)
45 Just (Right value00) <- getvalue selectTable1Result (RowNumber 0) colNum0
46 Just (Right value01) <- getvalue selectTable1Result (RowNumber 0) colNum1
47 Just (Right value10) <- getvalue selectTable1Result (RowNumber 1) colNum0
48 Just (Right value11) <- getvalue selectTable1Result (RowNumber 1) colNum1
49 liftBase $ do
50 print (value00 :: Int32)
51 print (value01 :: Int32)
52 print (value10 :: Int32)
53 print (value11 :: Int32)
54 finish connection2
56type Columns =
57 '[ "col1" ::: 'Required ('NotNull 'PGInt4)
58 , "col2" ::: 'Required ('NotNull 'PGInt4)
59 ]
60-- type SumAndCol1 = '[ "sum" ::: 'NotNull 'PGInt4, "col1" ::: 'NotNull 'PGInt4]
61type StudentsColumns = '["name" ::: 'Required ('NotNull 'PGText)]
62type Tables = '[ "table1" ::: Columns, "students" ::: StudentsColumns]
63-- type OrderColumns =
64-- [ "orderID" ::: 'NotNull 'PGInt4
65-- , "orderVal" ::: 'NotNull 'PGText
66-- , "customerID" ::: 'NotNull 'PGInt4
67-- , "shipperID" ::: 'NotNull 'PGInt4
68-- ]
69-- type CustomerColumns =
70-- [ "customerID" ::: 'NotNull 'PGInt4, "customerVal" ::: 'NotNull 'PGFloat4 ]
71-- type ShipperColumns =
72-- [ "shipperID" ::: 'NotNull 'PGInt4, "shipperVal" ::: 'NotNull 'PGBool ]
73-- type JoinTables =
74-- [ "shippers" ::: ShipperColumns
75-- , "customers" ::: CustomerColumns
76-- , "orders" ::: OrderColumns
77-- ]
78-- type ValueColumns =
79-- [ "orderVal" ::: 'NotNull 'PGText
80-- , "customerVal" ::: 'NotNull 'PGFloat4
81-- , "shipperVal" ::: 'NotNull 'PGBool
82-- ]