refactor: Simplify funcsSqlQuery

This allows to re-use ANY($$1) in the next commit.
This commit is contained in:
Wolfgang Walther
2024-07-09 08:31:31 +02:00
committed by Wolfgang Walther
parent 735e1edbf6
commit f31848f2e5
2 changed files with 7 additions and 8 deletions
+1 -1
View File
@@ -181,7 +181,7 @@ actionQuery (MaybeDb plan@InspectPlan{ipSchema=tSchema}) AppConfig{..} _ _ sCach
tableAccess <- SQL.statement [tSchema] (SchemaCache.accessibleTables configDbPreparedStatements)
MaybeDbResult plan . Just <$> ((,,)
(HM.filterWithKey (\qi _ -> S.member qi tableAccess) $ SchemaCache.dbTables sCache)
<$> SQL.statement (tSchema, configDbHoistedTxSettings) (SchemaCache.accessibleFuncs configDbPreparedStatements)
<$> SQL.statement ([tSchema], configDbHoistedTxSettings) (SchemaCache.accessibleFuncs configDbPreparedStatements)
<*> SQL.statement tSchema (SchemaCache.schemaDescription configDbPreparedStatements))
OAIgnorePriv ->
MaybeDbResult plan . Just <$> ((,,)
+6 -7
View File
@@ -360,21 +360,19 @@ dataRepresentations = SQL.Statement sql mempty decodeRepresentations
|]
allFunctions :: Bool -> SQL.Statement AppConfig RoutineMap
allFunctions = SQL.Statement sql params decodeFuncs
allFunctions = SQL.Statement funcsSqlQuery params decodeFuncs
where
params =
(toList . configDbSchemas >$< arrayParam HE.text) <>
(configDbHoistedTxSettings >$< arrayParam HE.text)
sql =
funcsSqlQuery <> " AND pn.nspname = ANY($1)"
accessibleFuncs :: Bool -> SQL.Statement (Schema, [Text]) RoutineMap
accessibleFuncs :: Bool -> SQL.Statement ([Schema], [Text]) RoutineMap
accessibleFuncs = SQL.Statement sql params decodeFuncs
where
params =
(fst >$< param HE.text) <>
(fst >$< arrayParam HE.text) <>
(snd >$< arrayParam HE.text)
sql = funcsSqlQuery <> " AND pn.nspname = $1 AND has_function_privilege(p.oid, 'execute')"
sql = funcsSqlQuery <> " AND has_function_privilege(p.oid, 'execute')"
funcsSqlQuery :: SqlQuery
funcsSqlQuery = encodeUtf8 [trimming|
@@ -465,7 +463,8 @@ funcsSqlQuery = encodeUtf8 [trimming|
WHERE setting ~ ANY($$2)
) func_settings ON TRUE
WHERE t.oid <> 'trigger'::regtype AND COALESCE(a.callable, true)
AND prokind = 'f'|]
AND prokind = 'f'
AND pn.nspname = ANY($$1) |]
schemaDescription :: Bool -> SQL.Statement Schema (Maybe Text)
schemaDescription =