Couchx.Adapter (Couchx v0.1.0)
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.Schema.autogenerate/1
.
Callback implementation for Ecto.Adapter.checked_out?/1
.
Callback implementation for Ecto.Adapter.checkout/3
.
Callback implementation for Ecto.Adapter.Schema.delete/4
.
Callback implementation for Ecto.Adapter.dumpers/2
.
Callback implementation for Ecto.Adapter.ensure_all_started/2
.
Callback implementation for Ecto.Adapter.Queryable.execute/5
.
Callback implementation for Ecto.Adapter.init/1
.
Callback implementation for Ecto.Adapter.Schema.insert/6
.
Callback implementation for Ecto.Adapter.Schema.insert_all/8
.
Callback implementation for Ecto.Adapter.loaders/2
.
Callback implementation for Ecto.Adapter.Queryable.prepare/2
.
Callback implementation for Ecto.Adapter.Queryable.stream/5
.
Callback implementation for Ecto.Adapter.Schema.update/6
.
Link to this section Functions
autogenerate(atom)
Callback implementation for Ecto.Adapter.Schema.autogenerate/1
.
checked_out?(arg)
Callback implementation for Ecto.Adapter.checked_out?/1
.
checkout(adapter, config, result)
Callback implementation for Ecto.Adapter.checkout/3
.
create_admin(server, name, password)
create_db(server, name)
delete(meta, meta_schema, params, opts)
Callback implementation for Ecto.Adapter.Schema.delete/4
.
delete_admin(server, name)
delete_db(server, name)
dumpers(arg1, type)
Callback implementation for Ecto.Adapter.dumpers/2
.
ensure_all_started(repo, type)
Callback implementation for Ecto.Adapter.ensure_all_started/2
.
execute(meta, query_meta, query_cache, params, opts)
Callback implementation for Ecto.Adapter.Queryable.execute/5
.
execute(atom, meta, design, view, key, query_opts)
init(config)
Callback implementation for Ecto.Adapter.init/1
.
insert(meta, repo, fields, on_conflict, returning, options)
Callback implementation for Ecto.Adapter.Schema.insert/6
.
insert_all(a, b, c, d, e, f, g)
insert_all(_, _, _, _, _, _, _, _)
Callback implementation for Ecto.Adapter.Schema.insert_all/8
.
loaders(arg1, type)
Callback implementation for Ecto.Adapter.loaders/2
.
prepare(atom, query)
Callback implementation for Ecto.Adapter.Queryable.prepare/2
.
stream(a, b, c, d, e)
Callback implementation for Ecto.Adapter.Queryable.stream/5
.
update(meta, repo, fields, identity, returning, _)
Callback implementation for Ecto.Adapter.Schema.update/6
.