ExCouch v0.1.0-alpha ExCouch View Source

A pure Elixir client for CouchDB.

Implements API calls to CouchDB 2.

Starting the client

The ExCouch module can be supervised. Start it as part of your application. The url parameter is required, and should point to the base URL of your CouchDB instance (e.g. http://localhost:5984). username and password are optional for unauthenticated servers.

Example

defmodule MyApplication do
  use Application
  def start(_type, _args) do
    children = [
      {ExCouch, url: "http://localhost:5984", username: "couch", password: "couch"}
    ]

    opts = [strategy: :one_for_one, name: Enseada.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

After being started, methods can be called to interact with the server.

list = ExCouch.list_databases(limit: 10, skip: 5)

{:ok, "mydb"} = ExCouch.create_database("mydb")

if ExCouch.database_exists?("mydb") do
  {:ok, info} = ExCouch.get_database("mydb")
end

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Create a new database

Checks if a database with the given name already exists

Delete a database

Retrieve information about a database

Callback invoked to start the supervisor and during hot code upgrades.

List all available databases

Link to this section Types

Link to this type

error()

View Source
error() ::
  {:error, atom(), String.t()}
  | {:error, :unexpected, Tesla.Env.t()}
  | {:error, :client, any()}

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

create_database(name)

View Source
create_database(name :: String.t()) :: {:ok, String.t()} | error()

Create a new database

Link to this function

database_exists?(name)

View Source
database_exists?(name :: String.t()) :: boolean() | error()

Checks if a database with the given name already exists

Link to this function

delete_database(name)

View Source
delete_database(name :: String.t()) :: {:ok, String.t()} | error()

Delete a database

Link to this function

get_database(name)

View Source
get_database(name :: String.t()) :: {:ok, Map.t()} | error()

Retrieve information about a database

Callback invoked to start the supervisor and during hot code upgrades.

Developers typically invoke Supervisor.init/2 at the end of their init callback to return the proper supervision flags.

Callback implementation for Supervisor.init/1.

Link to this function

list_databases(opts \\ [])

View Source
list_databases(
  opts :: [
    descending: boolean(),
    start_key: any(),
    end_key: any(),
    limit: pos_integer(),
    skip: pos_integer()
  ]
) :: [String.t()] | error()

List all available databases