Skip to content

Commit

Permalink
Merge pull request #3 from chintan-mishra/master
Browse files Browse the repository at this point in the history
Update README for Phoenix framework
  • Loading branch information
vaartis committed May 10, 2018
2 parents ecc4aa2 + 52c68ac commit c5f694c
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ Documentation can be found [here](https://hexdocs.pm/couchdb_ex)

## Usage example

### 1. Add the dependency in your application's `mix.exs`
```elixir
defp deps do
[
# ...
{:couchdb_ex, "~> 0.2.1"},
]
end
```

### 2. Use it in your application

#### 2.1. Elixir application
First, add the couchdb worker to your supervisor

```elixir
Expand All @@ -42,7 +55,31 @@ First, add the couchdb worker to your supervisor
Supervisor.start_link(children, opts)
```

Then, you use functions from `CouchDBEx`
#### 2.2. Phoenix framework application
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

```elixir
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
```
### 3. You are all set to make DB operations

Now, you can use functions from `CouchDBEx`

```elixir
:ok = CouchDBEx.db_create("couchdb-ex-test")
Expand Down

0 comments on commit c5f694c

Please sign in to comment.