refactor: pass media type to Statements module
This commit is contained in:
committed by
Steve Chavez
parent
7a7ceaf39a
commit
0708f46df3
+3
-11
@@ -267,11 +267,8 @@ handleRead headersOnly identifier context@RequestContext{..} = do
|
|||||||
else
|
else
|
||||||
countQuery
|
countQuery
|
||||||
)
|
)
|
||||||
(iAcceptMediaType == MTSingularJSON)
|
|
||||||
(shouldCount iPreferCount)
|
(shouldCount iPreferCount)
|
||||||
(iAcceptMediaType == MTTextCSV)
|
iAcceptMediaType
|
||||||
(iAcceptMediaType == MTTextXML)
|
|
||||||
(iAcceptMediaType == MTGeoJSON)
|
|
||||||
bField
|
bField
|
||||||
configDbPreparedStatements
|
configDbPreparedStatements
|
||||||
|
|
||||||
@@ -462,10 +459,7 @@ handleInvoke invMethod proc context@RequestContext{..} = do
|
|||||||
(QueryBuilder.readRequestToQuery req)
|
(QueryBuilder.readRequestToQuery req)
|
||||||
(QueryBuilder.readRequestToCountQuery req)
|
(QueryBuilder.readRequestToCountQuery req)
|
||||||
(shouldCount iPreferCount)
|
(shouldCount iPreferCount)
|
||||||
(iAcceptMediaType == MTSingularJSON)
|
iAcceptMediaType
|
||||||
(iAcceptMediaType == MTTextCSV)
|
|
||||||
(iAcceptMediaType == MTTextXML)
|
|
||||||
(iAcceptMediaType == MTGeoJSON)
|
|
||||||
(iPreferParameters == Just MultipleObjects)
|
(iPreferParameters == Just MultipleObjects)
|
||||||
bField
|
bField
|
||||||
(configDbPreparedStatements ctxConfig)
|
(configDbPreparedStatements ctxConfig)
|
||||||
@@ -550,10 +544,8 @@ writeQuery mutation identifier@QualifiedIdentifier{..} isInsert pkCols context@R
|
|||||||
Statements.createWriteStatement
|
Statements.createWriteStatement
|
||||||
(QueryBuilder.readRequestToQuery readReq)
|
(QueryBuilder.readRequestToQuery readReq)
|
||||||
(QueryBuilder.mutateRequestToQuery mutateReq)
|
(QueryBuilder.mutateRequestToQuery mutateReq)
|
||||||
(iAcceptMediaType ctxApiRequest == MTSingularJSON)
|
|
||||||
isInsert
|
isInsert
|
||||||
(iAcceptMediaType ctxApiRequest == MTTextCSV)
|
(iAcceptMediaType ctxApiRequest)
|
||||||
(iAcceptMediaType ctxApiRequest == MTGeoJSON)
|
|
||||||
(iPreferRepresentation ctxApiRequest)
|
(iPreferRepresentation ctxApiRequest)
|
||||||
pkCols
|
pkCols
|
||||||
(configDbPreparedStatements ctxConfig)
|
(configDbPreparedStatements ctxConfig)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import PostgREST.Error (Error (..))
|
|||||||
import PostgREST.GucHeader (GucHeader)
|
import PostgREST.GucHeader (GucHeader)
|
||||||
|
|
||||||
import PostgREST.DbStructure.Identifiers (FieldName)
|
import PostgREST.DbStructure.Identifiers (FieldName)
|
||||||
|
import PostgREST.MediaType (MediaType (..))
|
||||||
import PostgREST.Query.SqlFragment
|
import PostgREST.Query.SqlFragment
|
||||||
import PostgREST.Request.Preferences
|
import PostgREST.Request.Preferences
|
||||||
|
|
||||||
@@ -43,10 +44,10 @@ import Protolude
|
|||||||
-}
|
-}
|
||||||
type ResultsWithCount = (Maybe Int64, Int64, [BS.ByteString], BS.ByteString, Either Error [GucHeader], Either Error (Maybe Status))
|
type ResultsWithCount = (Maybe Int64, Int64, [BS.ByteString], BS.ByteString, Either Error [GucHeader], Either Error (Maybe Status))
|
||||||
|
|
||||||
createWriteStatement :: SQL.Snippet -> SQL.Snippet -> Bool -> Bool -> Bool -> Bool ->
|
createWriteStatement :: SQL.Snippet -> SQL.Snippet -> Bool -> MediaType ->
|
||||||
PreferRepresentation -> [Text] -> Bool ->
|
PreferRepresentation -> [Text] -> Bool ->
|
||||||
SQL.Statement () ResultsWithCount
|
SQL.Statement () ResultsWithCount
|
||||||
createWriteStatement selectQuery mutateQuery wantSingle isInsert asCsv asGeoJson rep pKeys =
|
createWriteStatement selectQuery mutateQuery isInsert mediaType rep pKeys =
|
||||||
SQL.dynamicallyParameterized snippet decodeStandard
|
SQL.dynamicallyParameterized snippet decodeStandard
|
||||||
where
|
where
|
||||||
snippet =
|
snippet =
|
||||||
@@ -73,9 +74,9 @@ createWriteStatement selectQuery mutateQuery wantSingle isInsert asCsv asGeoJson
|
|||||||
|
|
||||||
bodyF
|
bodyF
|
||||||
| rep /= Full = "''"
|
| rep /= Full = "''"
|
||||||
| asCsv = asCsvF
|
| mediaType == MTTextCSV = asCsvF
|
||||||
| asGeoJson = asGeoJsonF
|
| mediaType == MTGeoJSON = asGeoJsonF
|
||||||
| wantSingle = asJsonSingleF False
|
| mediaType == MTSingularJSON = asJsonSingleF False
|
||||||
| otherwise = asJsonF False
|
| otherwise = asJsonF False
|
||||||
|
|
||||||
selectF
|
selectF
|
||||||
@@ -87,9 +88,9 @@ createWriteStatement selectQuery mutateQuery wantSingle isInsert asCsv asGeoJson
|
|||||||
decodeStandard =
|
decodeStandard =
|
||||||
fromMaybe (Nothing, 0, [], mempty, Right [], Right Nothing) <$> HD.rowMaybe standardRow
|
fromMaybe (Nothing, 0, [], mempty, Right [], Right Nothing) <$> HD.rowMaybe standardRow
|
||||||
|
|
||||||
createReadStatement :: SQL.Snippet -> SQL.Snippet -> Bool -> Bool -> Bool -> Bool -> Bool -> Maybe FieldName -> Bool ->
|
createReadStatement :: SQL.Snippet -> SQL.Snippet -> Bool -> MediaType -> Maybe FieldName -> Bool ->
|
||||||
SQL.Statement () ResultsWithCount
|
SQL.Statement () ResultsWithCount
|
||||||
createReadStatement selectQuery countQuery isSingle countTotal asCsv asXml asGeoJson binaryField =
|
createReadStatement selectQuery countQuery countTotal mediaType binaryField =
|
||||||
SQL.dynamicallyParameterized snippet decodeStandard
|
SQL.dynamicallyParameterized snippet decodeStandard
|
||||||
where
|
where
|
||||||
snippet =
|
snippet =
|
||||||
@@ -108,10 +109,10 @@ createReadStatement selectQuery countQuery isSingle countTotal asCsv asXml asGeo
|
|||||||
(countCTEF, countResultF) = countF countQuery countTotal
|
(countCTEF, countResultF) = countF countQuery countTotal
|
||||||
|
|
||||||
bodyF
|
bodyF
|
||||||
| asCsv = asCsvF
|
| mediaType == MTTextCSV = asCsvF
|
||||||
| isSingle = asJsonSingleF False
|
| mediaType == MTSingularJSON = asJsonSingleF False
|
||||||
| asGeoJson = asGeoJsonF
|
| mediaType == MTGeoJSON = asGeoJsonF
|
||||||
| isJust binaryField && asXml = asXmlF $ fromJust binaryField
|
| isJust binaryField && mediaType == MTTextXML = asXmlF $ fromJust binaryField
|
||||||
| isJust binaryField = asBinaryF $ fromJust binaryField
|
| isJust binaryField = asBinaryF $ fromJust binaryField
|
||||||
| otherwise = asJsonF False
|
| otherwise = asJsonF False
|
||||||
|
|
||||||
@@ -132,9 +133,9 @@ standardRow = (,,,,,) <$> nullableColumn HD.int8 <*> column HD.int8
|
|||||||
type ProcResults = (Maybe Int64, Int64, ByteString, Either Error [GucHeader], Either Error (Maybe Status))
|
type ProcResults = (Maybe Int64, Int64, ByteString, Either Error [GucHeader], Either Error (Maybe Status))
|
||||||
|
|
||||||
callProcStatement :: Bool -> Bool -> SQL.Snippet -> SQL.Snippet -> SQL.Snippet -> Bool ->
|
callProcStatement :: Bool -> Bool -> SQL.Snippet -> SQL.Snippet -> SQL.Snippet -> Bool ->
|
||||||
Bool -> Bool -> Bool -> Bool -> Bool -> Maybe FieldName -> Bool ->
|
MediaType -> Bool -> Maybe FieldName -> Bool ->
|
||||||
SQL.Statement () ProcResults
|
SQL.Statement () ProcResults
|
||||||
callProcStatement returnsScalar returnsSingle callProcQuery selectQuery countQuery countTotal asSingle asCsv asXml asGeoJson multObjects binaryField =
|
callProcStatement returnsScalar returnsSingle callProcQuery selectQuery countQuery countTotal mediaType multObjects binaryField =
|
||||||
SQL.dynamicallyParameterized snippet decodeProc
|
SQL.dynamicallyParameterized snippet decodeProc
|
||||||
where
|
where
|
||||||
snippet =
|
snippet =
|
||||||
@@ -152,13 +153,12 @@ callProcStatement returnsScalar returnsSingle callProcQuery selectQuery countQue
|
|||||||
(countCTEF, countResultF) = countF countQuery countTotal
|
(countCTEF, countResultF) = countF countQuery countTotal
|
||||||
|
|
||||||
bodyF
|
bodyF
|
||||||
| asSingle = asJsonSingleF returnsScalar
|
| mediaType == MTSingularJSON = asJsonSingleF returnsScalar
|
||||||
| asCsv = asCsvF
|
| mediaType == MTTextCSV = asCsvF
|
||||||
| asGeoJson = asGeoJsonF
|
| mediaType == MTGeoJSON = asGeoJsonF
|
||||||
| isJust binaryField && asXml = asXmlF $ fromJust binaryField
|
| isJust binaryField && mediaType == MTTextXML = asXmlF $ fromJust binaryField
|
||||||
| isJust binaryField = asBinaryF $ fromJust binaryField
|
| isJust binaryField = asBinaryF $ fromJust binaryField
|
||||||
| returnsSingle
|
| returnsSingle && not multObjects = asJsonSingleF returnsScalar
|
||||||
&& not multObjects = asJsonSingleF returnsScalar
|
|
||||||
| otherwise = asJsonF returnsScalar
|
| otherwise = asJsonF returnsScalar
|
||||||
|
|
||||||
decodeProc :: HD.Result ProcResults
|
decodeProc :: HD.Result ProcResults
|
||||||
|
|||||||
Reference in New Issue
Block a user