haskell-relational-record/doc/slide/haskell-hackathon-201412/opaleye/Birthday.hs
2014-12-21 16:16:54 +09:00

25 lines
701 B
Haskell

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Birthday where
import Data.Time
import Opaleye
import Data.Profunctor.Product.TH
data Birthday' a b = Birthday { name :: a, day :: b }
type Birthday = Birthday' String Day
type BirthdayColumn = Birthday' (Column PGText) (Column PGDate)
$(makeAdaptorAndInstance "pBirthday" ''Birthday')
birthdayTable :: Table BirthdayColumn BirthdayColumn
birthdayTable = Table "birthdayTable"
(pBirthday Birthday { name = required "name"
, day = required "day" })
birthdayQuery :: Query BirthdayColumn
birthdayQuery = queryTable birthdayTable