# `Shardex.Adapter.Ecto`
[🔗](https://github.com/epinault/shardex/blob/v0.1.0/lib/shardex/adapter/ecto.ex#L2)

Adapter for Ecto repos. Requires the optional `:ecto` dependency.

**Dynamic mode** (one repo module, many databases) — pass `:config`:

    shard_1: {Shardex.Adapter.Ecto, repo: MyApp.Repo, config: [database: "s1"]}

Shardex starts `MyApp.Repo` with `name: MyApp.Shards.shard_1.primary` plus
`config` (merged over the repo's app config). `run/2` sets that dynamic repo
with `put_dynamic_repo/1`, calls `fun.(MyApp.Repo)` and restores the
previous dynamic repo. `ref/3` returns the dynamic repo name, so a Plug can
do `MyApp.Repo.put_dynamic_repo(ref)` itself.

**Module mode** (one repo module per shard) — omit `:config`:

    shard_1: {Shardex.Adapter.Ecto, repo: MyApp.RepoShard1}

Options:

  * `:repo` (required) - the `Ecto.Repo` module
  * `:config` - start options for dynamic mode
  * `:start` - set to `false` when the repo is started elsewhere (default `true`)

---

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