NogDB

Documentation

License

Copyright (c) 2018 NogDB contributors.

NogDB is licensed under the GNU General Public License v3.0. See the included LICENSE file for more details.

NogDB library build and distribution include LMDB, which is licensed under The OpenLDAP Public License.



Full API Documentation



Basic coding with NogDB

  • To use NogDB in our project, we first havae to include NogDB to our code.
#include <nogdb/nogdb.h>
  • And add flag while compile
-lnogdb
  • Before we make any operation with NogDB, we have to create a database context, to open a connection to database file first.
// open a connection to database located at 'mygraph.db'
nogdb::Context ctx{"mygraph.db"};

// with a maximum database number
nogdb::Context ctx{"mygraph.db", static_cast<unsigned int>(128)};

// with a maximum databse size (in Bytes)
nogdb::Context ctx{"mygraph.db", static_cast<unsigned long>(4294967296)};
nogdb::Context ctx{"mygraph.db", 128, 4294967296UL};
  • In graph database, we have Class, equivalent to table in a relational database. It must be created prior to storing any associated information. There are two available types of class in NogDB, vertex and edge.
nogdb::Class::create(txn, "Person", nogdb::ClassType:VERTEX);
nogdb::Class::create(txn, "Relation", nogdb::ClassType:EDGE);
  • Vertex and Edge can have their own defined properties, which will be used to store each element's attributes.
nogdb::Property::add(txn, "Person", "name", nogdb::PropertyType::TEXT);
nogdb::Property::add(txn, "Person", "age", nogdb::PropertyType::UNIGNED_INTEGER);
nogdb::Property::add(txn, "Relation", "relation", nogdb::PropertyType::TEXT);
  • In NogDB we have records, which equivalent to rows in relational database. Record is an element of class, representing vertices or edges in graph. Each can have it own properties.
nogdb::Record r{};
r.set("name", "Harry Potter");
r.set("age", 38);
nogdb::Txn txn(ctx, nogdb::Txn::Mode::READ_WRITE);
nogdb::RecordDescriptor harry = nogdb::Vertex::create(txn, "Person", r);
txn.commit();
  • In graph database. We use edge to represent relation between vertices, like a row in relational database. Which can have it own attributes.
nogdb::Txn txn(ctx, nogdb::Txn::Mode::READ_WRITE);

nogdb::Record r{};
r.set("relation", "friend");
nogdb::RecordDescriptor relation_harry_ron = nogdb::Edge::create(txn, "Relation", harry, ron, r);

txn.commit();