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