Skip to content

Wraps the LMDB C API into an OOP model that allows for opening and using multiple environments and databases at once

License

Notifications You must be signed in to change notification settings

gibme-c/lmdb-cpp

Repository files navigation

lmdb-cpp: A simple OOP-style wrapper around lmdb

This library is designed to be as simple as possible to use; however, we do not guarantee full coverage of the entire LMDB API. If you're in need of something, please feel free to submit an issue or open a pull request to add the functionality you need. Otherwise, WYSIWYG.

The following features have been baked in:

  • Builds with CMake making it easy to add to other projects
  • GibHub Actions verifies that it builds on Ubuntu, Windows, and MacOS using various compilers
  • The option to compress values stored in the database using snappy compression at a small performance cost.
  • Use of shared pointers and singleton patterns to attempt thread-safety while maintaining LMDB sanity.
  • Underlying LMDB instances are closed up as required as the shared pointers are destructed (ie. when the last instance of the shared pointer leaves scope).
  • Transactions are automatically aborted unless you explicitly commit them.

Documentation

C++ API documentation can be found in the headers (.h)

Example Use

#include <lmdb_cpp.hpp>
#include <iostream>

int main () {
    auto env = LMDB::Environment::instance("sample.db");
    
    auto db = env->database();
    
    const auto key = std::string("akey");
    const auto value = std::vector<bool>(10, true);
    
    db->put(key.data(), key.size(), value.data(), value.size());
    
    const auto [error, temp_value] = db->get(key.data(), key.size());
}

Cloning the Repository

This repository uses submodules, make sure you pull those before doing anything if you are cloning the project.

git clone --recursive https://github.com/gibme-c/lmdb-cpp

As a dependency

git submodule add https://github.com/gibme-c/lmdb-cpp external/lmdb
git submodule update --init --recursive

License

This wrapper is provided under the BSD-3-Clause license found in LICENSE.

About

Wraps the LMDB C API into an OOP model that allows for opening and using multiple environments and databases at once

Resources

License

Stars

Watchers

Forks