From 57fa142af8167945018740e8f208bc5abcb77db8 Mon Sep 17 00:00:00 2001 From: "Adam C. Baker" Date: Sat, 21 Jun 2014 16:07:05 -0700 Subject: [PATCH] better table json properties. --- Main.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Main.hs b/Main.hs index 20dd69942..7e73b00bb 100644 --- a/Main.hs +++ b/Main.hs @@ -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")