DDD.Repository behaviour (vicander v0.1.1)

Copy Markdown View Source

Port (interface) for DDD Repositories.

Declares base callbacks and domain-specific queries via find_by. The infrastructure layer provides the concrete Ecto adapter.

Usage

defmodule MyApp.OrderRepository do
  use DDD.Repository

  repo MyApp.Order do
    find_by :customer_id
    find_by :status
    find_by [:customer_id, :status]
  end
end

Generated callbacks:

find_by_id/1
save/1
delete/1
find_by_customer_id/1
find_by_status/1
find_by_customer_id_and_status/2

Summary

Callbacks

delete(aggregate)

@callback delete(aggregate :: struct()) :: :ok | {:error, any()}

find_by_id(id)

@callback find_by_id(id :: any()) :: {:ok, struct()} | {:error, :not_found}

save(aggregate)

@callback save(aggregate :: struct()) :: {:ok, struct()} | {:error, any()}

Functions

find_by(fields)

(macro)

repo(aggregate_module, list)

(macro)