Skip to content

Commit

Permalink
refactor: Move addHasVariadic to SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangwalther committed Dec 31, 2020
1 parent 519550e commit 43e2bd7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 9 additions & 1 deletion nix/overlays/checked-shell-script/checked-shell-script.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -32,7 +40,7 @@ let
exit 1
fi
''
+ text;
+ "(${text})";

checkPhase =
''
Expand Down
10 changes: 4 additions & 6 deletions src/PostgREST/DbStructure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 43e2bd7

Please sign in to comment.