Skip to content

Commit bda992b

Browse files
Merge branch 'develop' of https://github.com/marklogic/node-client-api into develop
2 parents 768bbcf + 2fb9593 commit bda992b

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

lib/query-builder.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2258,11 +2258,16 @@ function bindDefault() {
22582258
* Binds an empty query string to no documents or all documents.
22592259
* @method
22602260
* @memberof queryBuilder#
2261+
* @param {string} apply - a function from the all-results|no-results
2262+
* enumeration to control whether empty criteria matches all or no results
22612263
* @returns {queryBuilder.EmptyBindingParam} the binding for an empty string
22622264
* to pass to the {@link queryBuilder#parseBindings} function
22632265
*/
22642266
function bindEmptyAs() {
2265-
return {'empty':{'apply': 'all-results'}};
2267+
if (arguments.length === 0) {
2268+
throw new Error('no name to bind as a constraint');
2269+
}
2270+
return {'empty':{'apply': arguments[0]}};
22662271
}
22672272
/**
22682273
* The specification for a custom constraint parsing module as returned by

test-basic/documents-query.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,20 @@ describe('document query', function(){
377377
done();
378378
}, done);
379379
});
380+
it('should match an empty query', function(done){
381+
db.query(
382+
q.where(
383+
q.parsedFrom('',
384+
q.parseBindings(
385+
q.bindEmptyAs('no-results')
386+
))
387+
)
388+
).
389+
result(function(response) {
390+
response.length.should.equal(0);
391+
done();
392+
}, done);
393+
});
380394
});
381395
describe('for a QBE where clause', function() {
382396
it('should match a value query', function(done){

test-basic/query-builder.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,10 @@ describe('query-builder', function() {
13841384
q.bindEmptyAs('all-results'),
13851385
{empty:{'apply': 'all-results'}}
13861386
);
1387+
assert.deepEqual(
1388+
q.bindEmptyAs('no-results'),
1389+
{empty:{'apply': 'no-results'}}
1390+
);
13871391
assert.deepEqual(
13881392
q.parseFunction('module1', q.bind('constraint1')),
13891393
{custom:{parse: {

0 commit comments

Comments
 (0)