gonito/PersistTeamActionType.hs

21 lines
583 B
Haskell
Raw Normal View History

2021-03-03 09:19:34 +01:00
module PersistTeamActionType where
import ClassyPrelude.Yesod
import Database.Persist.Sql
import qualified Data.Text as T
data TeamActionType = TeamCreation | TeamJoining | TeamLeaving | TeamInvitation
2021-03-03 09:19:34 +01:00
deriving (Eq, Show, Read)
instance PersistField TeamActionType where
toPersistValue m = PersistText (T.pack $ show m)
fromPersistValue (PersistText t) = case readMay t of
Just val -> Right val
Nothing -> Left ("Unexpected value '" ++ t ++ "'")
fromPersistValue _ = Left "Unexpected value"
instance PersistFieldSql TeamActionType where
sqlType _ = SqlString