From d945e8c06a36bdeaf1b669ea2f3bb50b6e383ab5 Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Mon, 3 Apr 2023 11:41:32 -0500 Subject: [PATCH] refactor: remove Maybe from RetType for Proc type --- src/PostgREST/SchemaCache.hs | 10 +++++----- src/PostgREST/SchemaCache/Proc.hs | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/PostgREST/SchemaCache.hs b/src/PostgREST/SchemaCache.hs index 14cd9428e..00a317f77 100644 --- a/src/PostgREST/SchemaCache.hs +++ b/src/PostgREST/SchemaCache.hs @@ -255,16 +255,16 @@ decodeProcs = addKey :: ProcDescription -> (QualifiedIdentifier, ProcDescription) addKey pd = (QualifiedIdentifier (pdSchema pd) (pdName pd), pd) - parseRetType :: Text -> Text -> Bool -> Bool -> Bool -> Maybe RetType + parseRetType :: Text -> Text -> Bool -> Bool -> Bool -> RetType parseRetType schema name isSetOf isComposite isVoid - | isVoid = Nothing - | isSetOf = Just (SetOf pgType) - | otherwise = Just (Single pgType) + | isVoid = Single $ Scalar True + | isSetOf = SetOf pgType + | otherwise = Single pgType where qi = QualifiedIdentifier schema name pgType | isComposite = Composite qi - | otherwise = Scalar + | otherwise = Scalar False parseVolatility :: Char -> ProcVolatility parseVolatility v | v == 'i' = Immutable diff --git a/src/PostgREST/SchemaCache/Proc.hs b/src/PostgREST/SchemaCache/Proc.hs index d3161cd36..eadbce34f 100644 --- a/src/PostgREST/SchemaCache/Proc.hs +++ b/src/PostgREST/SchemaCache/Proc.hs @@ -23,7 +23,7 @@ import PostgREST.SchemaCache.Identifiers (QualifiedIdentifier (..), import Protolude data PgType - = Scalar + = Scalar Bool -- True if the type is void | Composite QualifiedIdentifier deriving (Eq, Ord, Generic, JSON.ToJSON) @@ -43,7 +43,7 @@ data ProcDescription = ProcDescription , pdName :: Text , pdDescription :: Maybe Text , pdParams :: [ProcParam] - , pdReturnType :: Maybe RetType + , pdReturnType :: RetType , pdVolatility :: ProcVolatility , pdHasVariadic :: Bool } @@ -70,22 +70,22 @@ type ProcsMap = HM.HashMap QualifiedIdentifier [ProcDescription] procReturnsScalar :: ProcDescription -> Bool procReturnsScalar proc = case proc of - ProcDescription{pdReturnType = Just (Single Scalar)} -> True - ProcDescription{pdReturnType = Just (SetOf Scalar)} -> True + ProcDescription{pdReturnType = Single (Scalar _)} -> True + ProcDescription{pdReturnType = SetOf (Scalar _)} -> True _ -> False procReturnsSingle :: ProcDescription -> Bool procReturnsSingle proc = case proc of - ProcDescription{pdReturnType = Just (Single _)} -> True - _ -> False + ProcDescription{pdReturnType = Single _} -> True + _ -> False procReturnsVoid :: ProcDescription -> Bool procReturnsVoid proc = case proc of - ProcDescription{pdReturnType = Nothing} -> True - _ -> False + ProcDescription{pdReturnType = Single (Scalar True)} -> True + _ -> False procTableName :: ProcDescription -> Maybe TableName procTableName proc = case pdReturnType proc of - Just (SetOf (Composite qi)) -> Just $ qiName qi - Just (Single (Composite qi)) -> Just $ qiName qi + SetOf (Composite qi) -> Just $ qiName qi + Single (Composite qi) -> Just $ qiName qi _ -> Nothing