better table json properties.

This commit is contained in:
Adam C. Baker
2014-06-21 16:07:05 -07:00
parent c1da42ea3f
commit 57fa142af8
+8 -2
View File
@@ -16,17 +16,23 @@ import Network.Wai.Handler.Warp hiding (Connection)
import Network.HTTP.Types.Status
import qualified Data.Aeson as JSON
import Data.Aeson ((.=))
data Table = Table {
viewSchema :: String
, viewName :: String
, viewInsertable :: Bool
} deriving (Show, Generic)
} deriving (Show)
instance FromRow Table where
fromRow = Table <$> field <*> field <*> fmap toBool field
instance JSON.ToJSON Table
instance JSON.ToJSON Table where
toJSON v = JSON.object [
"schema" .= (viewSchema v),
"name" .= (viewName v),
"insertable" .= (viewInsertable v)
]
toBool :: String -> Bool
toBool = (== "YES")