Skip to content

Commit 16a71aa

Browse files
committed
fix(queries): options default to object
1 parent 660a528 commit 16a71aa

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

components/queries.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function read (client, query, options = {}) {
1313
const limit = options.limit || 1
1414
const start = options.start || 1 // yes, start it seems to be 1-based
1515

16-
// remmove them from options as they cause NPEs in exist-db XML-RPC
16+
// remmove them from options as they cause NPEs in exist-db XML-RPC
1717
delete options.limit
1818
delete options.start
1919

@@ -27,7 +27,7 @@ function read (client, query, options = {}) {
2727
* @param {Object} options
2828
* @returns {Promise}
2929
*/
30-
function execute (client, queryStringOrBuffer, options) {
30+
function execute (client, queryStringOrBuffer, options = {}) {
3131
return client.promisedMethodCall('executeQuery', [queryStringOrBuffer, options])
3232
}
3333

@@ -51,7 +51,7 @@ function releaseResult (client, handle) {
5151
return client.promisedMethodCall('releaseQueryResult', [handle])
5252
}
5353

54-
function readAll (client, queryStringOrBuffer, options) {
54+
function readAll (client, queryStringOrBuffer, options = {}) {
5555
let resultHandle = -1
5656
let resultPages = -1
5757
let results, error

spec/tests/queries.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,25 @@ test('call queryAll method', function (t) {
7070
})
7171
})
7272

73+
test('call queryAll method without options', function (t) {
74+
const db = connect(envOptions)
75+
const queryString = 'for $i in (1,2) return $i + 10'
76+
const expectedResult = '11,12'
77+
78+
db.queries.readAll(queryString)
79+
.then(function (result) {
80+
const csv = result.pages.map(function (p) { return p.toString() }).join(',')
81+
t.equal(result.pages.length, result.hits, 'all pages retrieved')
82+
t.equal(csv, expectedResult, 'got expected result')
83+
t.deepEqual(result.options, {}, 'options default to empty object')
84+
t.end()
85+
})
86+
.catch(function (e) {
87+
t.fail(e)
88+
t.end()
89+
})
90+
})
91+
7392
test('run query, expect XML', function (t) {
7493
t.skip('not implemented yet')
7594
t.end()

0 commit comments

Comments
 (0)