Use show instances for a shortcut

This commit is contained in:
Joe Nelson
2015-11-20 10:29:08 -08:00
parent d2d86b35c4
commit f54742186b
4 changed files with 17 additions and 21 deletions
+1 -4
View File
@@ -75,10 +75,7 @@ app dbStructure conf reqBody req =
let
-- TODO: blow up for Left values (there is a middleware that checks the headers)
contentType = either (const ApplicationJSON) id (iAccepts intent)
contentTypeS ct = case ct of
ApplicationJSON -> "application/json"
TextCSV -> "text/csv"
contentTypeH = (hContentType, contentTypeS contentType) in
contentTypeH = (hContentType, cs $ show contentType) in
case (iAction intent, iTarget intent, iPayload intent) of
+2 -14
View File
@@ -321,20 +321,8 @@ orderF ts =
queryTerm :: OrderTerm -> Text
queryTerm t = " "
<> cs (pgFmtIdent $ otTerm t) <> " "
<> sqlOrderDirection (otDirection t) <> " "
<> maybe "" sqlOrderNulls (otNullOrder t) <> " "
sqlOrderDirection :: OrderDirection -> SqlFragment
sqlOrderDirection d =
case d of
OrderDesc -> "desc"
OrderAsc -> "asc"
sqlOrderNulls :: OrderNulls -> SqlFragment
sqlOrderNulls d =
case d of
OrderNullsFirst -> "nulls first"
OrderNullsLast -> "nulls last"
<> (cs.show) (otDirection t) <> " "
<> maybe "" (cs.show) (otNullOrder t) <> " "
insertableValue :: JSON.Value -> SqlFragment
insertableValue JSON.Null = "null"
+5 -1
View File
@@ -32,6 +32,10 @@ data Target = TargetIdent QualifiedIdentifier
-- | Enumeration of currently supported content types for
-- route responses and upload payloads
data ContentType = ApplicationJSON | TextCSV deriving Eq
instance Show ContentType where
show ApplicationJSON = "application/json"
show TextCSV = "text/csv"
-- | When Hasql supports the COPY command then we can
-- have a special payload just for CSV, but until
-- then CSV is converted to a JSON array.
@@ -128,7 +132,7 @@ userIntent schema req reqBody =
method = requestMethod req
isTargetingProc = fromMaybe False $ (== "rpc") <$> listToMaybe path
hdrs = requestHeaders req
qParams = [(cs k, cs <$> v)|(k,v) <- queryString req]
qParams = [(cs k, cs <$> v)|(k,v) <- queryString req]
lookupHeader = flip lookup hdrs
hasPrefer val = any (\(h,v) -> h == "Prefer" && v == val) hdrs
singular = hasPrefer "plurality=singular"
+9 -2
View File
@@ -50,8 +50,15 @@ data PrimaryKey = PrimaryKey {
, pkName :: Text
} deriving (Show, Eq)
data OrderDirection = OrderAsc | OrderDesc deriving (Show, Eq)
data OrderNulls = OrderNullsFirst | OrderNullsLast deriving (Show, Eq)
data OrderDirection = OrderAsc | OrderDesc deriving (Eq)
instance Show OrderDirection where
show OrderAsc = "asc"
show OrderDesc = "desc"
data OrderNulls = OrderNullsFirst | OrderNullsLast deriving (Eq)
instance Show OrderNulls where
show OrderNullsFirst = "nulls first"
show OrderNullsLast = "nulls last"
data OrderTerm = OrderTerm {
otTerm :: Text