Last active
August 5, 2016 04:02
-
-
Save kika/4fe0549aadd9c36245954614af72970f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DBResponse where | |
import Prelude | |
import Data.Foreign | |
import Data.Foreign.Class | |
data Doc a = Doc { doc :: a } | |
data CustomerResp = CustomerResp { rows :: Array (Doc Customer) } | |
data Customer = Customer { | |
alias :: String | |
, dalias :: String | |
, name :: String | |
} | |
instance custRespIsForeign::IsForeign CustomerResp where | |
read value = do | |
rows <- readProp "rows" value | |
pure $ CustomerResp { rows } | |
instance custDocIsForeign::IsForeign (Doc Customer) where | |
read value = do | |
doc <- readProp "doc" value | |
pure $ (Doc doc) | |
instance customerIsForeign::IsForeign Customer where | |
read value = do | |
alias <- readProp "alias" value | |
dalias <- readProp "dalias" value | |
name <- readProp "name" value | |
pure $ Customer {alias, dalias, name} | |
readCustomer json = | |
readJSON json :: F CustomerResp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
No type class instance was found for | |
Data.Foreign.Class.IsForeign { doc :: Customer } | |
in value declaration custDocIsForeign |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"rows": [ | |
{ | |
"id": "customer:foobar", | |
"doc": { | |
"alias": "foobar", | |
"dalias": "foobar", | |
"name": "Foobar", | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment