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.-
How to write simple parametrized SQL++ queries using the built-in travel-sample bucket.
-
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.
To run this prebuilt project, you will need:
-
Couchbase Capella cluster or a self managed Couchbase cluster with travel-sample bucket loaded.
-
CMake 3.9 or higher installed
-
Loading Travel Sample Bucket If travel-sample is not loaded in your cluster, you can load it by following the instructions:
We will walk through the different steps required to get the application running.
git clone https://github.com/couchbase-examples/cxx-quickstart.git
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://
orcouchbase://
part.
Run the command:
source setup_env_vars.sh
This will set the environment variables for that session.
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.
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
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:
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
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 hotel
collection.
You can find the schema for both these collections in the model folder.