PgRest.Registry.Snapshot (PgRest v0.2.0)

Copy Markdown View Source

The immutable schema cache a PgRest.Registry publishes: its resources keyed by {schema, table}, the exposed schemas (the first is the default) and the relationship graph.

graph spans every schema. Embedding follows PostgREST and only reaches tables in the request's schema, so requests resolve embeds through graph/2, the graph restricted to one schema (precomputed per exposed schema).

functions maps {schema, name} to its overloads (PgRest.Function), declared or introspected. introspection is nil without introspect:, otherwise what PgRest.Plug cross-checks on every request: %{mode: :app | :rls, as_role: [String.t()] | nil, authorization: module() | nil, filtered?: boolean()} (filtered? when only: or except: was given).

generation is unique per built snapshot, so a reload is a new generation.

scrub_rpc_details? is whether any resource is scoped or restricts columns (PgRest.Write.scrub_details?/2): a function may touch any table, so its database errors then lose their details.

Summary

Functions

Builds the snapshot of configs (resource configs, already validated) exposing schemas. opts may carry functions: (a list of PgRest.Function, grouped here by schema and name) and introspection:.

The resource registered for schema.table, or PostgREST's 404 PGRST205, with a "Perhaps you meant" hint naming the closest table of that schema.

The overloads of function schema.name (empty when none is registered).

The relationship graph a request against schema embeds through.

Every function registered in schema (the candidates of an RPC name hint).

Types

introspection()

@type introspection() :: %{
  mode: :app | :rls,
  as_role: [String.t()] | nil,
  authorization: module() | nil,
  filtered?: boolean()
}

t()

@type t() :: %PgRest.Registry.Snapshot{
  by_module: %{required(module()) => map()},
  default_schema: String.t(),
  functions: %{required({String.t(), String.t()}) => [PgRest.Function.t()]},
  generation: pos_integer(),
  graph: PgRest.SchemaGraph.t(),
  graphs: %{required(String.t()) => PgRest.SchemaGraph.t()},
  introspection: introspection() | nil,
  name: atom(),
  resources: %{required({String.t(), String.t()}) => map()},
  schemas: [String.t()],
  scrub_rpc_details?: boolean()
}

Functions

build(name, schemas, configs, opts \\ [])

@spec build(atom(), [String.t()], [map()], keyword()) :: t()

Builds the snapshot of configs (resource configs, already validated) exposing schemas. opts may carry functions: (a list of PgRest.Function, grouped here by schema and name) and introspection:.

fetch_resource(snap, schema, table)

@spec fetch_resource(t(), String.t(), String.t()) ::
  {:ok, map()} | {:error, PgRest.Error.t()}

The resource registered for schema.table, or PostgREST's 404 PGRST205, with a "Perhaps you meant" hint naming the closest table of that schema.

functions(snapshot, schema, name)

@spec functions(t(), String.t(), String.t()) :: [PgRest.Function.t()]

The overloads of function schema.name (empty when none is registered).

graph(snapshot, schema)

@spec graph(t(), String.t()) :: PgRest.SchemaGraph.t()

The relationship graph a request against schema embeds through.

schema_functions(snapshot, schema)

@spec schema_functions(t(), String.t()) :: [PgRest.Function.t()]

Every function registered in schema (the candidates of an RPC name hint).