/devguide-examples

Examples for topics in the developer guide

Primary LanguageJavaApache License 2.0Apache-2.0

Developer Guide Examples

These examples are intended to be linked to from within the developer guide. They are currently cross-referenced by language.

Each example should be fully self-contained and executable. For languages which have a significant setup, the example may be split into multiple files, but should still be executable. Error handling is optional but should be be at least hinted at.

Basic Connection

This example should show how to connect to a remote Couchbase cluster and bucket

C | Python | Java| .NET | Go | node.js | PHP

SSL Connection

This example shows how to connect using the server's SSL certificate which has already been downloaded locally to the SDK host. The C-based examples will refer to this path when connecting, while the other SDKs will refer to a specific store and possibly have the example divided into installing and using the certificate.

C | Python | Java | .NET | Go | node.js | PHP (currently crashes!)

Updating/Storing

This example should show how to store an item into a cluster

C | Python | Java | .NET | Go | node.js | PHP

Retrieving

This example should show how to get items out of the cluster

C | Python | Java | .NET | Go | node.js | PHP

Bulk Storing

This example should show how to store items into a cluster using the Bulk API

C | Python | Java | .NET | Go | node.js (N/A) | PHP

Bulk Retrieving

This example should show how to get items out of the cluster using the Bulk API

C | Python | Java | .NET | Go | node.js (N/A) | PHP

Counter

This example should show how to initialize and update a counter

C | Python | Java | .NET | Go | node.js | PHP

Expiry

This example should show how to initialize a document with an Expiry or "ttl" - time to live

C | Python | Java | .NET | Go | node.js | PHP

Query with criteria

This example should show how to perform a simple query against the travel-sample bucket. The query is something like:

query = N1QLQuery('SELECT airportname, city, country FROM `travel-sample` '
                  'WHERE type="airport" AND city="Reno"')

C | Python | Java | .NET | Go | node.js | PHP

Query with placeholders

This example should demonstrate how to use placeholders, and also the advantages they afford, perhaps by abstracting a given query away as a function, and passing a function parameter down as a query parameter.

This example should also demonstrate in a commented section of code how to optimize this query.

C | Python | Java | .NET | Go | node.js | PHP

Query - Ensuring all documents are the latest (scan consistency)

This example should show how the scan_consistency parameter may be enabled for a specific query.

C | Python | Java | .NET | Go | node.js | PHP

Query - Better reuse of queries with adhoc(false) and Prepared Statements

This example should demonstrate best practice when a statement is to be reused heavily. Setting the adhoc N1QL query tuning to false will use Prepared Statements in the background, which is useful in such a case. Note how this works with placeholders (but of course simple statements work too).

C | Python | Java | .NET | Go | node.js

Query - UPDATE and DELETE

Show how these statements can be used to modify existing documents using secondary document attributes. Also show how a single document can be modified via the USE KEYS clause.

C | Python | .NET | Go | node.js

CAS Handling - Using CAS for concurrent mutations

This example will demonstrate concurrent mutations with and without using the CAS value. Without using the CAS value, some modifications may end up getting lost, whereas using the CAS within a proper retry mechanism will ensure that all mutations remain in tact

C | Python | Java | .NET | Go | node.js | PHP

Durability

Shows storing an item with durability requirements, attempting to persist/replicate to the maximum number of nodes available.

Some SDKs provide APIs to determine how many nodes are in the cluster, while some SDKs allow dynamically persisting to the total number of nodes available, while others only allow fixed numbers. More details may be found in the examples.

C | Python | Java | .NET | Go | node.js | PHP