Merge pull request #2324 from robx/ghc92

Update GHC to 9.2.2 (fixes #2288)
This commit is contained in:
Robert
2022-06-16 18:45:10 +02:00
committed by GitHub
16 changed files with 169 additions and 112 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ let
"postgrest"; "postgrest";
compiler = compiler =
"ghc8107"; "ghc922";
# PostgREST source files, filtered based on the rules in the .gitignore files # PostgREST source files, filtered based on the rules in the .gitignore files
# and file extensions. We want to include as litte as possible, as the files # and file extensions. We want to include as litte as possible, as the files
+8 -8
View File
@@ -24,21 +24,22 @@ import qualified Data.Text as T
import qualified Data.Text.IO as T import qualified Data.Text.IO as T
import qualified Dot import qualified Dot
import qualified GHC import qualified GHC
import qualified GHC.Paths
import qualified Language.Haskell.GHC.ExactPrint.Parsers as ExactPrint import qualified Language.Haskell.GHC.ExactPrint.Parsers as ExactPrint
import qualified Options.Applicative as O import qualified Options.Applicative as O
import qualified System.FilePath as FP import qualified System.FilePath as FP
import Bag (bagToList)
import Data.Aeson.Encode.Pretty (encodePretty) import Data.Aeson.Encode.Pretty (encodePretty)
import Data.Function ((&)) import Data.Function ((&))
import Data.List (intercalate) import Data.List (intercalate)
import Data.Maybe (catMaybes, mapMaybe) import Data.Maybe (catMaybes, mapMaybe)
import Data.Text (Text) import Data.Text (Text)
import GHC.Data.Bag (bagToList)
import GHC.Generics (Generic) import GHC.Generics (Generic)
import GHC.Hs.Extension (GhcPs) import GHC.Hs.Extension (GhcPs)
import Module (moduleNameString) import GHC.Types.Name.Occurrence (occNameString)
import OccName (occNameString) import GHC.Types.Name.Reader (rdrNameOcc)
import RdrName (rdrNameOcc) import GHC.Unit.Module.Name (moduleNameString)
import System.Directory.Recursive (getFilesRecursive) import System.Directory.Recursive (getFilesRecursive)
import System.Exit (exitFailure) import System.Exit (exitFailure)
@@ -197,11 +198,11 @@ sourceSymbols source = do
return $ concatMap (importSymbols source filepath . GHC.unLoc) hsmodImports return $ concatMap (importSymbols source filepath . GHC.unLoc) hsmodImports
-- | Parse a Haskell module -- | Parse a Haskell module
parseModule :: String -> IO (GHC.HsModule GhcPs) parseModule :: FilePath -> IO GHC.HsModule
parseModule filepath = do parseModule filepath = do
result <- ExactPrint.parseModule filepath result <- ExactPrint.parseModule GHC.Paths.libdir filepath
case result of case result of
Right (_, hsmod) -> Right hsmod ->
return $ GHC.unLoc hsmod return $ GHC.unLoc hsmod
Left errs -> Left errs ->
fail $ "Errors with " <> show filepath <> ":\n " fail $ "Errors with " <> show filepath <> ":\n "
@@ -212,7 +213,6 @@ parseModule filepath = do
-- If the import is a wildcard, i.e. no symbols are selected for import, then -- If the import is a wildcard, i.e. no symbols are selected for import, then
-- only one item is returned. -- only one item is returned.
importSymbols :: FilePath -> FilePath -> GHC.ImportDecl GhcPs -> [ImportedSymbol] importSymbols :: FilePath -> FilePath -> GHC.ImportDecl GhcPs -> [ImportedSymbol]
importSymbols _ _ (GHC.XImportDecl _) = mempty
importSymbols source filepath GHC.ImportDecl{..} = importSymbols source filepath GHC.ImportDecl{..} =
case ideclHiding of case ideclHiding of
Just (hiding, syms) -> Just (hiding, syms) ->
+19
View File
@@ -70,6 +70,25 @@ let
hspec-wai-json = hspec-wai-json =
lib.dontCheck (lib.unmarkBroken prev.hspec-wai-json); lib.dontCheck (lib.unmarkBroken prev.hspec-wai-json);
ptr =
prev.callHackageDirect
{
pkg = "ptr";
ver = "0.16.8.2";
sha256 = "sha256-Ei2GeQ0AjoxvsvmWbdPELPLtSaowoaj9IzsIiySgkAQ=";
}
{ };
weeder =
lib.dontCheck (prev.callHackageDirect
{
pkg = "weeder";
ver = "2.4.0";
sha256 = "sha256-Nhp8EogHJ5SIr67060TPEvQbN/ECg3cRJFQnUtJUyC0=";
}
{ });
} // extraOverrides final prev; } // extraOverrides final prev;
in in
{ {
+1
View File
@@ -58,6 +58,7 @@ let
defaultCabalPackageVersionComingWithGhc = defaultCabalPackageVersionComingWithGhc =
{ {
ghc8107 = "Cabal_3_2_1_0"; ghc8107 = "Cabal_3_2_1_0";
ghc922 = "Cabal_3_6_3_0";
}."${compiler}"; }."${compiler}";
# The static-haskell-nix 'survey' derives a full static set of Haskell # The static-haskell-nix 'survey' derives a full static set of Haskell
+15 -13
View File
@@ -62,19 +62,21 @@ library
PostgREST.RangeQuery PostgREST.RangeQuery
PostgREST.Request.ApiRequest PostgREST.Request.ApiRequest
PostgREST.Request.DbRequestBuilder PostgREST.Request.DbRequestBuilder
PostgREST.Request.MutateQuery
PostgREST.Request.Preferences PostgREST.Request.Preferences
PostgREST.Request.Types
PostgREST.Request.QueryParams PostgREST.Request.QueryParams
PostgREST.Request.ReadQuery
PostgREST.Request.Types
PostgREST.Version PostgREST.Version
PostgREST.Workers PostgREST.Workers
other-modules: Paths_postgrest other-modules: Paths_postgrest
build-depends: base >= 4.9 && < 4.16 build-depends: base >= 4.9 && < 4.17
, HTTP >= 4000.3.7 && < 4000.4 , HTTP >= 4000.3.7 && < 4000.4
, Ranged-sets >= 0.3 && < 0.5 , Ranged-sets >= 0.3 && < 0.5
, aeson >= 2.0.3 && < 2.1 , aeson >= 2.0.3 && < 2.1
, auto-update >= 0.1.4 && < 0.2 , auto-update >= 0.1.4 && < 0.2
, base64-bytestring >= 1 && < 1.3 , base64-bytestring >= 1 && < 1.3
, bytestring >= 0.10.8 && < 0.11 , bytestring >= 0.10.8 && < 0.12
, case-insensitive >= 1.2 && < 1.3 , case-insensitive >= 1.2 && < 1.3
, cassava >= 0.4.5 && < 0.6 , cassava >= 0.4.5 && < 0.6
, configurator-pg >= 0.2 && < 0.3 , configurator-pg >= 0.2 && < 0.3
@@ -93,7 +95,7 @@ library
, insert-ordered-containers >= 0.2.2 && < 0.3 , insert-ordered-containers >= 0.2.2 && < 0.3
, interpolatedstring-perl6 >= 1 && < 1.1 , interpolatedstring-perl6 >= 1 && < 1.1
, jose >= 0.8.5.1 && < 0.10 , jose >= 0.8.5.1 && < 0.10
, lens >= 4.14 && < 5.1 , lens >= 4.14 && < 5.2
, lens-aeson >= 1.0.1 && < 1.2 , lens-aeson >= 1.0.1 && < 1.2
, mtl >= 2.2.2 && < 2.3 , mtl >= 2.2.2 && < 2.3
, network >= 2.6 && < 3.2 , network >= 2.6 && < 3.2
@@ -106,7 +108,7 @@ library
, scientific >= 0.3.4 && < 0.4 , scientific >= 0.3.4 && < 0.4
, swagger2 >= 2.4 && < 2.9 , swagger2 >= 2.4 && < 2.9
, text >= 1.2.2 && < 1.3 , text >= 1.2.2 && < 1.3
, time >= 1.6 && < 1.11 , time >= 1.6 && < 1.12
, unordered-containers >= 0.2.8 && < 0.3 , unordered-containers >= 0.2.8 && < 0.3
, vault >= 0.3.1.5 && < 0.4 , vault >= 0.3.1.5 && < 0.4
, vector >= 0.11 && < 0.13 , vector >= 0.11 && < 0.13
@@ -147,7 +149,7 @@ executable postgrest
NoImplicitPrelude NoImplicitPrelude
hs-source-dirs: main hs-source-dirs: main
main-is: Main.hs main-is: Main.hs
build-depends: base >= 4.9 && < 4.16 build-depends: base >= 4.9 && < 4.17
, containers >= 0.5.7 && < 0.7 , containers >= 0.5.7 && < 0.7
, postgrest , postgrest
, protolude >= 0.3.1 && < 0.4 , protolude >= 0.3.1 && < 0.4
@@ -210,13 +212,13 @@ test-suite spec
Feature.RpcPreRequestGucsSpec Feature.RpcPreRequestGucsSpec
SpecHelper SpecHelper
TestTypes TestTypes
build-depends: base >= 4.9 && < 4.16 build-depends: base >= 4.9 && < 4.17
, aeson >= 2.0.3 && < 2.1 , aeson >= 2.0.3 && < 2.1
, aeson-qq >= 0.8.1 && < 0.9 , aeson-qq >= 0.8.1 && < 0.9
, async >= 2.1.1 && < 2.3 , async >= 2.1.1 && < 2.3
, auto-update >= 0.1.4 && < 0.2 , auto-update >= 0.1.4 && < 0.2
, base64-bytestring >= 1 && < 1.3 , base64-bytestring >= 1 && < 1.3
, bytestring >= 0.10.8 && < 0.11 , bytestring >= 0.10.8 && < 0.12
, case-insensitive >= 1.2 && < 1.3 , case-insensitive >= 1.2 && < 1.3
, containers >= 0.5.7 && < 0.7 , containers >= 0.5.7 && < 0.7
, hasql-pool >= 0.5 && < 0.6 , hasql-pool >= 0.5 && < 0.6
@@ -226,7 +228,7 @@ test-suite spec
, hspec-wai >= 0.10 && < 0.12 , hspec-wai >= 0.10 && < 0.12
, hspec-wai-json >= 0.10 && < 0.12 , hspec-wai-json >= 0.10 && < 0.12
, http-types >= 0.12.3 && < 0.13 , http-types >= 0.12.3 && < 0.13
, lens >= 4.14 && < 5.1 , lens >= 4.14 && < 5.2
, lens-aeson >= 1.0.1 && < 1.2 , lens-aeson >= 1.0.1 && < 1.2
, monad-control >= 1.0.1 && < 1.1 , monad-control >= 1.0.1 && < 1.1
, postgrest , postgrest
@@ -253,10 +255,10 @@ test-suite querycost
hs-source-dirs: test/spec hs-source-dirs: test/spec
main-is: QueryCost.hs main-is: QueryCost.hs
other-modules: SpecHelper other-modules: SpecHelper
build-depends: base >= 4.9 && < 4.16 build-depends: base >= 4.9 && < 4.17
, aeson >= 2.0.3 && < 2.1 , aeson >= 2.0.3 && < 2.1
, base64-bytestring >= 1 && < 1.3 , base64-bytestring >= 1 && < 1.3
, bytestring >= 0.10.8 && < 0.11 , bytestring >= 0.10.8 && < 0.12
, case-insensitive >= 1.2 && < 1.3 , case-insensitive >= 1.2 && < 1.3
, containers >= 0.5.7 && < 0.7 , containers >= 0.5.7 && < 0.7
, contravariant >= 1.4 && < 1.6 , contravariant >= 1.4 && < 1.6
@@ -268,7 +270,7 @@ test-suite querycost
, hspec >= 2.3 && < 2.9 , hspec >= 2.3 && < 2.9
, hspec-wai >= 0.10 && < 0.12 , hspec-wai >= 0.10 && < 0.12
, http-types >= 0.12.3 && < 0.13 , http-types >= 0.12.3 && < 0.13
, lens >= 4.14 && < 5.1 , lens >= 4.14 && < 5.2
, lens-aeson >= 1.0.1 && < 1.2 , lens-aeson >= 1.0.1 && < 1.2
, postgrest , postgrest
, process >= 1.4.2 && < 1.7 , process >= 1.4.2 && < 1.7
@@ -288,7 +290,7 @@ test-suite doctests
NoImplicitPrelude NoImplicitPrelude
hs-source-dirs: test/doc hs-source-dirs: test/doc
main-is: Main.hs main-is: Main.hs
build-depends: base >= 4.9 && < 4.16 build-depends: base >= 4.9 && < 4.17
, doctest >= 0.8 , doctest >= 0.8
, postgrest , postgrest
, pretty-simple , pretty-simple
+1 -1
View File
@@ -82,7 +82,7 @@ import PostgREST.Request.Preferences (PreferCount (..),
PreferRepresentation (..), PreferRepresentation (..),
toAppliedHeader) toAppliedHeader)
import PostgREST.Request.QueryParams (QueryParams (..)) import PostgREST.Request.QueryParams (QueryParams (..))
import PostgREST.Request.Types (ReadRequest, fstFieldNames) import PostgREST.Request.ReadQuery (ReadRequest, fstFieldNames)
import PostgREST.Version (prettyVersion) import PostgREST.Version (prettyVersion)
import PostgREST.Workers (connectionWorker, listener) import PostgREST.Workers (connectionWorker, listener)
+3 -1
View File
@@ -28,7 +28,9 @@ import PostgREST.DbStructure.Relationship (Cardinality (..),
import PostgREST.Request.Preferences (PreferResolution (..)) import PostgREST.Request.Preferences (PreferResolution (..))
import PostgREST.Query.SqlFragment import PostgREST.Query.SqlFragment
import PostgREST.RangeQuery (allRange) import PostgREST.RangeQuery (allRange)
import PostgREST.Request.MutateQuery
import PostgREST.Request.ReadQuery
import PostgREST.Request.Types import PostgREST.Request.Types
import Protolude import Protolude
+2 -1
View File
@@ -50,6 +50,7 @@ import PostgREST.DbStructure.Identifiers (FieldName,
QualifiedIdentifier (..)) QualifiedIdentifier (..))
import PostgREST.RangeQuery (NonnegRange, allRange, import PostgREST.RangeQuery (NonnegRange, allRange,
rangeLimit, rangeOffset) rangeLimit, rangeOffset)
import PostgREST.Request.ReadQuery (SelectItem)
import PostgREST.Request.Types (Alias, Field, Filter (..), import PostgREST.Request.Types (Alias, Field, Filter (..),
FtsOperator (..), FtsOperator (..),
JoinCondition (..), JoinCondition (..),
@@ -61,7 +62,7 @@ import PostgREST.Request.Types (Alias, Field, Filter (..),
Operation (..), Operation (..),
OrderDirection (..), OrderDirection (..),
OrderNulls (..), OrderNulls (..),
OrderTerm (..), SelectItem, OrderTerm (..),
SimpleOperator (..), SimpleOperator (..),
TrileanVal (..)) TrileanVal (..))
+7 -6
View File
@@ -36,13 +36,14 @@ rangeParse :: BS.ByteString -> NonnegRange
rangeParse range = do rangeParse range = do
let rangeRegex = "^([0-9]+)-([0-9]*)$" :: BS.ByteString let rangeRegex = "^([0-9]+)-([0-9]*)$" :: BS.ByteString
case listToMaybe (range =~ rangeRegex :: [[BS.ByteString]]) of case range =~ rangeRegex :: [[BS.ByteString]] of
Just parsedRange -> [[_, l, u]] ->
let [_, mLower, mUpper] = readMaybe . BS.unpack <$> parsedRange let lower = maybe emptyRange rangeGeq (readInteger l)
lower = maybe emptyRange rangeGeq mLower upper = maybe allRange rangeLeq (readInteger u) in
upper = maybe allRange rangeLeq mUpper in
rangeIntersection lower upper rangeIntersection lower upper
Nothing -> allRange _ -> allRange
where
readInteger = readMaybe . BS.unpack
rangeRequested :: RequestHeaders -> NonnegRange rangeRequested :: RequestHeaders -> NonnegRange
rangeRequested headers = maybe allRange rangeParse $ lookup hRange headers rangeRequested headers = maybe allRange rangeParse $ lookup hRange headers
+4 -2
View File
@@ -48,7 +48,9 @@ import PostgREST.Request.ApiRequest (Action (..),
Mutation (..), Mutation (..),
Payload (..)) Payload (..))
import PostgREST.Request.MutateQuery
import PostgREST.Request.Preferences import PostgREST.Request.Preferences
import PostgREST.Request.ReadQuery as ReadQuery
import PostgREST.Request.Types import PostgREST.Request.Types
import qualified PostgREST.Request.QueryParams as QueryParams import qualified PostgREST.Request.QueryParams as QueryParams
@@ -263,7 +265,7 @@ addFilters ApiRequest{..} rReq =
addFilterToNode :: (EmbedPath, Filter) -> Either ApiRequestError ReadRequest -> Either ApiRequestError ReadRequest addFilterToNode :: (EmbedPath, Filter) -> Either ApiRequestError ReadRequest -> Either ApiRequestError ReadRequest
addFilterToNode = addFilterToNode =
updateNode (\flt (Node (q@Select {where_=lf}, i) f) -> Node (q{where_=addFilterToLogicForest flt lf}::ReadQuery, i) f) updateNode (\flt (Node (q@Select {where_=lf}, i) f) -> Node (q{ReadQuery.where_=addFilterToLogicForest flt lf}, i) f)
addOrders :: ApiRequest -> ReadRequest -> Either ApiRequestError ReadRequest addOrders :: ApiRequest -> ReadRequest -> Either ApiRequestError ReadRequest
addOrders ApiRequest{..} rReq = addOrders ApiRequest{..} rReq =
@@ -295,7 +297,7 @@ addLogicTrees ApiRequest{..} rReq =
QueryParams.QueryParams{..} = iQueryParams QueryParams.QueryParams{..} = iQueryParams
addLogicTreeToNode :: (EmbedPath, LogicTree) -> Either ApiRequestError ReadRequest -> Either ApiRequestError ReadRequest addLogicTreeToNode :: (EmbedPath, LogicTree) -> Either ApiRequestError ReadRequest -> Either ApiRequestError ReadRequest
addLogicTreeToNode = updateNode (\t (Node (q@Select{where_=lf},i) f) -> Node (q{where_=t:lf}::ReadQuery, i) f) addLogicTreeToNode = updateNode (\t (Node (q@Select{where_=lf},i) f) -> Node (q{ReadQuery.where_=t:lf}, i) f)
-- Find a Node of the Tree and apply a function to it -- Find a Node of the Tree and apply a function to it
updateNode :: (a -> ReadRequest -> ReadRequest) -> (EmbedPath, a) -> Either ApiRequestError ReadRequest -> Either ApiRequestError ReadRequest updateNode :: (a -> ReadRequest -> ReadRequest) -> (EmbedPath, a) -> Either ApiRequestError ReadRequest -> Either ApiRequestError ReadRequest
+45
View File
@@ -0,0 +1,45 @@
module PostgREST.Request.MutateQuery
( MutateQuery(..)
, MutateRequest
)
where
import qualified Data.ByteString.Lazy as LBS
import qualified Data.Set as S
import PostgREST.DbStructure.Identifiers (FieldName,
QualifiedIdentifier)
import PostgREST.RangeQuery (NonnegRange)
import PostgREST.Request.Preferences (PreferResolution)
import PostgREST.Request.Types (LogicTree, OrderTerm)
import Protolude
type MutateRequest = MutateQuery
data MutateQuery
= Insert
{ in_ :: QualifiedIdentifier
, insCols :: S.Set FieldName
, insBody :: Maybe LBS.ByteString
, onConflict :: Maybe (PreferResolution, [FieldName])
, where_ :: [LogicTree]
, returning :: [FieldName]
}
| Update
{ in_ :: QualifiedIdentifier
, updCols :: S.Set FieldName
, updBody :: Maybe LBS.ByteString
, where_ :: [LogicTree]
, pkFilters :: [FieldName]
, mutRange :: NonnegRange
, mutOrder :: [OrderTerm]
, returning :: [FieldName]
}
| Delete
{ in_ :: QualifiedIdentifier
, where_ :: [LogicTree]
, mutRange :: NonnegRange
, mutOrder :: [OrderTerm]
, returning :: [FieldName]
}
+12 -10
View File
@@ -44,16 +44,18 @@ import PostgREST.RangeQuery (NonnegRange, allRange,
rangeGeq, rangeLimit, rangeGeq, rangeLimit,
rangeOffset, restrictRange) rangeOffset, restrictRange)
import PostgREST.Request.Types (EmbedParam (..), EmbedPath, Field, import PostgREST.Request.ReadQuery (SelectItem)
Filter (..), FtsOperator (..), import PostgREST.Request.Types (EmbedParam (..), EmbedPath, Field,
JoinType (..), JsonOperand (..), Filter (..), FtsOperator (..),
JsonOperation (..), JsonPath, ListVal, JoinType (..), JsonOperand (..),
LogicOperator (..), LogicTree (..), JsonOperation (..), JsonPath,
OpExpr (..), Operation (..), ListVal, LogicOperator (..),
OrderDirection (..), OrderNulls (..), LogicTree (..), OpExpr (..),
OrderTerm (..), QPError (..), Operation (..),
SelectItem, SimpleOperator (..), OrderDirection (..),
SingleVal, TrileanVal (..)) OrderNulls (..), OrderTerm (..),
QPError (..), SimpleOperator (..),
SingleVal, TrileanVal (..))
import Protolude hiding (try) import Protolude hiding (try)
+48
View File
@@ -0,0 +1,48 @@
module PostgREST.Request.ReadQuery
( ReadNode
, ReadQuery(..)
, ReadRequest
, SelectItem
, fstFieldNames
) where
import Data.Tree (Tree (..))
import PostgREST.DbStructure.Identifiers (FieldName,
QualifiedIdentifier)
import PostgREST.DbStructure.Relationship (Relationship)
import PostgREST.RangeQuery (NonnegRange)
import PostgREST.Request.Types (Alias, Cast, Depth, Field,
Hint, JoinCondition,
JoinType, LogicTree,
NodeName, OrderTerm)
import Protolude
type ReadRequest = Tree ReadNode
type ReadNode =
(ReadQuery, (NodeName, Maybe Relationship, Maybe Alias, Maybe Hint, Maybe JoinType, Depth))
-- | The select value in `/tbl?select=alias:field::cast`
type SelectItem = (Field, Maybe Cast, Maybe Alias, Maybe Hint, Maybe JoinType)
data ReadQuery = Select
{ select :: [SelectItem]
, from :: QualifiedIdentifier
-- ^ A table alias is used in case of self joins
, fromAlias :: Maybe Alias
-- ^ Only used for Many to Many joins. Parent and Child joins use explicit joins.
, implicitJoins :: [QualifiedIdentifier]
, where_ :: [LogicTree]
, joinConditions :: [JoinCondition]
, order :: [OrderTerm]
, range_ :: NonnegRange
}
deriving (Eq)
-- First level FieldNames(e.g get a,b from /table?select=a,b,other(c,d))
fstFieldNames :: ReadRequest -> [FieldName]
fstFieldNames (Node (sel, _) _) =
fst . (\(f, _, _, _, _) -> f) <$> select sel
+1 -67
View File
@@ -1,6 +1,7 @@
{-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE DuplicateRecordFields #-}
module PostgREST.Request.Types module PostgREST.Request.Types
( Alias ( Alias
, Cast
, Depth , Depth
, EmbedParam(..) , EmbedParam(..)
, ApiRequestError(..) , ApiRequestError(..)
@@ -19,8 +20,6 @@ module PostgREST.Request.Types
, ListVal , ListVal
, LogicOperator(..) , LogicOperator(..)
, LogicTree(..) , LogicTree(..)
, MutateQuery(..)
, MutateRequest
, NodeName , NodeName
, OpExpr(..) , OpExpr(..)
, Operation (..) , Operation (..)
@@ -28,21 +27,13 @@ module PostgREST.Request.Types
, OrderNulls(..) , OrderNulls(..)
, OrderTerm(..) , OrderTerm(..)
, QPError(..) , QPError(..)
, ReadNode
, ReadQuery(..)
, ReadRequest
, SelectItem
, SingleVal , SingleVal
, TrileanVal(..) , TrileanVal(..)
, fstFieldNames
, SimpleOperator(..) , SimpleOperator(..)
, FtsOperator(..) , FtsOperator(..)
) where ) where
import qualified Data.ByteString.Lazy as LBS import qualified Data.ByteString.Lazy as LBS
import qualified Data.Set as S
import Data.Tree (Tree (..))
import PostgREST.ContentType (ContentType (..)) import PostgREST.ContentType (ContentType (..))
import PostgREST.DbStructure.Identifiers (FieldName, import PostgREST.DbStructure.Identifiers (FieldName,
@@ -50,8 +41,6 @@ import PostgREST.DbStructure.Identifiers (FieldName,
import PostgREST.DbStructure.Proc (ProcDescription (..), import PostgREST.DbStructure.Proc (ProcDescription (..),
ProcParam (..)) ProcParam (..))
import PostgREST.DbStructure.Relationship (Relationship) import PostgREST.DbStructure.Relationship (Relationship)
import PostgREST.RangeQuery (NonnegRange)
import PostgREST.Request.Preferences (PreferResolution)
import Protolude import Protolude
@@ -76,30 +65,11 @@ data ApiRequestError
data QPError = QPError Text Text data QPError = QPError Text Text
type ReadRequest = Tree ReadNode
type MutateRequest = MutateQuery
type CallRequest = CallQuery type CallRequest = CallQuery
type ReadNode =
(ReadQuery, (NodeName, Maybe Relationship, Maybe Alias, Maybe Hint, Maybe JoinType, Depth))
type NodeName = Text type NodeName = Text
type Depth = Integer type Depth = Integer
data ReadQuery = Select
{ select :: [SelectItem]
, from :: QualifiedIdentifier
-- ^ A table alias is used in case of self joins
, fromAlias :: Maybe Alias
-- ^ Only used for Many to Many joins. Parent and Child joins use explicit joins.
, implicitJoins :: [QualifiedIdentifier]
, where_ :: [LogicTree]
, joinConditions :: [JoinCondition]
, order :: [OrderTerm]
, range_ :: NonnegRange
}
deriving (Eq)
data JoinCondition = data JoinCondition =
JoinCondition JoinCondition
(QualifiedIdentifier, FieldName) (QualifiedIdentifier, FieldName)
@@ -123,33 +93,6 @@ data OrderNulls
| OrderNullsLast | OrderNullsLast
deriving (Eq) deriving (Eq)
data MutateQuery
= Insert
{ in_ :: QualifiedIdentifier
, insCols :: S.Set FieldName
, insBody :: Maybe LBS.ByteString
, onConflict :: Maybe (PreferResolution, [FieldName])
, where_ :: [LogicTree]
, returning :: [FieldName]
}
| Update
{ in_ :: QualifiedIdentifier
, updCols :: S.Set FieldName
, updBody :: Maybe LBS.ByteString
, where_ :: [LogicTree]
, pkFilters :: [FieldName]
, mutRange :: NonnegRange
, mutOrder :: [OrderTerm]
, returning :: [FieldName]
}
| Delete
{ in_ :: QualifiedIdentifier
, where_ :: [LogicTree]
, mutRange :: NonnegRange
, mutOrder :: [OrderTerm]
, returning :: [FieldName]
}
data CallQuery = FunctionCall data CallQuery = FunctionCall
{ funCQi :: QualifiedIdentifier { funCQi :: QualifiedIdentifier
, funCParams :: CallParams , funCParams :: CallParams
@@ -163,9 +106,6 @@ data CallParams
= KeyParams [ProcParam] -- ^ Call with key params: func(a := val1, b:= val2) = KeyParams [ProcParam] -- ^ Call with key params: func(a := val1, b:= val2)
| OnePosParam ProcParam -- ^ Call with positional params(only one supported): func(val) | OnePosParam ProcParam -- ^ Call with positional params(only one supported): func(val)
-- | The select value in `/tbl?select=alias:field::cast`
type SelectItem = (Field, Maybe Cast, Maybe Alias, Maybe Hint, Maybe JoinType)
type Field = (FieldName, JsonPath) type Field = (FieldName, JsonPath)
type Cast = Text type Cast = Text
type Alias = Text type Alias = Text
@@ -205,12 +145,6 @@ data JsonOperand
| JIdx { jVal :: Text } | JIdx { jVal :: Text }
deriving (Eq) deriving (Eq)
-- First level FieldNames(e.g get a,b from /table?select=a,b,other(c,d))
fstFieldNames :: ReadRequest -> [FieldName]
fstFieldNames (Node (sel, _) _) =
fst . (\(f, _, _, _, _) -> f) <$> select sel
-- | Boolean logic expression tree e.g. "and(name.eq.N,or(id.eq.1,id.eq.2))" is: -- | Boolean logic expression tree e.g. "and(name.eq.N,or(id.eq.1,id.eq.2))" is:
-- --
-- And -- And
+1 -1
View File
@@ -498,7 +498,7 @@ spec actualPgVersion = do
[json|[ { "k":"圍棋", "extra":"" } ]|] [json|[ { "k":"圍棋", "extra":"" } ]|]
{ matchStatus = 201 } { matchStatus = 201 }
let Just location = lookup hLocation $ simpleHeaders p Just location <- pure $ lookup hLocation $ simpleHeaders p
get location get location
`shouldRespondWith` `shouldRespondWith`
[json|[ { "k":"圍棋", "extra":"" } ]|] [json|[ { "k":"圍棋", "extra":"" } ]|]
+1 -1
View File
@@ -52,7 +52,7 @@ validateOpenApiResponse headers = do
let respHeaders = simpleHeaders r in let respHeaders = simpleHeaders r in
respHeaders `shouldSatisfy` respHeaders `shouldSatisfy`
\hs -> ("Content-Type", "application/openapi+json; charset=utf-8") `elem` hs \hs -> ("Content-Type", "application/openapi+json; charset=utf-8") `elem` hs
let Just body = decode (simpleBody r) Just body <- pure $ decode (simpleBody r)
Just schema <- liftIO $ decode <$> BL.readFile "test/spec/fixtures/openapi.json" Just schema <- liftIO $ decode <$> BL.readFile "test/spec/fixtures/openapi.json"
let args :: M.Map Text Value let args :: M.Map Text Value
args = M.fromList args = M.fromList