Represents a CouchDB server.
Useful for creating/deleting DBs and dealing with system-level functionality such as replication and task monitoring.
None
, auth=None
, full_commit=True
)
Initialize the server object.
None
)
Retrieve the list of database names on this server
None
, value=None
, delete=False
, callback=None
)
Get/set the configuration of the CouchDB server (or a field thereof).
name
name
name
arg, returns the entire config dictionary.name
is specified, returns the value of that sub-pathvalue
is specified, returns Nonedelete
is specified, returns the pre-deletion valueNone
)
Create a new database with the given name.
False
, callback=None
)
Initialize a Database object corrsponding to a particular db name.
name
None
)
Delete the database with the specified name.
None
, **options)
Replicate changes from the source database to the target database.
_replicator
database for subsequent querying. If not provided, the
legacy _replicate
API will be used instead.The _replicator system database
self.db('_replicator')
None
, callback=None
)
Server statistics.
name
is specified, returns the value at that sub-pathname
is invalid)None
)
A list of tasks currently active on the server.
The _users system database.
self.db('_users')
1
, callback=None
)
Retrieve a batch of uuids
None
)
The version string of the CouchDB server.
Represents a single DB on a couch server.
This is the primary class for interacting with documents, views, changes, et al.
None
)
Initialize the database object.
None
, **opts)
Retrieve a list of changes from the database or begin listening to a continuous feed.
myddoc/subset
)ChangesFeed
object will be created and begin
listening to the specified _changes feed. [{seq:0, id:'', changes:[]}, …]
{last_seq:0, results:[{id:'', seq:0, …}, …]}
feed='continuous'
and a valid callback: a ChangesFeed objectNone
)
Clean up old design document indexes.
{ok:True}
None
)
If the server is configured to delay commits, or previous requests
used the special X-Couch-Full-Commit:
false
header to disable
immediate commits, this method can be used to ensure that any
non-committed changes are committed to physical storage.
None
, callback=None
)
Compact the database or a design document's index.
None
)
Copy a given document to create a new document or overwrite an old one.
_id
and _rev
keys
specifying the document to be copied_id
and _rev
keys
specifying the document to be created/overwritten
None
)
Delete the given document from the database.
_id
and _rev
keys identifying the doc to be deleted
None
)
Delete the specified attachment.
_id
and _rev
keysNone
)
Check whether this Database object corresponds to an existing db on the server
False
, callback=None
, **options)
Return the document(s) with the specified ID(s).
None
)
Return an attachment from the specified doc and filename.
_id
keyNone
, callback=None
)
Fetch information about the database or a design document.
None
, **options)
Format a view using a 'list' function.
None
, **options)
Initiate a replication from a source url to this database
_replicator
database for subsequent querying. If not provided, the
legacy _replicate
API will be used instead.None
)
Perform purging (complete removal) of the given documents.
Uses a single HTTP request to purge all given documents. Purged documents do not leave any metadata in the storage and are not replicated.
Think thrice before doing this.
{_id:'', _rev:''}
{purge_seq:0, purged:{id1:[], id2:[], ...}}
None
, **options)
Initiate a replication from this database to a target url
_replicator
database for subsequent querying. If not provided, the
legacy _replicate
API will be used instead.None
, content_type=None
, callback=None
)
Create or replace an attachment.
_id
and _rev
keys{ok:True, id:'', rev:''}
None
, callback=None
, **options)
Create a temporary view using the provided javascript function(s) and perform a mind-bendingly inefficient ad-hoc query.
_sum
, _count
, or _stats
)
None
, **options)
Return all available revisions of the given document.
None
, merge=None
, force=False
, callback=None
, **options)
Create a new document or update an existing document.
merge
function will be called for each local/remote pair. The
merge function should return either a dict-like object to be written to the database
or (in case the write attempt should be abandoned) None.
.resolved
property (useful in an async context where the callback
function doesn't have the original arguments in its scope)None
, callback=None
)
Access the database's _security object
If called without arguments, returns the security object. If called with a dict, sets the security object to that value.
None
, callback=None
, **options)
Call a 'show' function.
None
, body=None
, callback=None
, **options)
Calls a server side update handler.
None
, **options)
Query a view.
All of the query args in the HTTP api can be passed as keyword
args. Key values should be json-serializeable objects (abbreviated
as obj
below) of the form defined in your view function.
start
s and end
s when
toggling this.endkey
in the results. If False, treat endkey
as defining the
first rows to be *excluded* from the results.Iterable representation of a set of results from a view query
limit
is in the options dict)Representation of a single row of results from a view query
The associated document for the row. This is only present when the
view was accessed with include_docs=True
as a query parameter,
otherwise this property will be None
.
Couch's description of an error if one occurred, otherwise None
The ID of the doc that emitted this row if it exists
or None
if it doesn't (e.g., when querying a view
with a reduce function).
The emitted key
The emitted value
A dictionary subclass with couch-friendly additions.
Inherits from odict
to preserve key-ordering when converting to/from
json and from adict
to allow for dot-syntax access to dictionary items.
Contains the server response from an HTTP request.
Status objects are returned as the final argument to callback functions when returning from an asynchronous database request.
None
if the request was successful, or an HTTPError subclassNone
). This is redundant but allows
for the syntax if
status.error
is
NotFound
in callback functions.
Persistent listener to a Database's _changes
endpoint
The result of an attempt to write to the database.
Presents the results of a Database.save
call and provides syntax
for resolution of any conflicted documents
{some_doc:
{doc:{_id:"some_doc",
…},
error:"conflict"},
…}
_id
) of docs that were written
without error. Their _id
and _rev
keys have been updated to
reflect the save.
None
)
Attempt to replace the server's copy of the docs with those in .pending
This is a brute-force method of resolving conflicts. The database is queried for the _revs of all the docs with pending conflicts. The local copies of the docs are then updated with the up-to-date _revs and a bulk-save is attempted.
None
)
Attempt to merge the local and server versions of docs with pending conflicts.
Allows a user-provided function to decide how to resolve each conflict and what (if anything) ought to be written to the server.
None
is returned, the document will be skipped in
the write attempt and remains ‘pending’.
A decorator for simplifying async couchdb access from Tornado.
Methods using this decorator will be able to make asynchronous calls to the database
without needing to provide explicit callbacks (and restoring traditional exception
handling in the process). It decides between applying tornado's @asynchronous
and
@gen.engine
decorators as appropriate for a given method.
Its primary function is to intercept yield statements in your request handler and to evaluate them asynchronously (with an automatic callback that it inserts). When the database request completes, the callback will resume your function at the yield point and pass the received data off with a simple assignment.
Everything that can go wrong…
Couch gives quite a bit of feedback through numeric HTTP error codes. These exceptions give less-unweildy names to some of the more common ones: