From ce378e6b3a93230faa48095a4394d868edafa581 Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Thu, 13 Apr 2023 17:18:43 -0500 Subject: [PATCH] refactor: clarify Scalar type It now contains the type of the scalar. This way we can discriminate the void type in a more obvious way. --- src/PostgREST/Error.hs | 2 +- src/PostgREST/SchemaCache.hs | 9 +++------ src/PostgREST/SchemaCache/Routine.hs | 10 +++++----- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/PostgREST/Error.hs b/src/PostgREST/Error.hs index 5aab087b91..810bf40314 100644 --- a/src/PostgREST/Error.hs +++ b/src/PostgREST/Error.hs @@ -283,7 +283,7 @@ noRelBetweenHint parent child schema allRels = ("Perhaps you meant '" <>) <$> -- to all the overloaded functions' params using the form "param1, param2, param3, ..." -- and shows the best match as hint. -- --- >>> let procsDesc = [Routine {pdParams = [RoutineParam {ppName="val"}, RoutineParam {ppName="param"}, RoutineParam {ppName="name"}]}, Routine {pdParams = [RoutineParam {ppName="id"}, RoutineParam {ppName="attr"}]}] +-- >>> let procsDesc = [Function {pdParams = [RoutineParam {ppName="val"}, RoutineParam {ppName="param"}, RoutineParam {ppName="name"}]}, Function {pdParams = [RoutineParam {ppName="id"}, RoutineParam {ppName="attr"}]}] -- -- >>> noRpcHint "api" "test" ["vall", "pqaram", "nam"] procs procsDesc -- Just "Perhaps you meant to call the function api.test(name, param, val)" diff --git a/src/PostgREST/SchemaCache.hs b/src/PostgREST/SchemaCache.hs index cd61e0dcad..2cbf5c37f8 100644 --- a/src/PostgREST/SchemaCache.hs +++ b/src/PostgREST/SchemaCache.hs @@ -247,7 +247,6 @@ decodeFuncs = <*> column HD.text <*> column HD.bool <*> column HD.bool - <*> column HD.bool <*> column HD.bool) <*> (parseVolatility <$> column HD.char) <*> column HD.bool @@ -255,16 +254,15 @@ decodeFuncs = addKey :: Routine -> (QualifiedIdentifier, Routine) addKey pd = (QualifiedIdentifier (pdSchema pd) (pdName pd), pd) - parseRetType :: Text -> Text -> Bool -> Bool -> Bool -> Bool -> RetType - parseRetType schema name isSetOf isComposite isVoid isCompositeAlias - | isVoid = Single $ Scalar True + parseRetType :: Text -> Text -> Bool -> Bool -> Bool -> RetType + parseRetType schema name isSetOf isComposite isCompositeAlias | isSetOf = SetOf pgType | otherwise = Single pgType where qi = QualifiedIdentifier schema name pgType | isComposite = Composite qi isCompositeAlias - | otherwise = Scalar False + | otherwise = Scalar qi parseVolatility :: Char -> FuncVolatility parseVolatility v | v == 'i' = Immutable @@ -339,7 +337,6 @@ funcsSqlQuery pgVer = [q| -- if any TABLE, INOUT or OUT arguments present, treat as composite or COALESCE(proargmodes::text[] && '{t,b,o}', false) ) AS rettype_is_composite, - ('void'::regtype = t.oid) AS rettype_is_void, bt.oid <> bt.base as rettype_is_composite_alias, p.provolatile, p.provariadic > 0 as hasvariadic diff --git a/src/PostgREST/SchemaCache/Routine.hs b/src/PostgREST/SchemaCache/Routine.hs index 2a5c0e7fcf..568d734d90 100644 --- a/src/PostgREST/SchemaCache/Routine.hs +++ b/src/PostgREST/SchemaCache/Routine.hs @@ -25,7 +25,7 @@ import PostgREST.SchemaCache.Identifiers (QualifiedIdentifier (..), import Protolude data PgType - = Scalar Bool -- True if the type is void + = Scalar QualifiedIdentifier | Composite QualifiedIdentifier Bool -- True if the composite is a domain alias(used to work around a bug in pg 11 and 12, see QueryBuilder.hs) deriving (Eq, Ord, Generic, JSON.ToJSON) @@ -72,12 +72,12 @@ type RoutineMap = HM.HashMap QualifiedIdentifier [Routine] funcReturnsScalar :: Routine -> Bool funcReturnsScalar proc = case proc of - Function{pdReturnType = Single (Scalar _)} -> True + Function{pdReturnType = Single (Scalar{})} -> True _ -> False funcReturnsSetOfScalar :: Routine -> Bool funcReturnsSetOfScalar proc = case proc of - Function{pdReturnType = SetOf (Scalar _)} -> True + Function{pdReturnType = SetOf (Scalar{})} -> True _ -> False funcReturnsCompositeAlias :: Routine -> Bool @@ -93,8 +93,8 @@ funcReturnsSingleComposite proc = case proc of funcReturnsVoid :: Routine -> Bool funcReturnsVoid proc = case proc of - Function{pdReturnType = Single (Scalar True)} -> True - _ -> False + Function{pdReturnType = Single (Scalar (QualifiedIdentifier "pg_catalog" "void"))} -> True + _ -> False funcTableName :: Routine -> Maybe TableName funcTableName proc = case pdReturnType proc of