Skip to content

couchbase-examples/cxx-quickstart

Repository files navigation

Quickstart in Couchbase with C++

Overview

This repository provides a simple guide to get started with integrating Couchbase with a C++ application. It is designed to give you a starter project in order to give you an idea about how to start working with the Couchbase C++ SDK.

More Info Following topics are 1. How to create, read, update, and delete documents using [Key Value operations](https://docs.couchbase.com/python-sdk/current/howtos/kv-operations.html) (KV operations). KV operations are unique to couchbase and provide super fast (think microseconds) queries.
  1. How to write simple parametrized SQL++ queries using the built-in travel-sample bucket.

  2. How to create and use Search indexes for near real-time search capabilities for a diverse range of data types.

Full documentation for the tutorial can be found on the Couchbase Developer Portal.

Prerequisites

To run this prebuilt project, you will need:

Application Setup

We will walk through the different steps required to get the application running.

Cloning Repo

git clone https://github.com/couchbase-examples/cxx-quickstart.git

Setup Database Configuration

To know more about connecting to your Capella cluster, please follow the instructions.

Specifically, you need to do the following:

  • Create the database credentials to access the travel-sample bucket (Read and Write) used in the application.
  • Allow access to the Cluster from the IP on which the application is running.

All configuration for communication with the database is read from the environment variables. We have provided a convenience feature in this quickstart to setup the required environment variables using a shell script setup_env_vars.sh. Change the values of the following lines:

export DB_CONN_STR=<connection_string>
export DB_USERNAME=<username>
export DB_PASSWORD=<password>
export BUCKET_NAME=<bucket_name>
export SCOPE_NAME=<inventory>
export COL_NAME=<collection_name>

Note: The connection string expects the couchbases:// or couchbase:// part.

Run the command:

source setup_env_vars.sh

This will set the environment variables for that session.

Install Dependencies and Building

This project makes use of CMake and CPM to install dependencies.

mkdir build
cd build
cmake ..
cmake --build .

This will download and install all the dependencies required for the project to built. Along with that it will build the executable required to run the application.

Running The Application

Directly on Machine

At this point, we have installed the dependencies, loaded the travel-sample data and configured the application with the credentials. The application is now ready and you can run it by executing the following command from the build directory:

./cxx_quickstart

Verifying the Application

Once you run the executable, your terminal should fill up with the results of the executed statements written in the main function of the main.cpp and should look something like this: image

Running Tests

For running tests, a self-managed cluster is required with travel-sample bucket loaded or you need to update the connection details in the tests/test.cpp file. To run the tests, use the following command from the build directory:

./tests/u_tests

Data Model

For this quickstart, we use one collection, airline and hotels collection that contains sample airline and sample hotel information. For CRUD operations, we make use of the airline collection, whereas for Search indexes and Query execution we use the hotelcollection. You can find the schema for both these collections in the model folder.

About

Entry level Couchbase demo/tutorial with C++

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published