Bylaw.Db.Adapter behaviour (bylaw_db v0.1.0-alpha.1)

Copy Markdown View Source

Behaviour implemented by database adapter packages.

Adapters build validation targets, run checks, and execute database-specific introspection queries for checks.

Summary

Types

Adapter-specific query execution option.

Adapter-specific query execution options.

Raw database query result returned by an adapter.

Adapter-specific target construction option.

Adapter-specific target construction options.

Callbacks

Executes database-specific introspection SQL for target.

Builds a single validation target from adapter-specific options.

Runs checks against a non-empty list of targets.

Types

query_opt()

@type query_opt() :: {atom(), term()}

Adapter-specific query execution option.

query_opts()

@type query_opts() :: [query_opt()]

Adapter-specific query execution options.

query_result()

@type query_result() :: term()

Raw database query result returned by an adapter.

target_opt()

@type target_opt() :: {atom(), term()}

Adapter-specific target construction option.

target_opts()

@type target_opts() :: [target_opt()]

Adapter-specific target construction options.

Callbacks

query(target, sql, params, opts)

@callback query(
  target :: Bylaw.Db.Target.t(),
  sql :: String.t(),
  params :: [term()],
  opts :: query_opts()
) :: {:ok, query_result()} | {:error, term()}

Executes database-specific introspection SQL for target.

Checks call this callback through the target's adapter when they need database metadata.

target(opts)

@callback target(opts :: target_opts()) :: Bylaw.Db.Target.t()

Builds a single validation target from adapter-specific options.

validate(targets, checks)

@callback validate(targets :: [Bylaw.Db.Target.t()], checks :: [Bylaw.Db.check_spec()]) ::
  Bylaw.Db.Check.result()

Runs checks against a non-empty list of targets.

Adapter implementations should usually delegate to Bylaw.Db.validate/2.