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