Get Started
Source Code
- Find our repository here
Download NogDB Manually
- Download NogDB source code.
Version | Zip File | Tar File |
---|---|---|
v1.0.0 | coming soon | coming soon |
-
Extract file
-
Windows: Double click the downloaded file to unzip it
-
Linux
-
$ tar -xzvf nogdb.tar.gz nogdb
Download NogDB from Github
$ git clone https://github.com/nogdb/nogdb
Dependency
- GCC (gcc/g++ 5.1.0 or above) or LLVM (clang/clang++ 3.8.0 or above) compiler that supports C++11
Installation
- Build NogDB with Makefile
$ cd nogdb
$ sh install_make.sh
$ make && make test
$ sudo make install
$ make clean
NOTE: In some platforms, for instance, Ubuntu and RHEL/CentOS, you may need to create symbolic links of headers and libs to your
$LD_LIBRARY_PATH
manually
- Build NogDB with CMake
$ cd nogdb
$ cmake .
$ cmake --build . && ctest
$ sudo make install
Hello World step-by-step
- Create cpp source with NogDB including
// Include nogdb to project
#include <nogdb/nogdb.h>
int main (int argc, char* argv[]) {
return 0;
}
- Create database context with maximum db number at 128 and maximum db size at 4GB
#include <nogdb/nogdb.h>
int main (int argc, char* argv[]) {
// Create database context pointing to file 'mygraph.db'
nogdb::Context ctx{"mygraph.db", 128, 4294967296UL};
return 0;
}
- Create classes VERTEX
Words
for words, VERTEXInitialWords
for starting words and EDGEWordLinks
for linking words
#include <nogdb/nogdb.h>
int main (int argc, char* argv[]) {
nogdb::Context ctx{"mygraph.db", 128, 4294967296UL};
try {
// Create READ_WRITE transaction
nogdb::Txn txn(ctx, nogdb::Txn::Mode::READ_WRITE);
// Create vertex 'Words'
nogdb::Class::create(txn "Words", nogdb::ClassType::VERTEX);
// Create vertex 'InitialWords'
nogdb::Class::createExtend(txn, "InitialWords", "Words");
// Create edge 'WordLinks'
nogdb::Class::create(txn, "WordLinks", nogdb::ClassType::EDGE);
} catch ( nogdb::Error& err ) {
std::cerr << err.code() << " " << err.what() << std::endl;
}
return 0;
}
- Create Property
string
within VERTEXWords
#include <nogdb/nogdb.h>
int main (int argc, char* argv[]) {
nogdb::Context ctx{"mygraph.db", 128, 4294967296UL};
try {
nogdb::Txn txn(ctx, nogdb::Txn::Mode::READ_WRITE);
nogdb::Class::create(txn, "Words", nogdb::ClassType::VERTEX);
nogdb::Class::createExtend(txn, "InitialWords", "Words");
nogdb::Class::create(txn, "WordLinks", nogdb::ClassType::EDGE);
// create property 'string' within vertex 'Words' (also applied to 'InitialWords')
nogdb::Property::add(txn, "Words", "string", nogdb::PropertyType::TEXT);
} catch ( NogDB::Error& err ) {
std::cerr << err.code() << " " << err.what() << std::endl;
}
return 0;
}
- Create vertices for
InitialWords
andWords
. And create link between them.
#include <nogdb/nogdb.h>
int main (int argc, char* argv[]) {
nogdb::Context ctx{"mygraph.db", 128, 4294967296UL};
try {
nogdb::Txn txn(ctx, nogdb::Txn::Mode::READ_WRITE);
nogdb::Class::create(txn, "Words", nogdb::ClassType::VERTEX);
nogdb::Class::createExtend(txn, "InitialWords", "Words");
nogdb::Class::create(txn, "WordLinks", nogdb::ClassType::EDGE);
nogdb::Property::add(txn, "Words", "string", nogdb::PropertyType::TEXT);
// Create prototypes of vertices
nogdb::Record hello{}, world{};
hello.set("string", "Hello");
world.set("string", ", World.");
// Create vertices to db with created prototypes
nogdb::RecordDescriptor vHello = nogdb::Vertex::create(txn, "InitialWords", hello);
nogdb::RecordDescriptor vWorld = nogdb::Vertex::create(txn, "Words", world);
// Create link between both vertices
nogdb::Edge::create(txn, "WordLinks", vHello, vWorld);
// Do a transaction commit
txn.commit();
} catch ( nogdb::Error& err ) {
std::cerr << err.code() << " " << err.what() << std::endl;
}
return 0;
}
- Get Initial Word, go to another word through edge, print string for every word passed.
#include <nogdb/nogdb.h>
int main (int argc, char* argv[]) {
nogdb::Context ctx{"mygraph.db", 128, 4294967296UL};qๆ
try {
nogdb::Txn txn(ctx, nogdb::Txn::Mode::READ_WRITE);
nogdb::Class::create(txn, "Words", nogdb::ClassType::VERTEX);
nogdb::Class::createExtend(txn, "InitialWords", "Words");
nogdb::Class::create(txn, "WordLinks", nogdb::ClassType::EDGE);
nogdb::Property::add(txn, "Words", "string", nogdb::PropertyType::TEXT);
nogdb::Record hello{}, world{};
hello.set("string", "Hello");
world.set("string", ", World.");
nogdb::RecordDescriptor vHello = nogdb::Vertex::create(txn, "InitialWords", hello);
nogdb::RecordDescriptor vWorld = nogdb::Vertex::create(txn, "Words", world);
nogdb::Edge::create(txn, "WordLinks", vHello, vWorld);
txn.commit();
} catch ( nogdb::Error& err ) {
std::cerr << err.code() << " " << err.what() << std::endl;
}
try {
// Create READ_ONLY transaction
nogdb::Txn txn(ctx, nogdb::Txn::Mode::READ_ONLY);
// Get initial word from 'InitialWords'
nogdb::ResultSet word1 = nogdb::Vertex::get(txn, "InitialWords");
// Get property 'string' from vertex and print to screen
std::cout << word1[0].record.get("string").toText();
// Get out edge from record
nogdb::ResultSet edge = nogdb::Vertex::getOutEdge(txn, word1[0].descriptor);
// Get destination vertex from edge
nogdb::Result word2 = nogdb::Edge::getDst(txn, edge[0].descriptor);
// Get property 'string' from another vertex and print to screen
std::cout << word2.record.get("string").toText() << std::endl;
} catch ( nogdb::Error& err ) {
std::cerr << err.code() << " " << err.what() << std::endl;
}
return 0;
}
- This is what final 'hello_world.cpp' looks like
#include <nogdb/nogdb.h>
int main (int argc, char* argv[]) {
nogdb::Context ctx{"mygraph.db", 128, 4294967296UL};
try {
nogdb::Txn txn(ctx, nogdb::Txn::Mode::READ_WRITE);
nogdb::Class::create(txn, "Words", nogdb::ClassType::VERTEX);
nogdb::Class::createExtend(txn, "InitialWords", "Words");
nogdb::Class::create(txn, "WordLinks", nogdb::ClassType::EDGE);
nogdb::Property::add(txn, "Words", "string", nogdb::PropertyType::TEXT);
nogdb::Record hello{}, world{};
hello.set("string", "Hello");
world.set("string", ", World.");
nogdb::RecordDescriptor vHello = nogdb::Vertex::create(txn, "InitialWords", hello);
nogdb::RecordDescriptor vWorld = nogdb::Vertex::create(txn, "Words", world);
nogdb::Edge::create(txn, "WordLinks", vHello, vWorld);
txn.commit();
} catch ( nogdb::Error& err ) {
std::cerr << err.code() << " " << err.what() << std::endl;
}
try {
nogdb::Txn txn(ctx, nogdb::Txn::Mode::READ_ONLY);
nogdb::ResultSet word1 = nogdb::Vertex::get(txn, "InitialWords");
std::cout << word1[0].record.get("string").toText();
nogdb::ResultSet edge = nogdb::Vertex::getOutEdge(txn, word1[0].descriptor);
nogdb::Result word2 = nogdb::Edge::getDst(txn, edge[0].descriptor);
std::cout << word2.record.get("string").toText() << std::endl;
} catch ( nogdb::Error& err ) {
std::cerr << err.code() << " " << err.what() << std::endl;
}
return 0;
}
- Build and run
$ g++ -std=c++11 hello_world.cpp -lnogdb -o hello_world
$ ./hello_world
Hello, World.