Public entry point for a Bier instance.

Bier is a Supervisor that the host application starts to spin up one named instance — its own validated configuration, its own Bandit web server, and its own router built on the fly from database introspection. Multiple instances can coexist in the same node by passing distinct :name values.

Usage

Add a Bier child to your application's supervision tree:

children = [
  {Bier, name: MyApp.Bier, router: [port: 4040, scheme: :http]}
]

Pass admin_server_port: to also expose the /live and /ready health endpoints on a separate listener (it must differ from router[:port]):

children = [
  {Bier,
   name: MyApp.Bier, router: [port: 4040, scheme: :http], admin_server_port: 4041}
]

See start_link/1 for the full list of options.

Per-instance processes are registered through Bier.Registry.

Summary

Functions

Returns a specification to start this module under a supervisor.

Returns the configured JSON encoding library for Bier.

The documentation branch matching postgrest_version/0"v" plus the version's major component, as PostgREST's docsVersion builds it (Version.hs). It selects the externalDocs URL of the OpenAPI document.

The PostgREST release whose wire behavior this build reproduces.

Re-runs the database introspection for the running instance name and atomically swaps its schema cache — the programmatic equivalent of PostgREST's NOTIFY pgrst, 'reload schema' (or SIGUSR1).

Starts a Bier supervision tree linked to the current process.

Bier's own release version, as declared in mix.exs.

Types

name()

@type name() :: term()

Functions

child_spec(init_arg)

@spec child_spec(Keyword.t()) :: Supervisor.child_spec()

Returns a specification to start this module under a supervisor.

See Supervisor.

json_library()

Returns the configured JSON encoding library for Bier.

To customize the JSON library, including the following in your config/config.exs:

config :bier, :json_library, AlternativeJsonLibrary

postgrest_docs_version()

@spec postgrest_docs_version() :: String.t()

The documentation branch matching postgrest_version/0"v" plus the version's major component, as PostgREST's docsVersion builds it (Version.hs). It selects the externalDocs URL of the OpenAPI document.

postgrest_version()

@spec postgrest_version() :: String.t()

The PostgREST release whose wire behavior this build reproduces.

PostgREST renders its own prettyVersion — the first two components of its package version (Version.hs) — into the Server response header (setServerName ("postgrest/" <> prettyVersion), App.hs), the OpenAPI document's info.version, and (through docsVersion) the externalDocs URL. Bier is a reimplementation, not a rebuild of PostgREST, so it answers the first two under its own name (version/0) and keeps this constant for the third — the externalDocs pointer at the dialect's documentation — and for stating the compatibility baseline in prose. Bump it when the conformance suite is re-synced to a new PostgREST pin (see docs/CONFORMANCE_IMPL.md).

reload_schema_cache(name)

@spec reload_schema_cache(name()) :: :ok | {:error, term()}

Re-runs the database introspection for the running instance name and atomically swaps its schema cache — the programmatic equivalent of PostgREST's NOTIFY pgrst, 'reload schema' (or SIGUSR1).

Works whether or not the instance's LISTEN/NOTIFY listener is enabled (db_channel_enabled). Returns {:error, :unknown_instance} when no instance is registered under name; an introspection failure leaves the previous cache serving and is returned as {:error, reason}.

start_link(opts)

@spec start_link(Keyword.t()) :: Supervisor.on_start()

Starts a Bier supervision tree linked to the current process.

Options

  • :name (atom/0) - Used for the supervisor name registration.

  • :router (non-empty keyword/0) - Bandit web endpoint options.

See schema/0 for the full set of validated options (DB connection, db_schemas, etc.), whose defaults are sourced from application env.

version()

@spec version() :: String.t()

Bier's own release version, as declared in mix.exs.

This is what Bier answers with when a client asks which server it is talking to: the Server response header (bier/<version>), the OpenAPI document's info.version, and the Warning header's product token all read it. Falls back to "0.0.0" when the :bier application is not loaded (an escript, or a bare Code.require_file/1).

For which PostgREST dialect a request is speaking, see postgrest_version/0.