Skip to content

Commit 1896935

Browse files
committed
Merge branch 'develop'
2 parents d6a13f8 + da2aad8 commit 1896935

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+4795
-1775
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ from Node.js applications.
1414

1515
## Status
1616

17-
Release 1.0.0 of the MarkLogic Node.js API
17+
Release 1.0.2 of the MarkLogic Node.js API
1818

1919
## Sample
2020

@@ -56,7 +56,7 @@ Other calls can create additional documents for the same collection.
5656

5757
Here are some resources that walk you through working with MarkLogic using the Node.js API:
5858

59-
* http://developer.marklogic.com/features/node-api
59+
* http://developer.marklogic.com/features/node-client-api
6060
* http://docs.marklogic.com/guide/node-dev/intro#id_68052
6161

6262
The instructions describe:

examples/optimistic-locking.js

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var exutil = require('./example-util.js');
1818
//a real application would require without the 'exutil.' namespace
1919
var marklogic = exutil.require('marklogic');
2020

21-
var p = marklogic.patchBuilder;
21+
var pb = marklogic.patchBuilder;
2222

2323
var dbAdmin = marklogic.createDatabaseClient(exutil.restAdminConnection);
2424

@@ -28,48 +28,48 @@ var timestamp = (new Date()).toISOString();
2828

2929
var uri = '/countries/uv.json';
3030
var operations = [
31-
p.pathLanguage('jsonpath'),
32-
p.replaceInsert('$.timestamp', '$.name', 'after', timestamp)
31+
pb.pathLanguage('jsonpath'),
32+
pb.replaceInsert('$.timestamp', '$.name', 'after', timestamp)
3333
];
3434

3535
console.log('configure the server to enforce optimistic locking');
3636
// a one-time administrative action
3737
dbAdmin.config.serverprops.write({
3838
'update-policy': 'version-required'
39-
}).
40-
result(function(response) {
39+
})
40+
.result(function(response) {
4141
console.log(
4242
'try to update a value in the content to '+
4343
timestamp+'\n without passing the document version id');
4444
db.documents.patch({
4545
uri: uri,
4646
operations: operations
4747
// versionId not specified
48-
}).result(
49-
function(success) {
50-
console.log('should never execute');
51-
},
52-
function(failure) {
53-
console.log('expected failure for the update without the version id');
48+
})
49+
.result(function(success) {
50+
console.log('should never execute');
51+
})
52+
.catch(function(failure) {
53+
console.log('expected failure for the update without the version id');
5454

55-
console.log('get the current version id for the document');
56-
db.documents.probe(uri).result().
57-
then(function(document){
55+
console.log('get the current version id for the document');
56+
db.documents.probe(uri)
57+
.result(function(document){
5858
console.log(
5959
'try to update the document passing the version id '+document.versionId);
6060
return db.documents.patch({
6161
uri: uri,
6262
operations: operations,
6363
versionId: document.versionId
6464
}).result();
65-
}).
66-
then(function(response){
65+
})
66+
.then(function(response){
6767
console.log('update succeeded with the version id');
6868

6969
console.log('get the new version id for the updated document');
7070
return db.documents.read(uri).result();
71-
}).
72-
then(function(documents) {
71+
})
72+
.then(function(documents) {
7373
var document = documents[0];
7474
console.log(
7575
'the document has the new version id '+document.versionId+
@@ -81,19 +81,21 @@ dbAdmin.config.serverprops.write({
8181
return dbAdmin.config.serverprops.write({
8282
'update-policy': 'merge-metadata'
8383
}).result();
84-
}).
85-
then(function(response) {
86-
console.log('done');
84+
})
85+
.then(function(response) {
86+
console.log('done');
8787

88-
exutil.succeeded();
89-
}, function(error) {
90-
console.log(JSON.stringify(error));
88+
exutil.succeeded();
89+
})
90+
.catch(function(error) {
91+
console.log(JSON.stringify(error));
9192

92-
exutil.failed();
93-
});
93+
exutil.failed();
94+
});
9495
});
95-
}, function(error) {
96+
})
97+
.catch(function(error) {
9698
console.log(JSON.stringify(error));
9799

98100
exutil.failed();
99-
});
101+
});

examples/patch-document.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var exutil = require('./example-util.js');
1818
//a real application would require without the 'exutil.' namespace
1919
var marklogic = exutil.require('marklogic');
2020

21-
var p = marklogic.patchBuilder;
21+
var pb = marklogic.patchBuilder;
2222

2323
var db = marklogic.createDatabaseClient(exutil.restWriterConnection);
2424

@@ -27,15 +27,15 @@ var timestamp = (new Date()).toISOString();
2727
console.log('Update a document with a patch');
2828

2929
db.documents.patch('/countries/uv.json',
30-
p.pathLanguage('jsonpath'),
31-
p.replace('$.timestamp', timestamp)
32-
).result().
33-
then(function(response) {
30+
pb.pathLanguage('jsonpath'),
31+
pb.replace('$.timestamp', timestamp)
32+
)
33+
.result(function(response) {
3434
var uri = response.uri;
3535
console.log('updated: '+uri);
3636
return db.documents.read(uri).result();
37-
}).
38-
then(function(documents) {
37+
})
38+
.then(function(documents) {
3939
var documentAfter = documents[0];
4040
console.log('after: '+
4141
documentAfter.content.name+' on '+
@@ -44,8 +44,9 @@ db.documents.patch('/countries/uv.json',
4444
console.log('done');
4545

4646
exutil.succeeded();
47-
}, function(error) {
47+
})
48+
.catch(function(error) {
4849
console.log(JSON.stringify(error));
4950

5051
exutil.failed();
51-
});
52+
});

examples/probe-document.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ var files = ['/countries/uv.json', '/does/not/exist.json'];
2626

2727
var finished = 0;
2828
files.forEach(function(uri){
29-
db.documents.probe(uri).result(function(document) {
29+
db.documents.probe(uri)
30+
.result(function(document) {
3031
console.log('document at '+uri+' exists: '+document.exists);
3132

3233
if ((++finished) === files.length) {
3334
console.log('done');
3435

3536
exutil.succeeded();
3637
}
37-
}, function(error) {
38+
})
39+
.catch(function(error) {
3840
console.log(JSON.stringify(error));
3941

4042
exutil.failed();

examples/query-builder.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ var exutil = require('./example-util.js');
1818
//a real application would require without the 'exutil.' namespace
1919
var marklogic = exutil.require('marklogic');
2020

21-
var q = marklogic.queryBuilder;
21+
var qb = marklogic.queryBuilder;
2222

2323
var db = marklogic.createDatabaseClient(exutil.restReaderConnection);
2424

2525
console.log('Query documents with the Query Builder');
2626

2727
db.documents.query(
28-
q.where(
29-
q.collection('/countries'),
30-
q.value('region', 'Africa'),
31-
q.or(
32-
q.word('background', 'France'),
33-
q.word('Legal system', 'French')
28+
qb.where(
29+
qb.collection('/countries'),
30+
qb.value('region', 'Africa'),
31+
qb.or(
32+
qb.word('background', 'France'),
33+
qb.word('Legal system', 'French')
3434
)
3535
)
3636
).

examples/query-by-example.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ var exutil = require('./example-util.js');
1818
//a real application would require without the 'exutil.' namespace
1919
var marklogic = exutil.require('marklogic');
2020

21-
var q = marklogic.queryBuilder;
21+
var qb = marklogic.queryBuilder;
2222

2323
var db = marklogic.createDatabaseClient(exutil.restReaderConnection);
2424

2525
console.log('Query documents with Query By Example');
2626

2727
db.documents.query(
28-
q.where(
29-
q.byExample({
28+
qb.where(
29+
qb.byExample({
3030
region: 'Africa',
3131
background: {$word: 'France'}
3232
})
33-
)).
33+
))
3434
// or use stream() as in query-builder.js
35-
result(function(documents) {
35+
.result(function(documents) {
3636
documents.forEach(function(document) {
3737
console.log(
3838
document.content.name+' at '+document.uri
@@ -41,7 +41,8 @@ db.documents.query(
4141
console.log('done');
4242

4343
exutil.succeeded();
44-
}, function(error) {
44+
})
45+
.catch(function(error) {
4546
console.log(JSON.stringify(error));
4647

4748
exutil.failed();

examples/query-extract.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,28 @@ var exutil = require('./example-util.js');
1818
//a real application would require without the 'exutil.' namespace
1919
var marklogic = exutil.require('marklogic');
2020

21-
var q = marklogic.queryBuilder;
21+
var qb = marklogic.queryBuilder;
2222

2323
var db = marklogic.createDatabaseClient(exutil.restReaderConnection);
2424

2525
console.log('Extract fragments from queried documents');
2626

2727
db.documents.query(
28-
q.where(
29-
q.collection('/countries'),
30-
q.value('region', 'Africa'),
31-
q.word('exportPartners', 'Niger')
32-
).
33-
slice(1, 10,
34-
q.extract({
28+
qb.where(
29+
qb.collection('/countries'),
30+
qb.value('region', 'Africa'),
31+
qb.word('exportPartners', 'Niger')
32+
)
33+
.slice(1, 10,
34+
qb.extract({
3535
selected:'include-with-ancestors',
3636
paths:[
3737
'/node("name")',
3838
'//node("total")[node("unit") eq "years"]'
3939
]
4040
})
41-
)
42-
).result(function (documents){
41+
))
42+
.result(function (documents){
4343
documents.forEach(function(document) {
4444
console.log(
4545
JSON.stringify(document.content)
@@ -48,7 +48,8 @@ db.documents.query(
4848
console.log('done');
4949

5050
exutil.succeeded();
51-
}, function(error) {
51+
})
52+
.catch(function(error) {
5253
console.log(JSON.stringify(error));
5354

5455
exutil.failed();

examples/query-parser.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ var exutil = require('./example-util.js');
1818
//a real application would require without the 'exutil.' namespace
1919
var marklogic = exutil.require('marklogic');
2020

21-
var q = marklogic.queryBuilder;
21+
var qb = marklogic.queryBuilder;
2222

2323
var db = marklogic.createDatabaseClient(exutil.restReaderConnection);
2424

2525
console.log('Query documents with the Query Parser');
2626

2727
db.documents.query(
28-
q.where(
29-
q.parsedFrom('location:Africa about:France',
30-
q.parseBindings(
31-
q.value('region', q.bind('location')),
32-
q.word('background', q.bind('about'))
28+
qb.where(
29+
qb.parsedFrom('location:Africa about:France',
30+
qb.parseBindings(
31+
qb.value('region', qb.bind('location')),
32+
qb.word('background', qb.bind('about'))
3333
))
34-
)).
34+
))
3535
// or use stream() as in query-builder.js
36-
result(function(documents) {
36+
.result(function(documents) {
3737
documents.forEach(function(document) {
3838
console.log(
3939
document.content.name+' at '+document.uri
@@ -42,7 +42,8 @@ db.documents.query(
4242
console.log('done');
4343

4444
exutil.succeeded();
45-
}, function(error) {
45+
})
46+
.catch(function(error) {
4647
console.log(JSON.stringify(error));
4748

4849
exutil.failed();

examples/read-documents.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ var db = marklogic.createDatabaseClient(exutil.restReaderConnection);
2222

2323
console.log('Read documents');
2424

25-
db.documents.read('/countries/ml.json', '/countries/uv.json').
25+
db.documents.read('/countries/ml.json', '/countries/uv.json')
2626
// or use stream() as in query-builder.js
27-
result(function(documents) {
27+
.result(function(documents) {
2828
console.log('read:\n'+
2929
documents.
3030
map(function(document){
@@ -35,7 +35,8 @@ db.documents.read('/countries/ml.json', '/countries/uv.json').
3535
console.log('done');
3636

3737
exutil.succeeded();
38-
}, function(error) {
38+
})
39+
.catch(function(error) {
3940
console.log(JSON.stringify(error));
4041

4142
exutil.failed();

examples/read-metadata.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ console.log('Read document content and metadata');
2525
db.documents.read({
2626
uris:['/countries/ml.json', '/countries/uv.json'],
2727
categories:['content', 'metadata']
28-
}).
29-
result(function(documents) {
28+
})
29+
.result(function(documents) {
3030
console.log('read:\n'+
3131
documents.
3232
map(function(document){
@@ -43,8 +43,9 @@ db.documents.read({
4343
console.log('done');
4444

4545
exutil.succeeded();
46-
}, function(error) {
46+
})
47+
.catch(function(error) {
4748
console.log(JSON.stringify(error));
4849

4950
exutil.failed();
50-
});
51+
});

0 commit comments

Comments
 (0)