From 43e2bd75d40d534bf19c2574c276bd2c64826535 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Thu, 31 Dec 2020 14:05:42 +0100 Subject: [PATCH] refactor: Move addHasVariadic to SQL --- .../checked-shell-script/checked-shell-script.nix | 10 +++++++++- src/PostgREST/DbStructure.hs | 10 ++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/nix/overlays/checked-shell-script/checked-shell-script.nix b/nix/overlays/checked-shell-script/checked-shell-script.nix index a776e0c69bf..4e21d26db3d 100644 --- a/nix/overlays/checked-shell-script/checked-shell-script.nix +++ b/nix/overlays/checked-shell-script/checked-shell-script.nix @@ -22,6 +22,14 @@ let '' #!${runtimeShell} set -euo pipefail + + # make sure that no script creates conflicting tix files + # postgrest-coverage will override HPCTIXFILE to make proper use of it + if test ! -v HPCTIXFILE; then + hpctixdir=$(mktemp -d) + export HPCTIXFILE="$hpctixdir"/postgrest.tix + trap 'rm -rf $hpctixdir' EXIT + fi '' + lib.optionalString inRootDir '' cd "$(${git}/bin/git rev-parse --show-toplevel)" @@ -32,7 +40,7 @@ let exit 1 fi '' - + text; + + "(${text})"; checkPhase = '' diff --git a/src/PostgREST/DbStructure.hs b/src/PostgREST/DbStructure.hs index 6682a0c259f..4cf98b77f8e 100644 --- a/src/PostgREST/DbStructure.hs +++ b/src/PostgREST/DbStructure.hs @@ -129,7 +129,7 @@ sourceColumnFromRow allCols (s1,t1,c1,s2,t2,c2) = (,) <$> col1 <*> col2 decodeProcs :: HD.Result ProcsMap decodeProcs = -- Duplicate rows for a function means they're overloaded, order these by least args according to ProcDescription Ord instance - map sort . M.fromListWith (++) . map ((\(x,y) -> (x, [y])) . addKey . addHasVariadic) <$> HD.rowList procRow + map sort . M.fromListWith (++) . map ((\(x,y) -> (x, [y])) . addKey) <$> HD.rowList procRow where procRow = ProcDescription <$> column HD.text @@ -142,10 +142,7 @@ decodeProcs = <*> column HD.bool <*> column HD.bool) <*> (parseVolatility <$> column HD.char) - <*> pure False - - addHasVariadic :: ProcDescription -> ProcDescription - addHasVariadic pd@ProcDescription{pdArgs} = pd{pdHasVariadic=isJust $ find pgaVar pdArgs} + <*> column HD.bool addKey :: ProcDescription -> (QualifiedIdentifier, ProcDescription) addKey pd = (QualifiedIdentifier (pdSchema pd) (pdName pd), pd) @@ -232,7 +229,8 @@ procsSqlQuery = [q| -- if any INOUT or OUT arguments present, treat as composite or COALESCE(proargmodes::text[] && '{b,o}', false) ) AS rettype_is_composite, - p.provolatile + p.provolatile, + p.provariadic > 0 AS hasvariadic FROM pg_proc p JOIN pg_namespace pn ON pn.oid = p.pronamespace JOIN base_types bt ON bt.oid = p.prorettype