# `DripDrop.Tenants`
[🔗](https://github.com/agoodway/dripdrop/blob/v0.4.1/lib/dripdrop/tenants.ex#L1)

Tenant-wide data operations.

`delete_tenant/1` removes every DripDrop row a tenant owns, for hosts that
delete an account. Every delete is filtered by `tenant_key`, so global rows
(`tenant_key: nil`) and other tenants' rows are never selected.

# `cross_tenant_reference`

```elixir
@type cross_tenant_reference() :: %{
  table: String.t(),
  column: atom(),
  count: pos_integer()
}
```

# `delete_tenant`

```elixir
@spec delete_tenant(String.t()) ::
  {:ok, %{required(atom()) =&gt; non_neg_integer()}}
  | {:error, {:cross_tenant_references, [cross_tenant_reference()]}}
```

Deletes every DripDrop row owned by `tenant_key` in one transaction.

Returns the deleted row count per table. When a row outside the tenant
references one of the tenant's rows, nothing is deleted and the references
are returned, since the delete would otherwise change that row too.

`tenant_key` must be a non-blank string; global rows cannot be deleted
through this function.

---

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