-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathnodejs-javascript-eval-params.js
More file actions
69 lines (60 loc) · 2.26 KB
/
Copy pathnodejs-javascript-eval-params.js
File metadata and controls
69 lines (60 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
var should = require('should');
var testconfig = require('../etc/test-config-qa.js');
var marklogic = require('../');
var q = marklogic.queryBuilder;
var db = marklogic.createDatabaseClient(testconfig.restReaderConnection);
var dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnection);
var dbEval = marklogic.createDatabaseClient(testconfig.restEvaluatorConnection);
var dbAdmin = marklogic.createDatabaseClient(testconfig.restAdminConnection);
describe('Javascript eval params test', function () {
it('should do javascript eval with params', function (done) {
dbEval.eval('var num1;' +
'var num2;' +
'num1 + num2;',
{ num1: 2, num2: 3 }
).result(function (values) {
//console.log(values);
values[0].value.should.equal(5);
done();
}, done);
});
it('should do javascript eval with params on stream', function (done) {
dbEval.eval('var num1;' +
'var num2;' +
'num1 + num2;',
{ num1: 2, num2: 3 }
).
stream().
on('data', function (data) {
//console.log(data);
data.value.should.equal(5);
}).
on('end', function () {
done();
}, done);
});
it('should do javascript eval with params and transaction', function (done) {
var tid = 0;
dbEval.transactions.open({ transactionName: 'evalTransaction', timeLimit: 60 })
.result(function (response) {
tid = response.txid;
return dbEval.eval({
source: 'var num1; var num2; num1 + num2;',
variables: { num1: 2, num2: 3 },
txid: tid
}).result();
})
.then(function (response) {
//console.log(response);
response[0].value.should.equal(5);
return dbEval.transactions.commit(tid).result();
})
.then(function (response) {
//console.log(response);
done();
}, done);
});
});