Skip to content

Instantly share code, notes, and snippets.

@kika
Last active August 5, 2016 04:02
Show Gist options
  • Save kika/4fe0549aadd9c36245954614af72970f to your computer and use it in GitHub Desktop.
Save kika/4fe0549aadd9c36245954614af72970f to your computer and use it in GitHub Desktop.
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
No type class instance was found for
Data.Foreign.Class.IsForeign { doc :: Customer }
in value declaration custDocIsForeign
{
"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