Created
February 8, 2016 23:29
-
-
Save begriffs/52b869a17be350d66cd0 to your computer and use it in GitHub Desktop.
remove all actual updating
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/PostgREST/App.hs b/src/PostgREST/App.hs | |
| index d1d27b4..abf3d8f 100644 | |
| --- a/src/PostgREST/App.hs | |
| +++ b/src/PostgREST/App.hs | |
| @@ -53,6 +53,7 @@ import PostgREST.QueryBuilder ( callProc | |
| , addRelations | |
| , createReadStatement | |
| , createWriteStatement | |
| + , lockRowExclusive | |
| , ResultsWithCount | |
| ) | |
| @@ -119,19 +120,12 @@ app dbStructure conf reqBody req = | |
| ] | |
| $ if iPreferRepresentation apiRequest == Full then cs body else "" | |
| - (ActionUpdate, TargetIdent qi, Just payload@(PayloadJSON uniform)) -> | |
| + (ActionUpdate, TargetIdent qi, Just (PayloadJSON _)) -> | |
| case mutateSqlParts of | |
| Left e -> return $ responseLBS status400 [jsonH] $ cs e | |
| - Right (sq,mq) -> do | |
| - let stm = createWriteStatement qi sq mq False (iPreferRepresentation apiRequest) [] (contentType == TextCSV) payload | |
| - row <- H.query uniform stm | |
| - let (_, queryTotal, _, body) = extractQueryResult row | |
| - r = contentRangeH 0 (toInteger $ queryTotal-1) (toInteger <$> Just queryTotal) | |
| - s = case () of _ | queryTotal == 0 -> status404 | |
| - | iPreferRepresentation apiRequest == Full -> status200 | |
| - | otherwise -> status204 | |
| - return $ responseLBS s [contentTypeH, r] | |
| - $ if iPreferRepresentation apiRequest == Full then cs body else "" | |
| + Right _ -> do | |
| + lockRowExclusive qi | |
| + return $ responseLBS status200 [] "" | |
| (ActionDelete, TargetIdent qi, Nothing) -> | |
| case mutateSqlParts of | |
| diff --git a/src/PostgREST/QueryBuilder.hs b/src/PostgREST/QueryBuilder.hs | |
| index 0da8118..103999e 100644 | |
| --- a/src/PostgREST/QueryBuilder.hs | |
| +++ b/src/PostgREST/QueryBuilder.hs | |
| @@ -19,6 +19,7 @@ module PostgREST.QueryBuilder ( | |
| , createReadStatement | |
| , createWriteStatement | |
| , inTransaction | |
| + , lockRowExclusive | |
| , operators | |
| , pgFmtIdent | |
| , pgFmtLit | |
| @@ -361,6 +362,11 @@ requestToQuery schema (DbMutate (Delete mainTbl conditions)) = | |
| ("WHERE " <> intercalate " AND " ( map (pgFmtCondition qi ) conditions )) `emptyOnNull` conditions | |
| ] | |
| +lockRowExclusive :: QualifiedIdentifier -> H.Session () | |
| +lockRowExclusive qi = | |
| + H.sql [qc| LOCK TABLE {fromQi qi} IN SHARE ROW EXCLUSIVE MODE; |] | |
| + | |
| + | |
| sourceCTEName :: SqlFragment | |
| sourceCTEName = "pg_source" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment