Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(generated): update partitioned database examples #1647

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 82 additions & 74 deletions examples/README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/snippets/deleteAttachment/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const service = CloudantV1.newInstance({});

service.deleteAttachment({
db: 'products',
docId: 'small-appliances:100001',
docId: '1000042',
attachmentName: 'product_details.txt',
rev: '4-1a0d1cd6f40472509e9aac646183736a'
}).then(response => {
console.log(response.result);
});
// section: markdown
// This example requires the `product_details.txt` attachment in `small-appliances:100001` document to exist. To create the attachment, see [Create or modify an attachment.](#putattachment)
// This example requires the `product_details.txt` attachment in `1000042` document to exist. To create the attachment, see [Create or modify an attachment.](#putattachment)
6 changes: 3 additions & 3 deletions examples/snippets/deleteDocument/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { CloudantV1 } from '@ibm-cloud/cloudant';
const service = CloudantV1.newInstance({});

service.deleteDocument({
db: 'events',
docId: '0007241142412418284',
rev: '2-9a0d1cd9f40472509e9aac6461837367'
db: 'orders',
docId: 'order00058',
rev: '1-99b02e08da151943c2dcb40090160bb8'
}).then(response => {
console.log(response.result);
});
4 changes: 2 additions & 2 deletions examples/snippets/getAttachment/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const service = CloudantV1.newInstance({});

service.getAttachment({
db: 'products',
docId: 'small-appliances:100001',
docId: '1000042',
attachmentName: 'product_details.txt'
}).then(response => {
let attachment = response.result as Readable;
attachment.pipe(process.stdout);
});
// section: markdown
// This example requires the `product_details.txt` attachment in `small-appliances:100001` document to exist. To create the attachment, see [Create or modify an attachment.](#putattachment)
// This example requires the `product_details.txt` attachment in `1000042` document to exist. To create the attachment, see [Create or modify an attachment.](#putattachment)
2 changes: 1 addition & 1 deletion examples/snippets/getDocument/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const service = CloudantV1.newInstance({});

service.getDocument({
db: 'products',
docId: 'small-appliances:1000042'
docId: '1000042'
}).then(response => {
console.log(response.result);
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const service = CloudantV1.newInstance({});

service.getDocumentShardsInfo({
db: 'products',
docId: 'small-appliances:1000042'
docId: '1000042'
}).then(response => {
console.log(response.result);
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { CloudantV1 } from '@ibm-cloud/cloudant';
const service = CloudantV1.newInstance({});

service.getPartitionInformation({
db: 'products',
partitionKey: 'small-appliances'
db: 'events',
partitionKey: 'ns1HJS13AMkK'
}).then(response => {
console.log(response.result);
});
8 changes: 4 additions & 4 deletions examples/snippets/getSearchInfo/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { CloudantV1 } from '@ibm-cloud/cloudant';
const service = CloudantV1.newInstance({});

service.getSearchInfo({
db: 'products',
ddoc: 'appliances',
index: 'findByPrice'
db: 'events',
ddoc: 'checkout',
index: 'findByDate'
}).then(response => {
console.log(response.result);
});
// section: markdown
// This example requires the `findByPrice` Cloudant Search partitioned index to exist. To create the design document with this index, see [Create or modify a design document.](#putdesigndocument)
// This example requires the `findByDate` Cloudant Search partitioned index to exist. To create the design document with this index, see [Create or modify a design document.](#putdesigndocument)
8 changes: 4 additions & 4 deletions examples/snippets/headAttachment/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const service = CloudantV1.newInstance({});

service.headAttachment({
db: 'products',
docId: 'small-appliances:100001',
docId: '1000042',
attachmentName: 'product_details.txt'
}).then(response => {
console.log(response.status);
console.log(response.headers['content-length']);
console.log(response.headers['content-type']);
console.log(response.headers['Content-Length']);
console.log(response.headers['Content-Type']);
});
// section: markdown
// This example requires the `product_details.txt` attachment in `small-appliances:100001` document to exist. To create the attachment, see [Create or modify an attachment.](#putattachment)
// This example requires the `product_details.txt` attachment in `1000042` document to exist. To create the attachment, see [Create or modify an attachment.](#putattachment)
6 changes: 3 additions & 3 deletions examples/snippets/headDesignDocument/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { CloudantV1 } from '@ibm-cloud/cloudant';
const service = CloudantV1.newInstance({});

service.headDesignDocument({
db: 'products',
ddoc: 'appliances'
db: 'events',
ddoc: 'checkout'
}).then(response => {
console.log(response.status);
console.log(response.headers['etag']);
console.log(response.headers['ETag']);
});
6 changes: 3 additions & 3 deletions examples/snippets/headDocument/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { CloudantV1 } from '@ibm-cloud/cloudant';
const service = CloudantV1.newInstance({});

service.headDocument({
db: 'events',
docId: '0007241142412418284'
db: 'orders',
docId: 'order00058'
}).then(response => {
console.log(response.status);
console.log(response.headers['etag']);
console.log(response.headers['ETag']);
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ service.headReplicationDocument({
docId: 'repldoc-example'
}).then(response => {
console.log(response.status);
console.log(response.headers['etag']);
console.log(response.headers['ETag']);
});
2 changes: 1 addition & 1 deletion examples/snippets/postAllDocsQueries/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CloudantV1 } from '@ibm-cloud/cloudant';
const service = CloudantV1.newInstance({});

const allDocsQueries: CloudantV1.AllDocsQuery[] = [{
keys: ['small-appliances:1000042', 'small-appliances:1000043'],
keys: ['1000042', '1000043'],
},
{
limit: 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ service.postBulkDocs({
{
"docs": [
{
"_id": "0007241142412418284",
"_id": "ns1HJS13AMkK:0007241142412418284",
"type": "event",
"userid": "abc123",
"userId": "abc123",
"eventType": "addedToBasket",
"productId": "1000042",
"date": "2019-01-28T10:44:22.000Z"
},
{
"_id": "0007241142412418285",
"_id": "H8tDIwfadxp9:0007241142412418285",
"type": "event",
"userid": "abc123",
"userId": "abc234",
"eventType": "addedToBasket",
"productId": "1000050",
"date": "2019-01-25T20:00:00.000Z"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { CloudantV1 } from '@ibm-cloud/cloudant';
const service = CloudantV1.newInstance({});

const eventDoc1: CloudantV1.Document = {
_id: '0007241142412418284',
_id: 'ns1HJS13AMkK:0007241142412418284',
type: 'event',
userid: 'abc123',
userId: 'abc123',
eventType:'addedToBasket',
productId: '1000042',
date: '2019-01-28T10:44:22.000Z'
}
const eventDoc2: CloudantV1.Document = {
_id: '0007241142412418285',
_id: 'H8tDIwfadxp9:0007241142412418285',
type: 'event',
userid: 'abc234',
userId: 'abc234',
eventType: 'addedToBasket',
productId: '1000050',
date: '2019-01-25T20:00:00.000Z'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { CloudantV1 } from '@ibm-cloud/cloudant';
const service = CloudantV1.newInstance({});

const eventDoc1: CloudantV1.Document = {
_id: '0007241142412418284',
_id: 'ns1HJS13AMkK:0007241142412418284',
_rev: '1-5005d65514fe9e90f8eccf174af5dd64',
_deleted: true,
}
const eventDoc2: CloudantV1.Document = {
_id: '0007241142412418285',
_id: 'H8tDIwfadxp9:0007241142412418285',
_rev: '1-2d7810b054babeda4812b3924428d6d6',
_deleted: true,
}
Expand Down
4 changes: 2 additions & 2 deletions examples/snippets/postDocument/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { CloudantV1 } from '@ibm-cloud/cloudant';
const service = CloudantV1.newInstance({});

const productsDoc: CloudantV1.Document = {
_id: 'small-appliances:1000042',
_id: '1000042',
type: 'product',
productid: '1000042',
productId: '1000042',
brand: 'Salter',
name: 'Digital Kitchen Scales',
description: 'Slim Colourful Design Electronic Cooking Appliance for Home / Kitchen, Weigh up to 5kg + Aquatronic for Liquids ml + fl. oz. 15Yr Guarantee - Green',
Expand Down
4 changes: 2 additions & 2 deletions examples/snippets/postPartitionAllDocs/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { CloudantV1 } from '@ibm-cloud/cloudant';
const service = CloudantV1.newInstance({});

service.postPartitionAllDocs({
db: 'products',
partitionKey: 'small-appliances',
db: 'events',
partitionKey: 'ns1HJS13AMkK',
includeDocs: true
}).then(response => {
console.log(response.result);
Expand Down
17 changes: 17 additions & 0 deletions examples/snippets/postPartitionExplain/example_request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// section: code
import { CloudantV1 } from '@ibm-cloud/cloudant';

const service = CloudantV1.newInstance({});

const selector: CloudantV1.Selector = {
userId: {'$eq': 'abc123'}
}
service.postPartitionExplain({
db: 'events',
executionStats: true,
limit: 10,
partitionKey: 'ns1HJS13AMkK',
selector: selector
}).then(response => {
console.log(response.result);
});
8 changes: 4 additions & 4 deletions examples/snippets/postPartitionFind/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { CloudantV1 } from '@ibm-cloud/cloudant';
const service = CloudantV1.newInstance({});

const selector: CloudantV1.Selector = {
type: {'$eq': 'product'}
userId: {'$eq': 'abc123'}
}
service.postPartitionFind({
db: 'products',
partitionKey: 'small-appliances',
fields: ['productid', 'name', 'description'],
db: 'events',
partitionKey: 'ns1HJS13AMkK',
fields: ['productId', 'eventType', 'date'],
selector: selector
}).then(response => {
console.log(response.result);
Expand Down
12 changes: 6 additions & 6 deletions examples/snippets/postPartitionSearch/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { CloudantV1 } from '@ibm-cloud/cloudant';
const service = CloudantV1.newInstance({});

service.postPartitionSearch({
db: 'products',
partitionKey: 'small-appliances',
ddoc: 'appliances',
index: 'findByPrice',
query: 'price:[14 TO 20]'
db: 'events',
partitionKey: 'ns1HJS13AMkK',
ddoc: 'checkout',
index: 'findByDate',
query: 'date:[2019-01-01T12:00:00.000Z TO 2019-01-31T12:00:00.000Z]'
}).then(response => {
console.log(response.result);
});
// section: markdown
// This example requires the `findByPrice` Cloudant Search partitioned index to exist. To create the design document with this index, see [Create or modify a design document.](#putdesigndocument)
// This example requires the `findByDate` Cloudant Search partitioned index to exist. To create the design document with this index, see [Create or modify a design document.](#putdesigndocument)
10 changes: 5 additions & 5 deletions examples/snippets/postPartitionView/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { CloudantV1 } from '@ibm-cloud/cloudant';
const service = CloudantV1.newInstance({});

service.postPartitionView({
db: 'products',
ddoc: 'appliances',
db: 'events',
ddoc: 'checkout',
includeDocs: true,
limit: 10,
partitionKey: 'small-appliances',
view: 'byApplianceProdId'
partitionKey: 'ns1HJS13AMkK',
view: 'byProductId'
}).then(response => {
console.log(response.result);
});
// section: markdown
// This example requires the `byApplianceProdId` partitioned view to exist. To create the design document with this view, see [Create or modify a design document.](#putdesigndocument)
// This example requires the `byProductId` partitioned view to exist. To create the design document with this view, see [Create or modify a design document.](#putdesigndocument)
2 changes: 2 additions & 0 deletions examples/snippets/postRevsDiff/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ service.postRevsDiff({
}).then(response => {
console.log(response.result);
});
// section: markdown
// This example requires the example revisions in the POST body to be replaced with valid revisions.
2 changes: 1 addition & 1 deletion examples/snippets/putAttachment/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ stream.push(null);

service.putAttachment({
db: 'products',
docId: 'small-appliances:100001',
docId: '1000042',
attachmentName: 'product_details.txt',
attachment: stream,
contentType: 'text/plain'
Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/putDatabase/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CloudantV1 } from '@ibm-cloud/cloudant';
const service = CloudantV1.newInstance({});

service.putDatabase({
db: 'products',
db: 'events',
partitioned: true
}).then(response => {
console.log(response.result);
Expand Down
20 changes: 10 additions & 10 deletions examples/snippets/putDesignDocument/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { CloudantV1 } from '@ibm-cloud/cloudant';
const service = CloudantV1.newInstance({});

const emailViewMapReduce: CloudantV1.DesignDocumentViewsMapReduce = {
map: 'function(doc) { if(doc.email_verified === true){\n emit(doc.email, [doc.name, doc.email_verified, doc.joined]) }}'
map: 'function(doc) { if(doc.email_verified === true) { emit(doc.email, [doc.name, doc.email_verified, doc.joined]); }}'
}

const userIndex: CloudantV1.SearchIndexDefinition = {
index: 'function (doc) { index("name", doc.name); index("active", doc.active);}'
index: 'function(doc) { index("name", doc.name); index("active", doc.active); }'
}

const designDocument: CloudantV1.DesignDocument = {
Expand All @@ -24,23 +24,23 @@ service.putDesignDocument({
});

const productMap: CloudantV1.DesignDocumentViewsMapReduce = {
map: 'function(doc) { emit(doc.productid, [doc.brand, doc.name, doc.description]) }'
map: 'function(doc) { emit(doc.productId, [doc.date, doc.eventType, doc.userId]); }'
}

const priceIndex: CloudantV1.SearchIndexDefinition = {
index: 'function (doc) { index(\"price\", doc.price);}'
const dateIndex: CloudantV1.SearchIndexDefinition = {
index: 'function(doc) { index("date", doc.date); }'
}

const partitionedDesignDoc: CloudantV1.DesignDocument = {
views: {'byApplianceProdId': productMap},
indexes: {'findByPrice': priceIndex}}
views: {'byProductId': productMap},
indexes: {'findByDate': dateIndex}}

service.putDesignDocument({
db: 'products',
db: 'events',
designDocument: partitionedDesignDoc,
ddoc: 'appliances'
ddoc: 'checkout'
}).then(response => {
console.log(response.result);
});
// section: markdown
// This example creates `allusers` design document in the `users` database and `appliances` design document in the partitioned `products` database.
// This example creates `allusers` design document in the `users` database and `checkout` design document in the partitioned `events` database.
4 changes: 2 additions & 2 deletions examples/snippets/putDocument/example_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ const service = CloudantV1.newInstance({});

const eventDoc: CloudantV1.Document = {
type: 'event',
userid: 'abc123',
userId: 'abc123',
eventType: 'addedToBasket',
productId: '1000042',
date: '2019-01-28T10:44:22.000Z'
};

service.putDocument({
db: 'events',
docId: '0007241142412418284',
docId: 'ns1HJS13AMkK:0007241142412418284',
document: eventDoc
}).then(response => {
console.log(response.result);
Expand Down
Loading