API for com.ashafa.clutch
by
Tunde Ashafa
Usage:
(ns your-namespace
(:require com.ashafa.clutch))
Overview
Public Variables and Functions
ad-hoc-view
function
Usage: (ad-hoc-view map-reduce-fns-map)
(ad-hoc-view map-reduce-fns-map query-params-map)
One-off queries (i.e. views you don't want to save in the CouchDB database). Ad-hoc
views should be used during development. Also takes an optional map for querying
options (see: http://bit.ly/gxObh).
all-databases
function
Usage: (all-databases)
(all-databases db-meta)
Returns a list of all databases on the CouchDB server.
bulk-update
function
Usage: (bulk-update documents-vector)
(bulk-update documents-vector update-map)
(bulk-update documents-vector update-map options-map)
Takes a vector of documents (maps) and inserts or updates (if "_id" and "_rev" keys
are supplied in a document) them with in a single request.
changes-error
multimethod
No usage documentation available
If the provided database is being watched for changes (see: 'watch-changes'), returns a map
containing the last exception, the time (java.util.Date) of the exception, and the argument
supplied to the callback, if an exception occured during execution of the callback.
couchdb-info
function
Usage: (couchdb-info)
(couchdb-info db-meta)
Returns informataion about a CouchDB instance.
create-database
multimethod
No usage documentation available
Takes a map (cofiguration of a CouchDB server with a :name key) or string (using the
string and the :name key and merging it into the default Clutch configuration) and
creates a database.
create-document
multimethod
No usage documentation available
Takes a map and creates a document with an auto generated id, returns the id
and revision in a map.
database-info
multimethod
No usage documentation available
Takes a database name and returns the meta information about the database.
delete-attachment
function
Usage: (delete-attachment document file-name)
Deletes an attachemnt from a document.
delete-database
multimethod
No usage documentation available
Takes a database name and deletes the corresponding database.
delete-document
function
Usage: (delete-document document)
Takes a document and deletes it from the database.
function
Usage: (get-all-documents-meta)
(get-all-documents-meta query-params-map)
(get-all-documents-meta query-params-map post-data-map)
Returns the meta (_id and _rev) of all documents in a database. By adding
the key ':include_docs' with a value of true to the optional query params map
you can also get the full documents, not just their meta. Also takes an optional
second map of {:key [keys]} to be POSTed.
(see: http://bit.ly/gxObh).
get-attachment
function
Usage: (get-attachment document-or-id attachment-name)
Returns an InputStream reading the named attachment to the specified/provided document,
or nil if the document or attachment does not exist.
Hint: use the copy or to-byte-array fns in duck-streams to easily redirect the result.
get-database
multimethod
No usage documentation available
Returns a database meta information if it already exists else creates a new database and returns
the meta information for the new database.
get-document
function
Usage: (get-document id)
(get-document id query-params-map)
Takes an id and an optional query parameters map as arguments and returns a
document (as a map) with an id that matches the id argument.
get-view
function
Usage: (get-view design-document view-key)
(get-view design-document view-key query-params-map)
(get-view design-document view-key query-params-map post-data-map)
Get documents associated with a design document. Also takes an optional map
for querying options, and a second map of {:key [keys]} to be POSTed.
(see: http://bit.ly/gxObh).
replicate-database
function
Usage: (replicate-database source-database target-database)
Takes two arguments (a source and target for replication) which could be a
string (name of a database in the default Clutch configuration) or a map that
contains a least the database name (':name' keyword, map is merged with
default Clutch configuration) and reproduces all the active documents in the
source database on the target databse.
save-filter
function
Usage: (save-filter design-document-name view-server-map)
Create a filter for use with CouchDB change notifications API via 'watch-changes'.
save-view
function
Usage: (save-view design-document-name view-key view-server-map)
Create a design document used for database queries.
set-clutch-defaults!
function
Usage: (set-clutch-defaults! configuration-map)
Sets Clutch default CouchDB configuration:
{:host <ip (defaults to "localhost")>
:port <port (defaults to 5984)>
:language <language the CouchDB view server uses (see: README)>
:username <username (if http authentication is enabled)>
:password <password (if http authentication is enabled)>}
stop-changes
multimethod
No usage documentation available
If the provided database changes are being watched (see: 'watch-changes'), stops the execution
of the callback on every change to the watched database.
update-attachment
function
Usage: (update-attachment document attachment & [file-key mime-type])
Takes a document, file (either a string path to the file, a java.io.File object, or an InputStream)
and optionally, a new file name in lieu of the file name of the file argument and a mime type,
then inserts (or updates if the file name of the attachment already exists in the document)
the file as an attachment to the document.
update-document
multimethod
No usage documentation available
Takes document and a map and merges it with the original. When a function
and a vector of keys are supplied as the second and third argument, the
value of the keys supplied are upadated with the result of the function of
their values (see: #'clojure.core/update-in).
watch-changes
multimethod
No usage documentation available
Provided a database (database meta <map>, url <string>, or database name <string>) and a callback, watches
for changes to the database and executes the given callback (takes one argument) on every change
to a document in the given database, using the meta of the changed document as the only
argument of the callback.
with-clj-view-server
macro
Usage: (with-clj-view-server view-server-map)
Takes a map and serializes the values of each key as a string for use by the Clojure view server.
with-db
macro
Usage: (with-db database & body)
Takes a string (database name) or map (database meta) with a body of forms. It
then binds the database information to the Clutch configuration and then executes
the body.
com.ashafa.clutch.http-client
*response-code*
var
When bound to an atom, will be reset! to the HTTP response code of the last couchdb request.
couchdb-request
function
Usage: (couchdb-request config method & [command data data-type])
Prepare request for CouchDB server by forming the required url, setting headers, and
if required, the post/put body and its mime type.
com.ashafa.clutch.utils
function
Usage: (url->db-meta url)
Given a url, returns a map with slots aligned with *defaults*.
Supports usage of URLs with with-db, etc.