Added db.isPartitioned(dbName) and extended db.create(dbName, params) to allow creation of partitioned database (#128)

This commit is contained in:
Jeffrey Layanto 2020-07-24 23:30:07 +10:00 committed by GitHub
parent 8fb3c67085
commit 97ec00e958
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 6 deletions

View file

@ -7,17 +7,18 @@ var DB = function (slouch) {
this._slouch = slouch;
};
DB.prototype._create = function (dbName) {
DB.prototype._create = function (dbName, params) {
return this._slouch._req({
uri: this._slouch._url + '/' + encodeURIComponent(dbName),
method: 'PUT'
method: 'PUT',
qs: params
});
};
DB.prototype.create = function (dbName) {
DB.prototype.create = function (dbName, params) {
var self = this;
return self._create(dbName).catch(function (err) {
return self._create(dbName, params).catch(function (err) {
// During heavy traffic, CouchDB does this strange thing where it will return an error even when
// the DB has been created. So, we check to see if the DB exists and then only throw the error
// if the DB does not exist.
@ -29,6 +30,12 @@ DB.prototype.create = function (dbName) {
});
};
DB.prototype.isPartitioned = function (dbName) {
return this.get(dbName).then(function (obj) {
return obj.props && (obj.props.partitioned === true);
});
};
DB.prototype.destroy = function (dbName) {
return this._slouch._req({
uri: this._slouch._url + '/' + encodeURIComponent(dbName),