NebulaGraph CPP¶
NebulaGraph CPP is a C++ client for connecting to and managing the NebulaGraph database.
Prerequisites¶
You have installed C++ and GCC 4.8 or later versions.
Compatibility with NebulaGraph¶
See github.
Install NebulaGraph CPP¶
This document describes how to install NebulaGraph CPP with the source code.
Prerequisites¶
- You have prepared the correct resources.
- You have installed C++ and GCC version is: {10.1.0 | 9.3.0 | 9.2.0 | 9.1.0 | 8.3.0 | 7.5.0 | 7.1.0}. For details, see the gcc_preset_versions parameter.
Steps¶
-
Clone the NebulaGraph CPP source code to the host.
-
(Recommended) To install a specific version of NebulaGraph CPP, use the Git option
--branch
to specify the branch. For example, to install v3.8.0, run the following command:$ git clone --branch release-3.8 https://github.com/vesoft-inc/nebula-cpp.git
-
To install the daily development version, run the following command to download the source code from the
master
branch:$ git clone https://github.com/vesoft-inc/nebula-cpp.git
-
-
Change the working directory to
nebula-cpp
.$ cd nebula-cpp
-
Create a directory named
build
and change the working directory to it.$ mkdir build && cd build
-
Generate the
makefile
file with CMake.Note
The default installation path is
/usr/local/nebula
. To modify it, add the-DCMAKE_INSTALL_PREFIX=<installation_path>
option while running the following command.$ cmake -DCMAKE_BUILD_TYPE=Release ..
Note
If G++ does not support C++ 11, add the option
-DDISABLE_CXX11_ABI=ON
. -
Compile NebulaGraph CPP.
To speed up the compiling, use the
-j
option to set a concurrent numberN
. It should be \(\min(\text{CPU core number},\frac{\text{the memory size(GB)}}{2})\).$ make -j{N}
-
Install NebulaGraph CPP.
$ sudo make install
-
Update the dynamic link library.
$ sudo ldconfig
Use NebulaGraph CPP¶
Compile the CPP file to an executable file, then you can use it. The following steps take using SessionExample.cpp
for example.
-
Use the example code to create the
SessionExample.cpp
file. -
Run the following command to compile the file.
$ LIBRARY_PATH=<library_folder_path>:$LIBRARY_PATH g++ -std=c++11 SessionExample.cpp -I<include_folder_path> -lnebula_graph_client -o session_example
library_folder_path
: The storage path of the NebulaGraph dynamic libraries. The default path is/usr/local/nebula/lib64
.
include_folder_path
: The storage of the NebulaGraph header files. The default path is/usr/local/nebula/include
.
For example:
$ LIBRARY_PATH=/usr/local/nebula/lib64:$LIBRARY_PATH g++ -std=c++11 SessionExample.cpp -I/usr/local/nebula/include -lnebula_graph_client -o session_example
API reference¶
Click here to check the classes and functions provided by the CPP Client.
Core of the example code¶
Nebula CPP clients provide both Session Pool and Connection Pool methods to connect to NebulaGraph. Using the Connection Pool method requires users to manage session instances by themselves.
-
Session Pool
For more details about all the code, see SessionPoolExample.
-
Connection Pool
For more details about all the code, see SessionExample.