Added promise (sync) variants of getCount

This commit is contained in:
Janek Thomaschewski 2016-11-30 00:20:01 +01:00
parent 82be9fc76e
commit 98a83939b4
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
@ -117,4 +125,4 @@ export default class extends Base {
createGraph(this.collection, body)
);
}
}
}

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
@ -117,4 +125,4 @@ export default class Query extends Base {
createGraph(this.collection, body)
);
}
}
}

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);
})
});
});