# `Accrue.Repo`
[🔗](https://github.com/szTheory/accrue/blob/accrue-v0.3.0/lib/accrue/repo.ex#L1)

Thin facade over the host-configured `Ecto.Repo`.

Accrue does not ship a Repo of its own (D-10 — the host application
owns the Repo lifecycle). Every Accrue context module that needs to
talk to Postgres routes through this facade, which resolves the real
Repo via `Application.get_env(:accrue, :repo)` at **call time**.

Runtime resolution (not compile-time) is deliberate: tests inject
`Accrue.TestRepo` through `config/test.exs`, and host apps inject
their own Repo through `config :accrue, :repo, MyApp.Repo` without
ever recompiling Accrue.

This module intentionally only re-exports the Repo callbacks Accrue
itself uses. If you need a lower-level Repo operation, call the host
Repo directly.

# `aggregate`

```elixir
@spec aggregate(Ecto.Queryable.t(), atom(), atom() | nil, keyword()) :: term()
```

Delegates to `c:Ecto.Repo.aggregate/4`. Used by concurrency tests and
the billing query layer for count/sum over queryables.

# `all`

```elixir
@spec all(
  Ecto.Queryable.t(),
  keyword()
) :: [any()]
```

Delegates to `c:Ecto.Repo.all/2`. Pass-through.

# `delete`

```elixir
@spec delete(
  Ecto.Schema.t() | Ecto.Changeset.t(),
  keyword()
) :: {:ok, struct()} | {:error, Ecto.Changeset.t()}
```

Delegates to `c:Ecto.Repo.delete/2`. Returns `{:ok, struct}` or
`{:error, changeset}`.

# `get`

```elixir
@spec get(Ecto.Queryable.t(), term(), keyword()) :: struct() | nil
```

Delegates to `c:Ecto.Repo.get/3`. Returns the row or `nil`.

# `get_by`

```elixir
@spec get_by(Ecto.Queryable.t(), keyword() | map(), keyword()) :: struct() | nil
```

Delegates to `c:Ecto.Repo.get_by/3`. Returns the row or `nil`.

# `get_by!`

```elixir
@spec get_by!(Ecto.Queryable.t(), keyword() | map(), keyword()) :: struct()
```

Delegates to `c:Ecto.Repo.get_by!/3`. Raises when the row is missing.

# `insert`

```elixir
@spec insert(
  Ecto.Changeset.t() | struct(),
  keyword()
) :: {:ok, struct()} | {:error, Ecto.Changeset.t()}
```

Delegates to `c:Ecto.Repo.insert/2`. Pass-through.

# `insert!`

```elixir
@spec insert!(
  Ecto.Changeset.t() | struct(),
  keyword()
) :: struct()
```

Delegates to `c:Ecto.Repo.insert!/2`. Raising variant used inside
`transact/2` blocks where the happy path is mandatory and failures
must abort the whole transaction via exception.

# `one`

```elixir
@spec one(
  Ecto.Queryable.t(),
  keyword()
) :: any() | nil
```

Delegates to `c:Ecto.Repo.one/2`. Pass-through.

# `preload`

```elixir
@spec preload(struct() | [struct()], atom() | list(), keyword()) ::
  struct() | [struct()]
```

Delegates to `c:Ecto.Repo.preload/3`. Used by Phase 3 Billing context
to hydrate associations after processor mutations.

# `repo`

```elixir
@spec repo() :: module()
```

Returns the configured host Repo module. Raises `Accrue.ConfigError`
when `:repo` is not configured (prevents runtime `UndefinedFunctionError`
with confusing stacktraces).

# `transact`

```elixir
@spec transact(
  (-&gt; any()) | (module() -&gt; any()),
  keyword()
) :: {:ok, any()} | {:error, any()}
```

Delegates to `c:Ecto.Repo.transact/2`. Accepts either a zero-arity
function (preferred) or a one-arity function that receives the Repo
module.

# `transaction`

```elixir
@spec transaction(
  Ecto.Multi.t() | (-&gt; any()),
  keyword()
) :: {:ok, any()} | {:error, any()} | {:error, Ecto.Multi.name(), any(), map()}
```

Delegates to `c:Ecto.Repo.transaction/2`. Accepts an `Ecto.Multi` or
a function. Used by `Accrue.Billing` for multi-step atomic writes.

# `update`

```elixir
@spec update(
  Ecto.Changeset.t(),
  keyword()
) :: {:ok, struct()} | {:error, Ecto.Changeset.t()}
```

Delegates to `c:Ecto.Repo.update/2` with Postgrex SQLSTATE `45A01`
translation. Attempts to update an `Accrue.Events.Event` will raise
`Accrue.EventLedgerImmutableError` rather than the raw `Postgrex.Error`.

Used only by tests and Plan 06 boot-check paths; normal Accrue code
MUST NOT call `update` on an `Event` — the trigger will reject it.

# `update!`

```elixir
@spec update!(
  Ecto.Changeset.t(),
  keyword()
) :: struct()
```

Delegates to `c:Ecto.Repo.update!/2`. Raising variant. Does NOT apply
the `45A01` SQLSTATE translation — reserved for the non-raising
`update/2` path since only test/boot code updates events directly.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
