-
Notifications
You must be signed in to change notification settings - Fork 10
Database
Represents a CouchDB database. Like the Server object, the methods here are largely administrative.
var couchdb = require("couchdb-api");
var db = couchdb().db("mydb");This helper method is for generating a String URL relative to the database. If path is specified,
it will resolve that path relative to the server root. (therefore, beginning a path with / will make
the resolved path relative to the server itself) path can also be an Array:String.
var base = db.url();
// => http://localhost:5984/mydb
var doc = db.url("mydoc");
// => http://localhost:5984/mydb/mydoc
var root = db.url("/");
// => http://localhost:5984/This helper method creates and returns a new Document object based on this Database.
Both parameters are technically optional, see the Document API documentation for more information.
var doc = db.doc("mydoc");This helper method creates and returns a new DesignDocument object based on this Database.
Both parameters are technically optional, see the Document API documentation for more information.
var ddoc = db.ddoc("myddoc");This helper method creates and returns a new LocalDocument object based on this Database.
Both parameters are technically optional, see the Document API documentation for more information.
var ldoc = db.ldoc("myldoc");PUT /{db}
CouchDB Documentation
Creates the database and returns the results.
db.create(function (err, results) {
// ...
});DELETE /{db}
CouchDB Documentation
Deletes the database.
db.destroy(function (err, results) {
// ...
});HEAD /{db}
CouchDB Documentation
Checks for the database's existence.
db.exists(function (err, exists) {
// ...
});GET /{db}
CouchDB Documentation
Retrieves information about this database.
db.info(function (err, info) {
// ...
});-
GET /{db}/all_docsCouchDB Documentation -
POST /{db}/all_docsCouchDB Documentation
Queries a view consisting of all documents in the database. When only a callback is provided: it is a simple GET.
When an Array is provided, it will issue a POST with { keys: [ ... ] }. When an Object is provided, a GET
request will be issued with additional query-string arguments appended.
// simple query
db.allDocs(function (err, results) {
// ...
});
// with query-string params
db.allDocs({ stale: true, skip: 10 }, function (err, results) {
// ...
});
// with an array of document keys
db.allDocs([ "doc-1", "doc-2" ], function (err, results) {
// ...
});