aboutsummaryrefslogtreecommitdiff
path: root/server/src/Job/Kind.hs
blob: 17997f7fb3c7aaa59eebcbb806141b396482a90c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Job.Kind
  ( Kind(..)
  ) where

import qualified Data.Text                        as T
import           Database.SQLite.Simple           (SQLData (SQLText))
import           Database.SQLite.Simple.FromField (FromField (fromField),
                                                   fieldData)
import           Database.SQLite.Simple.Ok        (Ok (Errors, Ok))
import           Database.SQLite.Simple.ToField   (ToField (toField))

data Kind =
  MonthlyPayment
  | WeeklyReport
  deriving (Eq, Show, Read)

instance FromField Kind where
  fromField field = case fieldData field of
    SQLText text -> Ok (read (T.unpack text) :: Kind)
    _            -> Errors [error "SQLText field required for job kind"]

instance ToField Kind where
  toField kind = SQLText . T.pack . show $ kind