Remove pjType from ActionCreate
* Remove isSingle from ActionCreate * Remove nRows from ActionCreate
This commit is contained in:
committed by
Steve Chávez
parent
00a0d8b9b7
commit
16059ad470
+28
-30
@@ -146,41 +146,39 @@ app dbStructure proc conf apiRequest =
|
|||||||
)
|
)
|
||||||
] (toS body)
|
] (toS body)
|
||||||
|
|
||||||
(ActionCreate, TargetIdent (QualifiedIdentifier tSchema tName), Just PayloadJSON{pjRaw, pjType}) ->
|
(ActionCreate, TargetIdent (QualifiedIdentifier tSchema tName), Just PayloadJSON{pjRaw}) ->
|
||||||
case mutateSqlParts tSchema tName of
|
case mutateSqlParts tSchema tName of
|
||||||
Left errorResponse -> return errorResponse
|
Left errorResponse -> return errorResponse
|
||||||
Right (sq, mq) -> do
|
Right (sq, mq) -> do
|
||||||
let (isSingle, nRows) = case pjType of
|
let pkCols = tablePKCols dbStructure tSchema tName
|
||||||
PJArray len -> (len == 1, len)
|
stm = createWriteStatement sq mq
|
||||||
PJObject -> (True, 1)
|
(contentType == CTSingularJSON) True
|
||||||
|
(contentType == CTTextCSV) (iPreferRepresentation apiRequest) pkCols
|
||||||
|
row <- H.statement (toS pjRaw) stm
|
||||||
|
let (_, queryTotal, fs, body) = extractQueryResult row
|
||||||
|
headers = catMaybes [
|
||||||
|
if null fs
|
||||||
|
then Nothing
|
||||||
|
else Just (hLocation, "/" <> toS tName <> renderLocationFields fs)
|
||||||
|
, if iPreferRepresentation apiRequest == Full
|
||||||
|
then Just $ toHeader contentType
|
||||||
|
else Nothing
|
||||||
|
, Just . contentRangeH 1 0 $
|
||||||
|
toInteger <$> if shouldCount then Just queryTotal else Nothing
|
||||||
|
, if null pkCols
|
||||||
|
then Nothing
|
||||||
|
else (\x -> ("Preference-Applied", show x)) <$> iPreferResolution apiRequest
|
||||||
|
]
|
||||||
if contentType == CTSingularJSON
|
if contentType == CTSingularJSON
|
||||||
&& not isSingle
|
&& queryTotal /= 1
|
||||||
&& iPreferRepresentation apiRequest == Full
|
&& iPreferRepresentation apiRequest == Full
|
||||||
then return $ singularityError (toInteger nRows)
|
then do
|
||||||
else do
|
HT.condemn
|
||||||
let pkCols = tablePKCols dbStructure tSchema tName
|
return $ singularityError (toInteger queryTotal)
|
||||||
stm = createWriteStatement sq mq
|
else
|
||||||
(contentType == CTSingularJSON) isSingle
|
return . responseLBS status201 headers $
|
||||||
(contentType == CTTextCSV) (iPreferRepresentation apiRequest) pkCols
|
if iPreferRepresentation apiRequest == Full
|
||||||
row <- H.statement (toS pjRaw) stm
|
then toS body else ""
|
||||||
let (_, _, fs, body) = extractQueryResult row
|
|
||||||
headers = catMaybes [
|
|
||||||
if null fs
|
|
||||||
then Nothing
|
|
||||||
else Just (hLocation, "/" <> toS tName <> renderLocationFields fs)
|
|
||||||
, if iPreferRepresentation apiRequest == Full
|
|
||||||
then Just $ toHeader contentType
|
|
||||||
else Nothing
|
|
||||||
, Just . contentRangeH 1 0 $
|
|
||||||
toInteger <$> if shouldCount then Just nRows else Nothing
|
|
||||||
, if null pkCols
|
|
||||||
then Nothing
|
|
||||||
else (\x -> ("Preference-Applied", show x)) <$> iPreferResolution apiRequest
|
|
||||||
]
|
|
||||||
|
|
||||||
return . responseLBS status201 headers $
|
|
||||||
if iPreferRepresentation apiRequest == Full
|
|
||||||
then toS body else ""
|
|
||||||
|
|
||||||
(ActionUpdate, TargetIdent (QualifiedIdentifier tSchema tName), Just p@PayloadJSON{pjRaw}) ->
|
(ActionUpdate, TargetIdent (QualifiedIdentifier tSchema tName), Just p@PayloadJSON{pjRaw}) ->
|
||||||
case (mutateSqlParts tSchema tName, pjIsEmpty p, iPreferRepresentation apiRequest == Full) of
|
case (mutateSqlParts tSchema tName, pjIsEmpty p, iPreferRepresentation apiRequest == Full) of
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ createReadStatement selectQuery countQuery isSingle countTotal asCsv binaryField
|
|||||||
createWriteStatement :: SqlQuery -> SqlQuery -> Bool -> Bool -> Bool ->
|
createWriteStatement :: SqlQuery -> SqlQuery -> Bool -> Bool -> Bool ->
|
||||||
PreferRepresentation -> [Text] ->
|
PreferRepresentation -> [Text] ->
|
||||||
H.Statement ByteString (Maybe ResultsWithCount)
|
H.Statement ByteString (Maybe ResultsWithCount)
|
||||||
createWriteStatement selectQuery mutateQuery wantSingle wantHdrs asCsv rep pKeys =
|
createWriteStatement selectQuery mutateQuery wantSingle isInsert asCsv rep pKeys =
|
||||||
unicodeStatement sql (HE.param HE.unknown) decodeStandardMay True
|
unicodeStatement sql (HE.param HE.unknown) decodeStandardMay True
|
||||||
|
|
||||||
where
|
where
|
||||||
@@ -123,9 +123,14 @@ createWriteStatement selectQuery mutateQuery wantSingle wantHdrs asCsv rep pKeys
|
|||||||
cols = intercalate ", " [
|
cols = intercalate ", " [
|
||||||
"'' AS total_result_set", -- when updateing it does not make sense
|
"'' AS total_result_set", -- when updateing it does not make sense
|
||||||
"pg_catalog.count(_postgrest_t) AS page_total",
|
"pg_catalog.count(_postgrest_t) AS page_total",
|
||||||
if wantHdrs
|
if isInsert
|
||||||
then "coalesce(" <> locationF pKeys <> ", " <> noLocationF <> ")"
|
then unwords [
|
||||||
else noLocationF <> " AS header",
|
"CASE",
|
||||||
|
"WHEN pg_catalog.count(_postgrest_t) = 1 THEN",
|
||||||
|
"coalesce(" <> locationF pKeys <> ", " <> noLocationF <> ")",
|
||||||
|
"ELSE " <> noLocationF,
|
||||||
|
"END AS header"]
|
||||||
|
else noLocationF <> "AS header",
|
||||||
if rep == Full
|
if rep == Full
|
||||||
then bodyF <> " AS body"
|
then bodyF <> " AS body"
|
||||||
else "''"
|
else "''"
|
||||||
|
|||||||
Reference in New Issue
Block a user