diff options
author | Joris | 2017-06-05 18:02:13 +0200 |
---|---|---|
committer | Joris | 2017-06-05 18:02:13 +0200 |
commit | 0b191f5c48edffc9da3e38c284e9640fd82e7cb1 (patch) | |
tree | c729e53822e7c41c1a854d82d25636e58ee65c9f /src/server/Model/Frequency.hs | |
parent | 5c110716cfda6e616a795edd12f2012b132dca9f (diff) |
Replace persistent by sqlite-simple
Diffstat (limited to 'src/server/Model/Frequency.hs')
-rw-r--r-- | src/server/Model/Frequency.hs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/server/Model/Frequency.hs b/src/server/Model/Frequency.hs index a6ba55c..f9958e1 100644 --- a/src/server/Model/Frequency.hs +++ b/src/server/Model/Frequency.hs @@ -6,21 +6,28 @@ module Model.Frequency ( Frequency(..) ) where -import GHC.Generics - -import Web.Scotty - -import Database.Persist.TH - import Data.Aeson +import Database.SQLite.Simple (SQLData(SQLText)) +import Database.SQLite.Simple.FromField (fieldData, FromField(fromField)) +import Database.SQLite.Simple.Ok (Ok(Ok, Errors)) +import Database.SQLite.Simple.ToField (ToField(toField)) +import GHC.Generics +import qualified Data.Text as T +import Web.Scotty (parseParam, Parsable, readEither) data Frequency = Punctual | Monthly deriving (Eq, Show, Read, Generic) -derivePersistField "Frequency" - instance Parsable Frequency where parseParam = readEither instance FromJSON Frequency instance ToJSON Frequency + +instance FromField Frequency where + fromField field = case fieldData field of + SQLText text -> Ok (read (T.unpack text) :: Frequency) + _ -> Errors [error "SQLText field required for frequency"] + +instance ToField Frequency where + toField frequency = SQLText . T.pack . show $ frequency |