# `Sofa.DB`
[🔗](https://github.com/skunkwerks/sofa/blob/0.5.1/lib/sofa/db.ex#L1)

Documentation for `Sofa.DB`, a test-driven idiomatic Apache CouchDB client.

> If the only tool you have is CouchDB, then
> everything looks like `{:ok, :relax}`

## Examples

    iex>  sofa = Sofa.init("http://admin:passwd@localhost:5984/")
          |> Sofa.client()
          |> Sofa.connect!()
        #Sofa<"...">

    iex> Sofa.DB.create(sofa, "testy")
        {:ok,
        #Sofa<
          client: %Req.Request{},
          database: "testy7",
          uri: %URI{},
          ...
        >,
        %Sofa.Response{
          body: %{"ok" => true},
          headers: %{
            cache_control: "must-revalidate",
            content_length: 95,
            content_type: "application/json",
            couch_body_time: 0,
            couch_request_id: "aa6cc50741",
            date: "Sun, 25 Apr 2021 20:04:34 GMT",
            server: "CouchDB/3.1.1 (Erlang OTP/22)"
          },
          method: :put,
          query: [],
          status: 201,
          url: "http://localhost:5984/testy7"
        }}

    iex> Sofa.DB.open!(sofa, "testy")
      #Sofa<
        database: "testy",
        client: %Req.Request{},
      ...>

# `create`

```elixir
@spec create(Sofa.t(), String.t()) :: {:error, any()} | {:ok, Sofa.t(), any()}
```

create DB. Only available to cluster admin users.

# `delete`

```elixir
@spec delete(Sofa.t(), String.t()) :: {:error, any()} | {:ok, Sofa.t(), any()}
```

Delete DB. Only available to cluster admin users.

# `info`

```elixir
@spec info(Sofa.t(), String.t()) :: {:error, any()} | {:ok, Sofa.t(), any()}
```

Get DB info. Only available to database & cluster admin users.

# `open`

```elixir
@spec open(Sofa.t(), String.t()) :: {:error, any()} | {:ok, Sofa.t(), any()}
```

Open DB. Checks if supplied credentials have access to the DB, and returns
updated `%Sofa{}` struct with DB. Ideal for subsequent use to read/write Docs.

# `open!`

```elixir
@spec open!(Sofa.t(), String.t()) :: Sofa.t()
```

Bang! version of open/2. Opens DB and raises on failure. Ideal for piping
directly into reading and writing Docs.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
