(database {:as config
:keys [url name username password insecure? pool-threads pool-timeout
connection-timeout socket-timeout session-auth-threshold
session-timing-error feed-refresh-interval cache-doc-ttl]
:or {session-auth-threshold 60
feed-refresh-interval 10000
insecure? false
pool-timeout 60
pool-threads 8
socket-timeout 5000
connection-timeout 5000
cache-doc-ttl 15
session-timing-error 30}})
Configuration :url - URL to CouchDB instance :name - Name of the database :username - CouchDB username :password - CouchDB password :insecure? - Connect to CouchDB regardless of an unsafe HTTPS connection default: false :pool-threads - Max number of threads used to connect to CouchDB default: 8 :pool-timeout - Seconds to keep connections open before automatically closing them. default: 60 :connection-timeout - Milliseconds to wait before aborting a new connection attempt, or 0, meaning no timeout default: 5000 :socket-timeout - Milliseconds of data silence to wait before abandoning an established connection, or 0, meaning no timeout default: 5000 :session-auth-threshold - Seconds of session time remaining before reauthenticating default: 60 :session-timing-error - Seconds remaining before considering a session expired. At a minimum, consider setting this value greater than socket-timeout + connection-timeout default: 30 :feed-refresh-interval - Milliseconds to keep a continuous connection open on /db/_changes to watch for updates to documents stored in cache. A lower interval means cache documents are added/removed to the watch more quickly to the watch list, at the expense of reopening connections more frequently. default: 10000 :cache-doc-ttl - Minutes to keep documents stored in memory default: 15
Configuration :url - URL to CouchDB instance :name - Name of the database :username - CouchDB username :password - CouchDB password :insecure? - Connect to CouchDB regardless of an unsafe HTTPS connection default: false :pool-threads - Max number of threads used to connect to CouchDB default: 8 :pool-timeout - Seconds to keep connections open before automatically closing them. default: 60 :connection-timeout - Milliseconds to wait before aborting a new connection attempt, or 0, meaning no timeout default: 5000 :socket-timeout - Milliseconds of data silence to wait before abandoning an established connection, or 0, meaning no timeout default: 5000 :session-auth-threshold - Seconds of session time remaining before reauthenticating default: 60 :session-timing-error - Seconds remaining before considering a session expired. At a minimum, consider setting this value greater than socket-timeout + connection-timeout default: 30 :feed-refresh-interval - Milliseconds to keep a continuous connection open on /db/_changes to watch for updates to documents stored in cache. A lower interval means cache documents are added/removed to the watch more quickly to the watch list, at the expense of reopening connections more frequently. default: 10000 :cache-doc-ttl - Minutes to keep documents stored in memory default: 15
(doc db ddoc-view k)
(doc db ddoc-view k opts)
Like view
, but returns the document of the first row matching key k
, or nil if no matches exist.
Throws if the design document or view does not exist.
Equivalent to:
(-> (view db ddoc-view (merge opts {:key k :limit 1 :include-docs? true})) :rows first :doc)
See view
documentation for info on query options.
Like `view`, but returns the document of the first row matching key `k`, or nil if no matches exist. Throws if the design document or view does not exist. Equivalent to: (-> (view db ddoc-view (merge opts {:key k :limit 1 :include-docs? true})) :rows first :doc) See `view` documentation for info on query options.
(view db ddoc-view)
(view db ddoc-view opts)
Queries a view. Returns a map containing :offset, :rows, and :total-rows. Throws if the design doc or view does not exist.
ddoc-view
specifies the design document and view name. It can take one of two forms:
keyword - :design-doc/view-name - For example, :users/by-id or (keyword "users" "by-id").
vector - ["design-doc" "view-name"] - For example, ["users" "by-id"].
opts
change the query:
:conflicts? - Include conflicts information in response. Ignored if include-docs
isn’t true. Default is false.
:descending? - Return the documents in descending order by key. Default is false.
:end-key - Stop returning records when the specified key is reached.
:end-key-doc-id - Stop returning records when the specified document ID is reached.
Ignored if end-key is not set.
:group? - Group the results using the reduce function to a group or single row.
Implies reduce is true and the maximum group-level. Default is false.
:group-level - Specify the group level to be used. Implies group is true.
:include-docs? - Include the associated document with each row. Default is false.
:inclusive-end? - Specifies whether the specified end key should be included in the result.
Default is true.
:key - Return only documents that match the specified key.
:keys - Return only documents where the key matches one of the keys specified in
the array.
:limit - Limit the number of the returned documents to the specified number.
:reduce? - Use the reduction function. Default is true when a reduce function
is defined.
:skip - Skip this number of records before starting to return the results.
Default is 0.
:sorted? - Sort returned rows. Setting this to false offers a performance boost. The
total-rows and offset fields are not available when this is set to false.
Default is true.
:stable? - Whether or not the view results should be returned from a stable
set of shards. Default is false.
:start-key - Return records starting with the specified key.
:start-key-doc-id - Return records starting with the specified document ID. Ignored if
startkey is not set.
:update - Whether or not the view in question should be updated prior to responding
to the user. Supported values: true, false, :lazy. Default is true.
:update-seq? - Whether to include in the response an update-seq value indicating the
sequence id of the database the view reflects. Default is false.
Queries a view. Returns a map containing :offset, :rows, and :total-rows. Throws if the design doc or view does not exist. `ddoc-view` specifies the design document and view name. It can take one of two forms: keyword - :design-doc/view-name - For example, :users/by-id or (keyword "users" "by-id"). vector - ["design-doc" "view-name"] - For example, ["users" "by-id"]. `opts` change the query: :conflicts? - Include conflicts information in response. Ignored if include-docs isn’t true. Default is false. :descending? - Return the documents in descending order by key. Default is false. :end-key - Stop returning records when the specified key is reached. :end-key-doc-id - Stop returning records when the specified document ID is reached. Ignored if end-key is not set. :group? - Group the results using the reduce function to a group or single row. Implies reduce is true and the maximum group-level. Default is false. :group-level - Specify the group level to be used. Implies group is true. :include-docs? - Include the associated document with each row. Default is false. :inclusive-end? - Specifies whether the specified end key should be included in the result. Default is true. :key - Return only documents that match the specified key. :keys - Return only documents where the key matches one of the keys specified in the array. :limit - Limit the number of the returned documents to the specified number. :reduce? - Use the reduction function. Default is true when a reduce function is defined. :skip - Skip this number of records before starting to return the results. Default is 0. :sorted? - Sort returned rows. Setting this to false offers a performance boost. The total-rows and offset fields are not available when this is set to false. Default is true. :stable? - Whether or not the view results should be returned from a stable set of shards. Default is false. :start-key - Return records starting with the specified key. :start-key-doc-id - Return records starting with the specified document ID. Ignored if startkey is not set. :update - Whether or not the view in question should be updated prior to responding to the user. Supported values: true, false, :lazy. Default is true. :update-seq? - Whether to include in the response an update-seq value indicating the sequence id of the database the view reflects. Default is false.
(row db ddoc-view k)
(row db ddoc-view k opts)
Like view
, but returns the first row matching key k
, or nil if no matches exist.
Throws if the design document or view does not exist.
Equivalent to: (first (:rows (view db ddoc-view opts)))
See view
documentation for info on query options.
Like `view`, but returns the first row matching key `k`, or nil if no matches exist. Throws if the design document or view does not exist. Equivalent to: (first (:rows (view db ddoc-view opts))) See `view` documentation for info on query options.
(remove db id)
(remove db id rev)
Removes a document. Returns true if the document was deleted or no longer exists. Returns false if the provided rev is old.
Removes a document. Returns true if the document was deleted or no longer exists. Returns false if the provided rev is old.
(insert db value)
(insert db id value)
Inserts a document. Returns the inserted document. Throws if the provided id
already exists.
Inserts a document. Returns the inserted document. Throws if the provided `id` already exists.
(get db id)
Gets a document if it exists, else returns nil.
Gets a document if it exists, else returns nil.
(docs db ddoc-view)
(docs db ddoc-view opts)
Like view
, but only returns documents from the maching rows.
Throws if the design document or view does not exist.
Equivalent to: (->> (view db ddoc-view (merge opts {:include-docs? true})) :rows (map :doc))
See view
documentation for info on query options.
Like `view`, but only returns documents from the maching rows. Throws if the design document or view does not exist. Equivalent to: (->> (view db ddoc-view (merge opts {:include-docs? true})) :rows (map :doc)) See `view` documentation for info on query options.
(rows db ddoc-view)
(rows db ddoc-view opts)
Like view
, but only returns rows.
Throws if the design document or view does not exist.
Equivalent to: (:rows (view db ddoc-view opts))
See view
documentation for info on query options.
Like `view`, but only returns rows. Throws if the design document or view does not exist. Equivalent to: (:rows (view db ddoc-view opts)) See `view` documentation for info on query options.
(get-or-insert db id value-fn)
Gets a document if it exists, else computes a value using value-fn and inserts a new one. Returns the existing or inserted document.
Gets a document if it exists, else computes a value using value-fn and inserts a new one. Returns the existing or inserted document.
(document db id)
(exists? doc)
Returns true if the document exists.
Returns true if the document exists.
(id doc)
Returns the document id.
Returns the document id.
(rev doc)
Returns the document revision or nil if the document no longer exists.
Returns the document revision or nil if the document no longer exists.
(value doc)
Similar to (deref doc), but removes CouchDB metadata keys like :_rev and :_id
Similar to (deref doc), but removes CouchDB metadata keys like :_rev and :_id
(with-database binding & body)
Same as (with-open [sym (database config)])
Same as (with-open [sym (database config)])
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close