Couchx.Adapter (Couchx v0.1.2)

Adapter to get basic query functionality into Ecto with CouchDB.

Configuration

It uses the same as Ecto pattern to config the Dbs with this format:

config :my_app, MyRepo,
  username: "username",
  password: "password",
  database: "db_name",
  hostname: "localhost",
  protocol: "http",
  port: 5984

Usage

Couchx supports 1 main repo and many dynamic supervised repos. A dynamic repo will allow you to have multiple db connections in your application. To achieve this, you will need to setup a DynamicSupervisor and a Registry in the application like:

  def start(_type, _args) do
    children = [
      {DynamicSupervisor, strategy: :one_for_one, name: CouchxSupervisor}
      {Registry, keys: :unique, name: CouchxRegistry},
      ...
    ]
    ...
  end

The Restry name is tied up to the code so it must be called CouchxRegistry.

The main Repo is configured as any other Ecto Repo, so you can start it in the application just adding it to the children list.

  def start(_type, _args) do
    children = [
      MyDb.Repo
    ]
    ...
  end

Dynamic Repo queries

The dynamic repos are implemente with a Macro that you can get into your repo as:

  use CouchxDyncamicTepo, otp_app: :my_app, name: :my_repo

This is used to setup a run function, with a callback as argument. To execute actions in a dynamic repo we follow this pattern:

  MyDynamicRepo.run( ->
    MyDynamicRepo.get(MyStruct, doc_id)
  end)

Any Repo call inside the callback function will be run in a dynamically supervised connection.

Link to this section Summary

Functions

Callback implementation for Ecto.Adapter.checked_out?/1.

Callback implementation for Ecto.Adapter.dumpers/2.

Callback implementation for Ecto.Adapter.init/1.

Callback implementation for Ecto.Adapter.loaders/2.

Link to this section Functions

Link to this function

autogenerate(atom)

Callback implementation for Ecto.Adapter.Schema.autogenerate/1.

Link to this function

checked_out?(arg)

Callback implementation for Ecto.Adapter.checked_out?/1.

Link to this function

checkout(adapter, config, result)

Callback implementation for Ecto.Adapter.checkout/3.

Link to this function

create_admin(server, name, password)

Link to this function

create_db(server, name)

Link to this function

delete(meta, meta_schema, params, opts)

Callback implementation for Ecto.Adapter.Schema.delete/4.

Link to this function

delete_admin(server, name)

Link to this function

delete_db(server, name)

Link to this function

dumpers(arg1, type)

Callback implementation for Ecto.Adapter.dumpers/2.

Link to this function

ensure_all_started(repo, type)

Callback implementation for Ecto.Adapter.ensure_all_started/2.

Link to this function

execute(meta, query_meta, query_cache, params, opts)

Callback implementation for Ecto.Adapter.Queryable.execute/5.

Link to this function

execute(atom, meta, design, view, key, query_opts)

Callback implementation for Ecto.Adapter.init/1.

Link to this function

insert(meta, repo, fields, on_conflict, returning, options)

Callback implementation for Ecto.Adapter.Schema.insert/6.

Link to this function

insert_all(a, b, c, d, e, f, g)

Link to this function

insert_all(_, _, _, _, _, _, _, _)

Callback implementation for Ecto.Adapter.Schema.insert_all/8.

Link to this function

loaders(arg1, type)

Callback implementation for Ecto.Adapter.loaders/2.

Link to this function

prepare(atom, query)

Callback implementation for Ecto.Adapter.Queryable.prepare/2.

Link to this function

stream(a, b, c, d, e)

Callback implementation for Ecto.Adapter.Queryable.stream/5.

Link to this function

update(meta, repo, fields, identity, returning, _)

Callback implementation for Ecto.Adapter.Schema.update/6.

Link to this function

update!(meta, repo, fields, identity, returning, a)