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 #720

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
166 changes: 96 additions & 70 deletions examples/README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/snippets/deleteAttachment/example_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

response = service.delete_attachment(
db='products',
doc_id='small-appliances:100001',
doc_id='1000042',
attachment_name='product_details.txt',
rev='4-1a0d1cd6f40472509e9aac646183736a'
).get_result()

print(response)
# 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.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
service = CloudantV1.new_instance()

response = service.delete_document(
db='events',
doc_id='0007241142412418284',
rev='2-9a0d1cd9f40472509e9aac6461837367'
db='orders',
doc_id='order00058',
rev='1-99b02e08da151943c2dcb40090160bb8'
).get_result()

print(response)
4 changes: 2 additions & 2 deletions examples/snippets/getAttachment/example_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

response_attachment = service.get_attachment(
db='products',
doc_id='small-appliances:100001',
doc_id='1000042',
attachment_name='product_details.txt'
).get_result().content

print(response_attachment)
# 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.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

response = service.get_document(
db='products',
doc_id='small-appliances:1000042'
doc_id='1000042'
).get_result()

print(response)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

response = service.get_document_shards_info(
db='products',
doc_id='small-appliances:1000042'
doc_id='1000042'
).get_result()

print(response)
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
service = CloudantV1.new_instance()

response = service.get_partition_information(
db='products',
partition_key='small-appliances'
db='events',
partition_key='ns1HJS13AMkK'
).get_result()

print(response)
8 changes: 4 additions & 4 deletions examples/snippets/getSearchInfo/example_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
service = CloudantV1.new_instance()

response = service.get_search_info(
db='products',
ddoc='appliances',
index='findByPrice'
db='events',
ddoc='checkout',
index='findByDate'
).get_result()

print(response)
# 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)
4 changes: 2 additions & 2 deletions examples/snippets/headAttachment/example_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

response = service.head_attachment(
db='products',
doc_id='small-appliances:100001',
doc_id='1000042',
attachment_name='product_details.txt'
)
print(response.get_status_code())
print(response.get_headers()['Content-Length'])
print(response.get_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)
4 changes: 2 additions & 2 deletions examples/snippets/headDesignDocument/example_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
service = CloudantV1.new_instance()

response = service.head_design_document(
db='products',
ddoc='appliances'
db='events',
ddoc='checkout'
)
print(response.get_status_code())
print(response.get_headers()['ETag'])
4 changes: 2 additions & 2 deletions examples/snippets/headDocument/example_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
service = CloudantV1.new_instance()

response = service.head_document(
db='events',
doc_id='0007241142412418284'
db='orders',
doc_id='order00058'
)
print(response.get_status_code())
print(response.get_headers()['ETag'])
2 changes: 1 addition & 1 deletion examples/snippets/postAllDocsQueries/example_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
service = CloudantV1.new_instance()

all_docs_query1 = AllDocsQuery(
keys=['small-appliances:1000042', 'small-appliances:1000043']
keys=['1000042', '1000043']
)

all_docs_query2 = AllDocsQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
{
"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 @@
service = CloudantV1.new_instance()

event_doc_1 = Document(
_id="0007241142412418284",
_id="ns1HJS13AMkK:0007241142412418284",
type="event",
userid="abc123",
userId="abc123",
eventType="addedToBasket",
productId="1000042",
date="2019-01-28T10:44:22.000Z"
)
event_doc_2 = 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 @@
service = CloudantV1.new_instance()

event_doc_1 = Document(
_id="0007241142412418284",
_id="ns1HJS13AMkK:0007241142412418284",
_rev="1-5005d65514fe9e90f8eccf174af5dd64",
_deleted=True,
)
event_doc_2 = Document(
_id="0007241142412418285",
_id="H8tDIwfadxp9:0007241142412418285",
_rev="1-2d7810b054babeda4812b3924428d6d6",
_deleted=True,
)
Expand Down
4 changes: 2 additions & 2 deletions examples/snippets/postDocument/example_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
service = CloudantV1.new_instance()

products_doc = 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
).get_result()
print(response)
# section: markdown
# This example requires the `getUserByAddress` Cloudant Query "json" index to exist. To create the index, see [Create a new index on a database.](#postindex)
# This example requires the `getUserByEmail` Cloudant Query "json" index to exist. To create the index, see [Create a new index on a database.](#postindex)
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
).get_result()
print(response)
# section: markdown
# This example requires the `getUserByVerifiedEmail` Cloudant Query "text" index to exist. To create the index, see [Create a new index on a database.](#postindex)
# This example requires the `getUserByAddress` Cloudant Query "text" index to exist. To create the index, see [Create a new index on a database.](#postindex)
4 changes: 2 additions & 2 deletions examples/snippets/postPartitionAllDocs/example_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
service = CloudantV1.new_instance()

response = service.post_partition_all_docs(
db='products',
partition_key='small-appliances',
db='events',
partition_key='ns1HJS13AMkK',
include_docs=True
).get_result()

Expand Down
14 changes: 14 additions & 0 deletions examples/snippets/postPartitionExplain/example_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# section: code
from ibmcloudant.cloudant_v1 import CloudantV1

service = CloudantV1.new_instance()

response = service.post_partition_explain(
db='events',
execution_stats=True,
limit=10,
partition_key='ns1HJS13AMkK',
selector={'userId': {'$eq': 'abc123'}}
).get_result()

print(response)
8 changes: 4 additions & 4 deletions examples/snippets/postPartitionFind/example_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
service = CloudantV1.new_instance()

response = service.post_partition_find(
db='products',
partition_key='small-appliances',
fields=['productid', 'name', 'description'],
selector={'type': {'$eq': 'product'}}
db='events',
partition_key='ns1HJS13AMkK',
fields=['productId', 'eventType', 'date'],
selector={'userId': {'$eq': 'abc123'}}
).get_result()

print(response)
12 changes: 6 additions & 6 deletions examples/snippets/postPartitionSearch/example_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
service = CloudantV1.new_instance()

response = service.post_partition_search(
db='products',
partition_key='small-appliances',
ddoc='appliances',
index='findByPrice',
query='price:[14 TO 20]'
db='events',
partition_key='ns1HJS13AMkK',
ddoc='checkout',
index='findByDate',
query='date:[2019-01-01T12:00:00.000Z TO 2019-01-31T12:00:00.000Z]'
).get_result()

print(response)
# 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)
11 changes: 6 additions & 5 deletions examples/snippets/postPartitionView/example_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
service = CloudantV1.new_instance()

response = service.post_partition_view(
db='products',
ddoc='appliances',
db='events',
ddoc='checkout',
include_docs=True,
limit=10,
partition_key='small-appliances',
view='byApplianceProdId'
partition_key='ns1HJS13AMkK',
view='byProductId'
).get_result()

print(response)
# 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.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
).get_result()

print(response)
// 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.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
detailed_description = "This appliance includes..."
response = service.put_attachment(
db='products',
doc_id='small-appliances:100001',
doc_id='1000042',
attachment_name='product_details.txt',
attachment=detailed_description,
content_type='text/plain'
Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/putDatabase/example_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

service = CloudantV1.new_instance()

response = service.put_database(db='products', partitioned=True).get_result()
response = service.put_database(db='events', partitioned=True).get_result()

print(response)
20 changes: 10 additions & 10 deletions examples/snippets/putDesignDocument/example_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
service = CloudantV1.new_instance()

email_view_map_reduce = 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]); }}'
)

user_index = SearchIndexDefinition(
index='function (doc) { index("name", doc.name); index("active", doc.active); }',
index='function(doc) { index("name", doc.name); index("active", doc.active); }',
analyzer=AnalyzerConfiguration(name="standard", fields={"email": Analyzer(name="email")}))

design_document = DesignDocument(
Expand All @@ -27,11 +27,11 @@
# Partitioned DesignDocument Example

product_map = 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]); }'
)

price_index = SearchIndexDefinition(
index='function (doc) { index("price", doc.price);}',
date_index = SearchIndexDefinition(
index='function(doc) { index("date", doc.date); }',
analyzer=AnalyzerConfiguration(name="classic", fields={"description": Analyzer(name="english")})
)

Expand All @@ -40,17 +40,17 @@
)

partitioned_design_doc = DesignDocument(
views={'byApplianceProdId': product_map},
indexes={'findByPrice': price_index},
views={'byProductId': product_map},
indexes={'findByDate': date_index},
options=design_document_options
)

response = service.put_design_document(
db='products',
db='events',
design_document=partitioned_design_doc,
ddoc='appliances'
ddoc='checkout'
).get_result()

print(response)
# 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.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

event_doc = Document(
type='event',
userid='abc123',
userId='abc123',
eventType='addedToBasket',
productId='1000042',
date='2019-01-28T10:44:22.000Z'
)
response = service.put_document(
db='events',
doc_id='0007241142412418284',
doc_id='ns1HJS13AMkK:0007241142412418284',
document=event_doc
).get_result()

Expand Down
Loading