11module Main (main) where
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 :: Connection '[] <- connectdb connectionString
31 Char8.putStrLn "setting up database"
32 connection1 <- flip execPQ connection0 $
34 ( createTable #students
35 ( (text & notNull) `As` #name
39 ( (int4 & notNull) `As` #col1
40 :* (int4 & notNull) `As` #col2
43 ( insertInto #table1 ( 1 `As` #col1 :* 2 `As` #col2 :* Nil ) )
45 ( insertInto #table1 ( 3 `As` #col1 :* 4 `As` #col2 :* Nil ) )
46 Char8.putStrLn "querying"
47 connection2 <- flip execPQ connection1 $ do
48 Just result <- pqExecNil $ select $ starFrom #table1
49 runMaybeT . runExceptT . flip runValue result $ do
50 value00 <- getValue (RowNumber 0) (columnNumber @0)
51 value01 <- getValue (RowNumber 0) (columnNumber @1)
52 value10 <- getValue (RowNumber 1) (columnNumber @0)
53 value11 <- getValue (RowNumber 1) (columnNumber @1)
54 row0 <- getRow (RowNumber 0)
55 row1 <- getRow (RowNumber 1)
57 print (value00 :: Int32)
58 print (value01 :: Int32)
59 print (value10 :: Int32)
60 print (value11 :: Int32)
61 print (row0 :: NP I '[Int32,Int32])
62 print (row1 :: NP I '[Int32,Int32])
63 Char8.putStrLn "tearing down database"
64 connection3 :: Connection '[] <- flip execPQ connection2 $ pqExec
65 (dropTable #table1 :: Statement '[] '[] Tables '["students" ::: StudentsColumns])
66 & pqThenExec (dropTable #students)
70 '[ "col1" ::: 'Required ('NotNull 'PGInt4)
71 , "col2" ::: 'Required ('NotNull 'PGInt4)
73-- type SumAndCol1 = '[ "sum" ::: 'NotNull 'PGInt4, "col1" ::: 'NotNull 'PGInt4]
74type StudentsColumns = '["name" ::: 'Required ('NotNull 'PGText)]
75type Tables = '[ "table1" ::: Columns, "students" ::: StudentsColumns]
77-- [ "orderID" ::: 'NotNull 'PGInt4
78-- , "orderVal" ::: 'NotNull 'PGText
79-- , "customerID" ::: 'NotNull 'PGInt4
80-- , "shipperID" ::: 'NotNull 'PGInt4
82-- type CustomerColumns =
83-- [ "customerID" ::: 'NotNull 'PGInt4, "customerVal" ::: 'NotNull 'PGFloat4 ]
84-- type ShipperColumns =
85-- [ "shipperID" ::: 'NotNull 'PGInt4, "shipperVal" ::: 'NotNull 'PGBool ]
87-- [ "shippers" ::: ShipperColumns
88-- , "customers" ::: CustomerColumns
89-- , "orders" ::: OrderColumns
92-- [ "orderVal" ::: 'NotNull 'PGText
93-- , "customerVal" ::: 'NotNull 'PGFloat4
94-- , "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