Sofa.Doc (sofa v0.1.3)
View SourceDocumentation for Sofa.Doc
, a test-driven idiomatic Apache CouchDB client.
If the only tool you have is CouchDB, then everything looks like
{:ok, :relax}
Examples
iex> Sofa.Doc.new()
Summary
Functions
Coerces a CouchDB "type" field to an existing atom. It is assumed that there will be a related Elixir Module Type of the same name. Elixir prefixes Module names with Elixir. and then elides this in iex, tests, and elsewhere, but here we need to make that explicit.
delete doc
Check if doc exists via HEAD /:db/:doc
and returns either
Check if doc exists via HEAD /:db/:doc
and returns either true or false
Converts CouchDB-native JSON-friendly map to internal %Sofa.Doc{}
format
GET doc and returns standard HTTP status, or the requested doc
Creates a new (empty) document
Optimistically write/update doc assuming rev matches
Converts internal %Sofa.Doc{}
format to CouchDB-native JSON-friendly map
Types
Functions
Coerces a CouchDB "type" field to an existing atom. It is assumed that there will be a related Elixir Module Type of the same name. Elixir prefixes Module names with Elixir. and then elides this in iex, tests, and elsewhere, but here we need to make that explicit.
The "user" type is special-cased as it is already present in CouchDB /_users database.
This function is expected to be paired up with Ecto Schemas to properly manage the appropriate fields in your document body.
delete doc
Check if doc exists via HEAD /:db/:doc
and returns either:
{:error, not_found}
# doc doesn't exist{:ok, %Sofa.Doc{}}
# doc exists and has metadata
Check if doc exists via HEAD /:db/:doc
and returns either true or false
Converts CouchDB-native JSON-friendly map to internal %Sofa.Doc{}
format
Examples
iex> %{ "_id" => "smol", "_rev" => "1-cute", "yes" => true}
|> from_map()
%Sofa.Doc{
attachments: nil,
body: %{"yes" => true},
id: "smol",
rev: "1-cute",
type: nil
}
GET doc and returns standard HTTP status, or the requested doc
- # doc doesn't exist, or similar HTTP status
- %Sofa.Doc{} # doc exists and has metadata
Creates a new (empty) document
Optimistically write/update doc assuming rev matches
Converts internal %Sofa.Doc{}
format to CouchDB-native JSON-friendly map
Examples
iex> %Sofa.Doc{id: "smol", rev: "1-cute", body: %{"yes" => true}}
|> to_map()
%{ "_id" => "smol", "_rev" => "1-cute", "yes" => true}