PgRest.Function.Introspect (PgRest v0.2.0)

Copy Markdown View Source

Loads PgRest.Functions from pg_proc, in one statement.

Only plain functions (prokind = 'f') of the given schemas are read. Extension-owned functions and functions returning trigger, event_trigger or internal are always skipped. The filter narrows further:

  • only: keeps exactly the listed names, except: drops them (matched as strings)
  • as_role: keeps a function only when at least one listed role may EXECUTE it

Every name and role is a bind parameter, and the statement runs with the statement options of Executor.repo_opts/2 (internal) (log: false, no repo query event), like every other PgRest statement. Types are pg_catalog.format_type(oid, NULL) text under an empty search_path (Catalog.with_empty_search_path/3 (internal), as every catalog load), so every type outside pg_catalog is schema qualified (test.status_enum, public.user_status). Each result column also carries its pg_type.typcategory (PgRest.Function.Return categories).

Differences from PostgREST

Extension-owned functions are never exposed, even when EXECUTE is granted. This keeps extension infrastructure outside the application RPC surface.

Summary

Functions

The functions of schemas that filter keeps. A composite return whose type is the table of one of resource_configs carries that resource. A database or connection failure is {:error, exception}.

Types

filter()

@type filter() :: %{
  optional(:only) => [String.t()] | nil,
  optional(:except) => [String.t()],
  optional(:as_role) => [String.t()] | nil
}

Functions

load(repo, schemas, resource_configs, filter \\ %{})

@spec load(module(), [String.t()], [map()], filter()) ::
  {:ok, [PgRest.Function.t()]} | {:error, Exception.t()}

The functions of schemas that filter keeps. A composite return whose type is the table of one of resource_configs carries that resource. A database or connection failure is {:error, exception}.