ejpp
Embedded JSON Database engine for C++11/14
|
View on GitHub
ejpp is a C++ wrapper for EJDB.
EJDB is a C library, so why a C++ wrapper?
While the C library is indeed usable from C++, its usage is far from idiomatic. ejpp provides a safe and modern C++ interface, taking advantage of many C++ language and library features such as exceptions, RAII, reference counted memory management, containers, and more.
ejpp has three main classes, ejdb::db
, ejdb::collection
, and ejdb::query
, which correspond to the opaque types EJDB
, EJCOLL
, and EJQ
, respectively. Valid ejdb::collection
and ejdb::query
objects can only be created via ejdb::db
; their default, or ill-constructed forms will give errors when attempting to perform operations on them.
ejpp does not impose a specific form of BSON data other than std::vector<char>
so that it can be used with your favourite BSON library.
Many ejpp functions offer throwing and non-throwing overloads. Non-throwing overloads take an extra parameter, a non-const lvalue reference to a std::error_code
.
Queries are handled in much the same way as EJDB. A ejdb::query
object is created from a BSON document, and can then be manipulated (add hints, $or
or $and
conditions) and executed. Queries can be executed with several different flags which will change the behaviour and return type of the query result.
EJDB supports transactions at the collection level, and ejpp wraps this functionality via the class ejdb::collection::transaction_t
, which is contained within each ejdb::collection
. This class alone provides no additional safety features, though with the help of ejdb::transaction_guard
and ejdb::unique_transaction
ejpp provides exception safety using RAII. ejdb::transaction_guard
and ejdb::unique_transaction
are mostly modelled after std::lock_guard
and std::unique_lock
, respectively.
If EJDB is in a non-standard location, pass EJDB_INCLUDE_DIR
and EJDB_LIBRARY_DIR
options to cmake.
EJPP_ENABLE_TESTING
- set to ON
to enable testing. OFF
by default. See Testing.EJPP_SANITIZE_ADDRESS
- set to ON
to build with -fsanitize=address
. OFF
by default.EJPP_LEAK_CHECKER
- set to ON
to build with -fsanitize=leak
. OFF
by default.EJPP_DOC_OUTPUT_DIR
- set to a path to output generated documentation. ./doc
by default. See Documentation.EJPP_LIBDIR_SUFFIX
- set to a string to add a suffix to the installation library directory, e.g. "64" to install to ${PREFIX}/lib64.API documentation can be viewed at http://chrismanning.github.io/ejpp or generated with doxygen.
It can then be viewed in a web browser by opening the generated index.html
, or any other file.
Unit testing (enabled via EJPP_ENABLE_TESTING
) has some additional requirements.
JBSON_INCLUDE_DIR
.