Merge pull request #76 from jbbr/promise-count

Adds promise (sync) variants of getCount
This commit is contained in:
Theodor Diaconu 2016-11-30 13:57:02 +02:00 committed by GitHub
commit 46f9d8b388
3 changed files with 23 additions and 3 deletions

View file

@ -74,6 +74,14 @@ export default class extends Base {
return _.first(this.fetch(...args));
}
/**
* Gets the count of matching elements in sync.
* @returns {any}
*/
async getCountSync() {
return await callWithPromise(this.name + '.count', prepareForProcess(this.body, this.params));
}
/**
* Gets the count of matching elements.
* @param callback

View file

@ -74,6 +74,14 @@ export default class Query extends Base {
return _.first(this.fetch(...args));
}
/**
* Gets the count of matching elements in sync.
* @returns {any}
*/
async getCountSync() {
return await callWithPromise(this.name + '.count', prepareForProcess(this.body, this.params));
}
/**
* Gets the count of matching elements.
* @param callback

View file

@ -210,5 +210,9 @@ describe('Query Client Tests', function () {
assert.isObject(result);
assert.isString(result._id);
assert.isArray(result.posts);
result = await query.getCountSync();
assert.isNumber(result);
})
});