This is supposed to be a good couchdb interface for elixir, documented, tested and other things, that's in progress for now, i know there are erlang and elixir clients already, but they are basically dead and not documented very good if at all, although you might also want to look at icouch
Some features implemented:
- Single and mass document insertion/deletion/update
- Subscribing to changes in the database
- Basic and cookie authentification
- Database configuration retreival and setting
- Document finding
- Attachment uploading/retreival/deletion
- Index creation/deletion/listing
- Replication
Documentation can be found here
defp deps do
[
# ...
{:couchdb_ex, "~> 0.3.0"},
]
end
First, add the couchdb worker to your supervisor
children = [
{CouchDBEx.Worker, [
hostname: "http://localhost",
username: "couchdb",
password: "couchdb",
auth_method: :cookie # or :basic, if you feel like it
]}
]
opts = [strategy: :one_for_one, name: Application.Supervisor]
Supervisor.start_link(children, opts)
Find the application.ex
which is usually present in hello/lib/hello/
where hello
is your project name. Phoenix uses soft-deprecated Supervisor.Spec
thus the minor difference in usage.
Then add the couchdb worker to your application module
def start(_type, _args) do
import Supervisor.Spec
children = [
supervisor(HelloWeb.Endpoint, []),
worker(CouchDBEx.Worker, [[
hostname: "http://localhost",
username: "couchdb",
password: "couchdb",
auth_method: :cookie # or :basic, if you feel like it
]])
]
opts = [strategy: :one_for_one, name: Hello.Supervisor]
Supervisor.start_link(children, opts)
end
Now, you can use functions from CouchDBEx
:ok = CouchDBEx.db_create("couchdb-ex-test")
{:ok, doc} = CouchDBEx.document_insert_one(%{test_value: 1}, "couchdb-ex-test")
This library also includes subscribing to database changes with CouchDBEx.changes_sub
and _unsub
,
see respective functions documentation for more
You need a running CouchDB instance.
$ mix test
If you want to override values, you can set those environment variables.
COUCHDB_HOSTNAME
COUCHDB_PORT
COUCHDB_USERNAME
COUCHDB_PASSWORD
COUCHDB_AUTH_METHOD
example:
$ COUCHDB_USERNAME=admin COUCHDB_PASSWORD=password mix test
Please do open issues and pull requests if you feel like something is wrong, this library probably doesn't have everything you need yet.