ICouch v0.6.2 ICouch.View View Source

Module to handle views in CouchDB.

View structs should not be created or manipulated directly, please use ICouch.open_view/3 or ICouch.open_view!/3.

The view struct implements the enumerable protocol for easy handling with Elixir's Enum module.

A view can be in a "fetched" state or in an "unfetched" state which can be tested with the fetched?/1 function and changed with the fetch/1, fetch!/1 and unfetch/1 function.

Note that iterating over an unfetched view will create an intermediate fetched version.

Link to this section Summary

Functions

Internal function to build a db endpoint.

Deletes an option in view.

Fetches all rows of view, turning it into a "fetched view".

Same as fetch/1 but returns the fetched view directly on success or raises an error on failure.

Tests whether view is in "fetched" state or not.

Returns the value of an option in view or nil if it was not set.

Adds or updates a single option in view.

Replaces view's options with the given ones.

Resets view back to the "unfetched" state.

Link to this section Types

Link to this type

t()

View Source
t() :: %ICouch.View{
  db: ICouch.DB.t(),
  ddoc: String.t() | nil,
  name: String.t(),
  params: map(),
  rows: [map()] | nil,
  total_rows: integer() | nil,
  update_seq: integer() | String.t() | nil
}
Link to this type

view_option_key()

View Source
view_option_key() ::
  :conflicts
  | :descending
  | :endkey
  | :endkey_docid
  | :group
  | :group_level
  | :include_docs
  | :attachments
  | :att_encoding_info
  | :inclusive_end
  | :key
  | :keys
  | :limit
  | :reduce
  | :skip
  | :stale
  | :startkey
  | :startkey_docid
  | :update_seq
Link to this type

view_option_value()

View Source
view_option_value() ::
  boolean() | String.t() | integer() | [String.t()] | :ok | :update_after

Link to this section Functions

Link to this function

db_endpoint(view)

View Source
db_endpoint(view :: t()) :: {String.t(), map()}

Internal function to build a db endpoint.

Link to this function

delete_option(view, key)

View Source
delete_option(view :: t(), key :: view_option_key()) :: t()

Deletes an option in view.

This will also set the view back to the "unfetched" state.

Returns view unchanged if the option was not set (and it already was "unfetched").

Link to this function

fetch(view)

View Source
fetch(view :: t()) :: {:ok, t()} | {:error, term()}

Fetches all rows of view, turning it into a "fetched view".

Link to this function

fetch!(view)

View Source
fetch!(view :: t()) :: t()

Same as fetch/1 but returns the fetched view directly on success or raises an error on failure.

Link to this function

fetched?(view)

View Source
fetched?(view :: t()) :: boolean()

Tests whether view is in "fetched" state or not.

Link to this function

get_option(view, key)

View Source
get_option(view :: t(), key :: view_option_key()) ::
  view_option_value() | nil

Returns the value of an option in view or nil if it was not set.

Link to this function

put_option(view, key, value)

View Source
put_option(
  view :: t(),
  key :: view_option_key(),
  value :: view_option_value()
) :: t()

Adds or updates a single option in view.

This will also set the view back to the "unfetched" state.

Link to this function

set_options(view, options)

View Source
set_options(view :: t(), options :: [ICouch.open_view_option()]) :: t()

Replaces view's options with the given ones.

This will also set the view back to the "unfetched" state.

Link to this function

unfetch(view)

View Source
unfetch(view :: t()) :: t()

Resets view back to the "unfetched" state.