@@ -25,7 +25,7 @@ import GHC.Generics (Generic)
2525import Witch (from )
2626
2727-- | Data type we want to persist.
28- data Person = Person { age :: ! Int64 , name :: ! String }
28+ data Person = Person { age :: ! Int64 , name :: ! String , ownsDog :: ! ( Bool ) }
2929 deriving (Generic , PrimaryKey "name", Show )
3030
3131-- | Connection string to access our PostgreSQL DB.
@@ -68,24 +68,30 @@ instance MonadDbNewConn AppM PSQL.Connection where
6868main :: IO ()
6969main = do
7070 let c = connStr " 127.0.0.1" 5432 " postgres" " demo" " demo"
71- let john = Person 70 " John"
71+ let john = Person 70 " John" False
7272 let info m s = do
7373 putStrLn $ " \n " <> m
7474 print =<< runAppM c (tx $ execute s)
7575
7676 info " Create table if not exists" $ createTable @ Person True
7777 info " Delete all" $ deleteAll @ Person -- Clear table before tutorial.
7878
79- info " Insert one" $ returning $ insertOne $ john
79+ let x = returning $ insertOne john -- Insert One (Just Person) Person
80+ --
81+ -- HasOutputType (Insert o (Just Person) a) where
82+ -- outputType = OutputTypeRows
83+ --
84+ -- ParseOutput DbValue s where
85+ info " Insert one" x
8086
8187 info " Insert many" $
82- insertMany [Person 25 " Alice" , Person 25 " Bob" ]
88+ insertMany [Person 25 " Alice" True , Person 25 " Bob" False ]
8389
8490 info " Insert many, returning" $
85- returning $ insertMany [Person 26 " Charlie" , Person 26 " Dee" ]
91+ returning $ insertMany [Person 26 " Charlie" False , Person 26 " Dee" True ]
8692
8793 info " Insert many, returning age" $
88- insertMany [Person 27 " Enid" , Person 27 " Flavio" ] ==> field @ " age"
94+ insertMany [Person 27 " Enid" False , Person 27 " Flavio" True ] ==> field @ " age"
8995
9096 info " Select all" $ selectAll @ Person
9197
0 commit comments