# Couchx

### CouchDB Adapter for Ecto3.

The Adapter supports 1 main Repo, but also dynamic repos where you can querie on multiple Dbs with a dynamic supervisor.

The supported functions in this version are:

Repo.get Struct, doc_id
Repo.all from doc in Struct, where: doc._id in ^doc_ids_list
Repo.insert Struct, doc
Repo.delete Struct, %{_id: doc_id}
Repo.update changeset

It adds a simple way to execute JS view queries with:

  def query(name, design, view_map, key, opts \\ []) do
    {adapter, meta} = Ecto.Repo.Registry.lookup(name)
    adapter.execute(:view, meta, design, view_map, key, opts)

Not ideal, so open to suggestions here.

### Mango support

Currently support for mango is limited to do queries on single property, on previously created indexes.
The selector is a map with the `type` property preset to the model namespace, such as:

  selector: %{
    type: "user",
    email: ""

This will be the query generated by:

import Ecto.Query

Repo.all from u in User, where: == ""

It will also work with:

import Ecto.Query

email = ""
Repo.all from u in User, where: == ^email

## TODO:

* Repo.insert_all
* Repo.delete_all
* Bulk doc updates
* Better error handling
* More Mango Queries
* A better view query pattern
* Auto indexing requested JS queries
* Index management
* Add tests

## Installation

The package can be installed by adding `couchx` to your list of dependencies in `mix.exs`:

def deps do
    {:couchx, "~> 0.1.0"}

Documentation can be generated with [ExDoc](
and published on [HexDocs]( Once published, the docs can
be found at [](