Use show instances for a shortcut
This commit is contained in:
@@ -75,10 +75,7 @@ app dbStructure conf reqBody req =
|
|||||||
let
|
let
|
||||||
-- TODO: blow up for Left values (there is a middleware that checks the headers)
|
-- TODO: blow up for Left values (there is a middleware that checks the headers)
|
||||||
contentType = either (const ApplicationJSON) id (iAccepts intent)
|
contentType = either (const ApplicationJSON) id (iAccepts intent)
|
||||||
contentTypeS ct = case ct of
|
contentTypeH = (hContentType, cs $ show contentType) in
|
||||||
ApplicationJSON -> "application/json"
|
|
||||||
TextCSV -> "text/csv"
|
|
||||||
contentTypeH = (hContentType, contentTypeS contentType) in
|
|
||||||
|
|
||||||
case (iAction intent, iTarget intent, iPayload intent) of
|
case (iAction intent, iTarget intent, iPayload intent) of
|
||||||
|
|
||||||
|
|||||||
@@ -321,20 +321,8 @@ orderF ts =
|
|||||||
queryTerm :: OrderTerm -> Text
|
queryTerm :: OrderTerm -> Text
|
||||||
queryTerm t = " "
|
queryTerm t = " "
|
||||||
<> cs (pgFmtIdent $ otTerm t) <> " "
|
<> cs (pgFmtIdent $ otTerm t) <> " "
|
||||||
<> sqlOrderDirection (otDirection t) <> " "
|
<> (cs.show) (otDirection t) <> " "
|
||||||
<> maybe "" sqlOrderNulls (otNullOrder t) <> " "
|
<> maybe "" (cs.show) (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"
|
|
||||||
|
|
||||||
insertableValue :: JSON.Value -> SqlFragment
|
insertableValue :: JSON.Value -> SqlFragment
|
||||||
insertableValue JSON.Null = "null"
|
insertableValue JSON.Null = "null"
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ data Target = TargetIdent QualifiedIdentifier
|
|||||||
-- | Enumeration of currently supported content types for
|
-- | Enumeration of currently supported content types for
|
||||||
-- route responses and upload payloads
|
-- route responses and upload payloads
|
||||||
data ContentType = ApplicationJSON | TextCSV deriving Eq
|
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
|
-- | When Hasql supports the COPY command then we can
|
||||||
-- have a special payload just for CSV, but until
|
-- have a special payload just for CSV, but until
|
||||||
-- then CSV is converted to a JSON array.
|
-- then CSV is converted to a JSON array.
|
||||||
@@ -128,7 +132,7 @@ userIntent schema req reqBody =
|
|||||||
method = requestMethod req
|
method = requestMethod req
|
||||||
isTargetingProc = fromMaybe False $ (== "rpc") <$> listToMaybe path
|
isTargetingProc = fromMaybe False $ (== "rpc") <$> listToMaybe path
|
||||||
hdrs = requestHeaders req
|
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
|
lookupHeader = flip lookup hdrs
|
||||||
hasPrefer val = any (\(h,v) -> h == "Prefer" && v == val) hdrs
|
hasPrefer val = any (\(h,v) -> h == "Prefer" && v == val) hdrs
|
||||||
singular = hasPrefer "plurality=singular"
|
singular = hasPrefer "plurality=singular"
|
||||||
|
|||||||
@@ -50,8 +50,15 @@ data PrimaryKey = PrimaryKey {
|
|||||||
, pkName :: Text
|
, pkName :: Text
|
||||||
} deriving (Show, Eq)
|
} deriving (Show, Eq)
|
||||||
|
|
||||||
data OrderDirection = OrderAsc | OrderDesc deriving (Show, Eq)
|
data OrderDirection = OrderAsc | OrderDesc deriving (Eq)
|
||||||
data OrderNulls = OrderNullsFirst | OrderNullsLast deriving (Show, 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 {
|
data OrderTerm = OrderTerm {
|
||||||
otTerm :: Text
|
otTerm :: Text
|
||||||
|
|||||||
Reference in New Issue
Block a user