ExOperation v0.1.0 ExOperation.DSL View Source

Functions that help defining operations.

Link to this section Summary

Functions

Schedules a callback function to run after successful database transaction commit

A conveniece step for fetching entities from the database. It wraps Ecto.Repo.get/2 under the hood

Adds an arbitrary step to the operation pipeline

Embeds another operation into the current one. Step names must not interfere

Link to this section Types

Link to this section Functions

Link to this function after_commit(operation, callback) View Source
after_commit(
  operation :: ExOperation.Operation.t(),
  callback :: (map() -> any())
) :: ExOperation.Operation.t()

Schedules a callback function to run after successful database transaction commit.

The callback receives the map of results of each step. The return value is ignored.

Link to this function find(operation, name, opts) View Source
find(operation :: ExOperation.Operation.t(), name :: name(), opts :: keyword()) ::
  ExOperation.Operation.t()

A conveniece step for fetching entities from the database. It wraps Ecto.Repo.get/2 under the hood.

Options

:schema – an Ecto.Schema module name to find for. This options is required. :id_path – param name or path list for deeply nested id key. Defaults to [:id]. :preloads – a list of association preloading in the format of Ecto.Repo.preload/3. Doesn’t preload any associations by default. :optional – when enabled doesn’t return error but nil if :id_path is missing in the given params. Defaults to false. :skip_missing – when enabled doesn’t return error but nil if the entity is missing in the database. Defaults to false.

Link to this function step(operation, name, callback) View Source
step(
  operation :: ExOperation.Operation.t(),
  name :: name(),
  callback :: (txn :: txn() -> {:ok | :error, any()})
) :: ExOperation.Operation.t()

Adds an arbitrary step to the operation pipeline.

callback is a function that accepts a map of changes so far where keys are names of preivous steps and values are their return values. It must return either {:ok, result} or {:error, reason} tuple.

Link to this function suboperation(operation, module, params_or_fun) View Source
suboperation(
  operation :: ExOperation.Operation.t(),
  module :: Module.t(),
  params_or_fun :: map() | (txn :: txn() -> map())
) :: ExOperation.Operation.t()

Embeds another operation into the current one. Step names must not interfere.

module is the suboperation module.

params_or_fun can be either a map or a callback function that gets changes so far and returns a map. The map will be passed to the suboperation.

Context is passed without changes.