Mediate.Postgres.Binding (mediate_postgres v0.1.0)

Copy Markdown View Source

The repo, the schemas, and the migrations table that Mediate.Postgres needs beyond the configuration.

  • the mediated repo, whose connection carries the session settings
  • the schemas whose tables the policies protect and read
  • the name of the table that holds the migration numbers

bind/1 validates them and keeps them for the life of the VM, as Mediate.Config.boot!/1 keeps the configuration. override/1 puts a binding in the current process for the rest of its life. resolve/0 reads it from the current process, then from each process in its $callers chain, and the nearest wins. So a test binds its own repo and leaves the boot binding alone.

The schemas serve three lookups:

  • an object type to the table and primary key its answers run against
  • a table back to the schema whose declarations cover it
  • the set of tables whose policies are the adapter's business

Summary

Types

t()

The bound repo, the schemas whose tables its policies protect, and where the version comes from.

Functions

Validate once at boot and keep the binding for resolve/0.

bind/1, but it raises the error.

Validate the options into the struct.

The schema of the binding's options.

Override the binding's fields for the rest of the current process.

Override the binding's fields around a function, then put the previous override back.

The boot binding under the current process's overrides, or an error when neither exists.

The bound schema whose table is table, or nil.

The tables of the bound schemas, sorted.

The schema, table, and single primary key of an object type, or nil when no bound schema has one.

The binding as the keyword list new/1 accepts.

Types

t()

@type t() :: %Mediate.Postgres.Binding{
  migrations_table: String.t(),
  repo: module(),
  schemas: [module()]
}

The bound repo, the schemas whose tables its policies protect, and where the version comes from.

Functions

bind(options)

@spec bind(keyword()) :: {:ok, t()} | {:error, Mediate.Error.t()}

Validate once at boot and keep the binding for resolve/0.

bind!(options)

@spec bind!(keyword()) :: t()

bind/1, but it raises the error.

new(options)

@spec new(keyword()) :: {:ok, t()} | {:error, Mediate.Error.t()}

Validate the options into the struct.

options_schema()

@spec options_schema() :: NimbleOptions.t()

The schema of the binding's options.

override(overrides)

@spec override(keyword()) :: :ok

Override the binding's fields for the rest of the current process.

override(overrides, fun)

@spec override(keyword(), (-> result)) :: result when result: term()

Override the binding's fields around a function, then put the previous override back.

resolve()

@spec resolve() :: {:ok, t()} | {:error, Mediate.Error.t()}

The boot binding under the current process's overrides, or an error when neither exists.

schema_of(binding, table)

@spec schema_of(t(), String.t()) :: module() | nil

The bound schema whose table is table, or nil.

tables(binding)

@spec tables(t()) :: [String.t()]

The tables of the bound schemas, sorted.

target(binding, object_type)

@spec target(t(), atom()) :: {module(), String.t(), atom()} | nil

The schema, table, and single primary key of an object type, or nil when no bound schema has one.

to_keyword(binding)

@spec to_keyword(t()) :: keyword()

The binding as the keyword list new/1 accepts.