10module Main (main) where
12import Control.Category ((>>>))
13import Control.Monad.Base
14import Control.Monad.Except
15import Control.Monad.Trans.Maybe
16import Data.Function ((&))
20import Squeel.PostgreSQL
22import qualified Data.ByteString.Char8 as Char8
26 Char8.putStrLn "squeel"
27 connectionString <- pure
28 "host=localhost port=5432 dbname=exampledb"
29 Char8.putStrLn $ "connecting to " <> connectionString
30 connection0 <- connectdb connectionString
31 Char8.putStrLn "creating tables"
32 connection1 <- flip execPQ connection0 $ pqExec $
34 ( (text & notNull) `As` #name
38 ( (int4 & notNull) `As` #col1
39 :* (int4 & notNull) `As` #col2
41 connection2 <- flip execPQ connection1 $ do
42 _insertTable1Result <- pqExec $
43 insertInto #table1 ( 1 `As` #col1 :* 2 `As` #col2 :* Nil )
45 insertInto #table1 ( 3 `As` #col1 :* 4 `As` #col2 :* Nil )
46 Just selectTable1Result <- flip pqExecParams Nil $
47 (select $ starFrom #table1 :: Statement '[] Columns Tables Tables)
48 Just (Right value00) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
49 getValue (RowNumber 0) colNum0
50 Just (Right value01) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
51 getValue (RowNumber 0) colNum1
52 Just (Right value10) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
53 getValue (RowNumber 1) colNum0
54 Just (Right value11) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
55 getValue (RowNumber 1) colNum1
56 Just (Right row0) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
58 Just (Right row1) <- runMaybeT . runExceptT . flip runValue selectTable1Result $
61 print (value00 :: Int32)
62 print (value01 :: Int32)
63 print (value10 :: Int32)
64 print (value11 :: Int32)
65 print (row0 :: NP I '[Int32,Int32])
66 print (row1 :: NP I '[Int32,Int32])
67 connection3 :: Connection '[] <- flip execPQ connection2 $ pqExec $
68 (dropTable #table1 :: Statement '[] '[] Tables '["students" ::: StudentsColumns])
69 >>> dropTable #students
73 '[ "col1" ::: 'Required ('NotNull 'PGInt4)
74 , "col2" ::: 'Required ('NotNull 'PGInt4)
76-- type SumAndCol1 = '[ "sum" ::: 'NotNull 'PGInt4, "col1" ::: 'NotNull 'PGInt4]
77type StudentsColumns = '["name" ::: 'Required ('NotNull 'PGText)]
78type Tables = '[ "table1" ::: Columns, "students" ::: StudentsColumns]
80-- [ "orderID" ::: 'NotNull 'PGInt4
81-- , "orderVal" ::: 'NotNull 'PGText
82-- , "customerID" ::: 'NotNull 'PGInt4
83-- , "shipperID" ::: 'NotNull 'PGInt4
85-- type CustomerColumns =
86-- [ "customerID" ::: 'NotNull 'PGInt4, "customerVal" ::: 'NotNull 'PGFloat4 ]
87-- type ShipperColumns =
88-- [ "shipperID" ::: 'NotNull 'PGInt4, "shipperVal" ::: 'NotNull 'PGBool ]
90-- [ "shippers" ::: ShipperColumns
91-- , "customers" ::: CustomerColumns
92-- , "orders" ::: OrderColumns
95-- [ "orderVal" ::: 'NotNull 'PGText
96-- , "customerVal" ::: 'NotNull 'PGFloat4
97-- , "shipperVal" ::: 'NotNull 'PGBool
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