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{},
...>
Summary
Functions
create DB. Only available to cluster admin users.
Delete DB. Only available to cluster admin users.
Get DB info. Only available to database & cluster admin users.
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.
Bang! version of open/2. Opens DB and raises on failure. Ideal for piping directly into reading and writing Docs.
The security object of the opened database, see Sofa.Security.
Replaces the security object of the opened database. Server admin only.
Functions
create DB. Only available to cluster admin users.
Delete DB. Only available to cluster admin users.
Get DB info. Only available to database & cluster admin users.
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.
Bang! version of open/2. Opens DB and raises on failure. Ideal for piping directly into reading and writing Docs.
@spec security(Sofa.t()) :: {:ok, Sofa.Security.t()} | {:error, Sofa.Response.error() | any()}
The security object of the opened database, see Sofa.Security.
@spec set_security(Sofa.t(), Sofa.Security.t()) :: :ok | {:error, Sofa.Response.error() | any()}
Replaces the security object of the opened database. Server admin only.
Sofa.Security.new() |> Sofa.Security.member(role: "users") |> then(&Sofa.DB.set_security(db, &1))