Bier.Introspection.Relation (bier v0.1.0)

Copy Markdown View Source

A single exposed relation (table or view) with its structure.

Summary

Types

Maps each computed field name to the schema its function lives in.

Data-representation cast functions for a DOMAIN-typed column (PostgREST "Data representations"). Each is a {schema, function} tuple or nil

HTTP methods the OpenAPI document advertises for this relation. nil (the introspection default) means "derive from kind": tables get the full set, views GET only. openapi-mode = follow-privileges overrides it with the methods the request role is actually granted.

t()

Types

column()

@type column() :: %{
  name: String.t(),
  type: String.t(),
  base_type: String.t(),
  pk?: boolean(),
  notnull?: boolean(),
  default: String.t() | nil,
  composite?: boolean(),
  data_rep: data_rep() | nil,
  comment: String.t() | nil,
  enum_labels: [String.t()] | nil,
  max_length: pos_integer() | nil
}

computed_schemas()

@type computed_schemas() :: %{optional(String.t()) => String.t()}

Maps each computed field name to the schema its function lives in.

That schema is not necessarily the relation's own: PostgREST only requires a computed field's function to sit in an exposed schema or on the extra search path, so test.foo(other.bar) is legal. Every call site qualifies the call with this schema rather than schema (see #100).

data_rep()

@type data_rep() :: %{
  read: {String.t(), String.t()} | nil,
  write: {String.t(), String.t()} | nil,
  text: {String.t(), String.t()} | nil
}

Data-representation cast functions for a DOMAIN-typed column (PostgREST "Data representations"). Each is a {schema, function} tuple or nil:

  • readCREATE CAST (<domain> AS json): domain value -> JSON output.
  • writeCREATE CAST (json AS <domain>): JSON body value -> domain.
  • textCREATE CAST (text AS <domain>): query-string filter value -> domain (used to parse col=eq.<raw> predicates).

foreign_key()

@type foreign_key() :: %{
  constraint: String.t(),
  columns: [String.t()],
  ref_schema: String.t(),
  ref_relation: String.t(),
  ref_columns: [String.t()],
  unique?: boolean()
}

methods()

@type methods() :: [:get | :post | :patch | :delete] | nil

HTTP methods the OpenAPI document advertises for this relation. nil (the introspection default) means "derive from kind": tables get the full set, views GET only. openapi-mode = follow-privileges overrides it with the methods the request role is actually granted.

t()

@type t() :: %Bier.Introspection.Relation{
  columns: [column()],
  comment: String.t() | nil,
  computed_column_schemas: computed_schemas(),
  computed_column_types: %{optional(String.t()) => String.t()},
  computed_columns: [String.t()],
  computed_relations: [map()],
  foreign_keys: [foreign_key()],
  kind: :table | :view,
  methods: methods(),
  name: String.t(),
  primary_key: [String.t()],
  schema: String.t()
}