mirror of
https://github.com/donl/slouch.git
synced 2026-05-25 22:07:24 -06:00
Added db.isPartitioned(dbName) and extended db.create(dbName, params) to allow creation of partitioned database (#128)
This commit is contained in:
parent
8fb3c67085
commit
97ec00e958
3 changed files with 36 additions and 6 deletions
5
API.md
5
API.md
|
|
@ -19,9 +19,10 @@
|
|||
* [changes(dbName, params, filter)](https://github.com/redgeoff/slouch/blob/master/API.md#changesdbname-params-filter)
|
||||
* [changesArray(dbName, params, filter)](https://github.com/redgeoff/slouch/blob/master/API.md#changesarraydbname-params-filter)
|
||||
* copy(fromDBName, toDBName)
|
||||
* create(dbName)
|
||||
* create(dbName, params)
|
||||
* destroy(dbName)
|
||||
* exists(dbName)
|
||||
* isPartitioned(dbName)
|
||||
* replicate(params)
|
||||
* get(dbName)
|
||||
* view(dbName, viewDocId, view, params)
|
||||
|
|
@ -70,8 +71,8 @@
|
|||
* system
|
||||
* get()
|
||||
* isCouchDB1()
|
||||
* supportPartitioned()
|
||||
* reset(exceptDBNames)
|
||||
* supportPartitioned()
|
||||
* updates(params)
|
||||
* updatesNoHistory(params)
|
||||
* updatesViaGlobalChanges(params)
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -99,6 +99,28 @@ describe('db', function () {
|
|||
});
|
||||
});
|
||||
|
||||
it('should create partitioned database if supported', function () {
|
||||
return slouch.system.supportPartitioned().then(function (partitioned) {
|
||||
if (partitioned) {
|
||||
return db.create('p' + utils.createdDB, {
|
||||
partitioned: true
|
||||
}).then(function () {
|
||||
dbsToDestroy.push('p' + utils.createdDB);
|
||||
return db.isPartitioned('p' + utils.createdDB).then(function (partitioned) {
|
||||
partitioned.should.eql(true);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return db.create('p' + utils.createdDB).then(function () {
|
||||
dbsToDestroy.push('p' + utils.createdDB);
|
||||
return db.isPartitioned('p' + utils.createdDB).then(function (partitioned) {
|
||||
partitioned.should.eql(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should iterate through dbs', function () {
|
||||
var dbNames = [];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue