blob: 41a325dca1d237155b808ec6686199d2157b7614 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Model.Frequency () 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))
import Common.Model (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
|