disambiguate range selection when plurality=singular
This commit is contained in:
@@ -20,6 +20,7 @@ import PostgREST.RangeQuery (NonnegRange, rangeRequested)
|
|||||||
import PostgREST.Types (QualifiedIdentifier (..),
|
import PostgREST.Types (QualifiedIdentifier (..),
|
||||||
Schema, Payload(..),
|
Schema, Payload(..),
|
||||||
UniformObjects(..))
|
UniformObjects(..))
|
||||||
|
import Data.Ranged.Ranges (singletonRange)
|
||||||
|
|
||||||
type RequestBody = BL.ByteString
|
type RequestBody = BL.ByteString
|
||||||
|
|
||||||
@@ -114,7 +115,7 @@ userApiRequest schema req reqBody =
|
|||||||
|
|
||||||
ApiRequest {
|
ApiRequest {
|
||||||
iAction = action
|
iAction = action
|
||||||
, iRange = if singular then Nothing else rangeRequested hdrs
|
, iRange = if singular then Just (singletonRange 0) else rangeRequested hdrs
|
||||||
, iTarget = target
|
, iTarget = target
|
||||||
, iAccepts = pickContentType $ lookupHeader "accept"
|
, iAccepts = pickContentType $ lookupHeader "accept"
|
||||||
, iPayload = relevantPayload
|
, iPayload = relevantPayload
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import qualified Data.Aeson as JSON
|
|||||||
|
|
||||||
import PostgREST.RangeQuery (NonnegRange, rangeLimit, rangeOffset)
|
import PostgREST.RangeQuery (NonnegRange, rangeLimit, rangeOffset)
|
||||||
import Control.Error (note, fromMaybe, mapMaybe)
|
import Control.Error (note, fromMaybe, mapMaybe)
|
||||||
import Data.Maybe (isNothing)
|
|
||||||
import Control.Monad (join)
|
import Control.Monad (join)
|
||||||
import qualified Data.HashMap.Strict as HM
|
import qualified Data.HashMap.Strict as HM
|
||||||
import Data.List (find)
|
import Data.List (find)
|
||||||
@@ -55,8 +54,6 @@ import Data.Scientific ( FPFormat (..)
|
|||||||
)
|
)
|
||||||
import Prelude hiding (unwords)
|
import Prelude hiding (unwords)
|
||||||
|
|
||||||
import Data.Ranged.Ranges (singletonRange)
|
|
||||||
|
|
||||||
type PStmt = H.Stmt P.Postgres
|
type PStmt = H.Stmt P.Postgres
|
||||||
instance Monoid PStmt where
|
instance Monoid PStmt where
|
||||||
mappend (B.Stmt query params prep) (B.Stmt query' params' prep') =
|
mappend (B.Stmt query params prep) (B.Stmt query' params' prep') =
|
||||||
@@ -74,7 +71,7 @@ createReadStatement selectQuery range isSingle countTable asCsv =
|
|||||||
if asCsv
|
if asCsv
|
||||||
then asCsvF
|
then asCsvF
|
||||||
else if isSingle then asJsonSingleF else asJsonF
|
else if isSingle then asJsonSingleF else asJsonF
|
||||||
] selectStarF (if isNothing range && isSingle then Just $ singletonRange 0 else range)
|
] selectStarF range
|
||||||
) V.empty True
|
) V.empty True
|
||||||
|
|
||||||
createWriteStatement :: SqlQuery -> SqlQuery -> Bool -> Bool ->
|
createWriteStatement :: SqlQuery -> SqlQuery -> Bool -> Bool ->
|
||||||
|
|||||||
Reference in New Issue
Block a user