Simplify serialization of location header

Possible after bug fix in a Hasql that we picked up with the new
dependency bounds in #606. Also includes test to ensure location header
is omitted on bulk insert.
This commit is contained in:
Christopher League
2016-05-22 21:54:26 -04:00
parent 4f53aef74f
commit 0940b2dccf
3 changed files with 19 additions and 10 deletions
+5 -4
View File
@@ -130,9 +130,10 @@ app dbStructure conf apiRequest =
let pKeys = map pkName $ filter (filterPk schema table) allPrKeys -- would it be ok to move primary key detection in the query itself?
let stm = createWriteStatement qi sq mq isSingle (iPreferRepresentation apiRequest) pKeys (contentType == TextCSV) payload
row <- H.query uniform stm
let (_, _, locationFieldsOpt, body) = extractQueryResult row
mkHeader fs = [(hLocation, "/" <> cs table <> renderLocationFields fs)]
header = maybe [] mkHeader locationFieldsOpt
let (_, _, fs, body) = extractQueryResult row
header =
if null fs then []
else [(hLocation, "/" <> cs table <> renderLocationFields fs)]
return $ if iPreferRepresentation apiRequest == Full
then responseLBS status201 (contentTypeH : header) (cs body)
@@ -391,4 +392,4 @@ instance ToJSON TableOptions where
extractQueryResult :: Maybe ResultsWithCount -> ResultsWithCount
extractQueryResult = fromMaybe (Nothing, 0, Nothing, "")
extractQueryResult = fromMaybe (Nothing, 0, [], "")