|
All checks were successful
Main LMDBAL workflow / Test LMDBAL with qt5 (push) Successful in 24s
Main LMDBAL workflow / Test LMDBAL with qt6 (push) Successful in 29s
Main LMDBAL workflow / Builds documentation (push) Successful in 22s
Main LMDBAL workflow / Deploys documentation (push) Successful in 1s
|
||
|---|---|---|
| .forgejo/workflows | ||
| cmake | ||
| doc | ||
| packaging/Archlinux | ||
| src | ||
| test | ||
| CHANGELOG.md | ||
| CMakeLists.txt | ||
| LICENSE.md | ||
| README.md | ||
LMDBAL - Lightning Memory Data Base Abstraction Level
LMDBAL is a thin C++17 wrapper around LMDB that plays nicely with Qt. Storages are declared with templates, transactions are handled via RAII helpers, and the LMDB environment stays open only for as long as you keep an active session.
Prerequisites
- a C++17 compiler (GCC or Clang are tested);
- Qt 5 or 6 Core module (
qt5-baseorqt6-base); - LMDB development headers and runtime library;
- CMake 3.16 or higher;
- Doxygen (optional, for documentation);
- GoogleTest (optional, for tests).
Using with CMake
As a system library
If you're using LMDBAL as a system library, you probably have no control over its build options. The easiest way to include the project is to add the following:
find_package(lmdbal CONFIG REQUIRED)
target_link_libraries(yourTarget PRIVATE LMDBAL::LMDBAL)
If you overrode LMDBAL_NAME while building the package, use ${LMDBAL_NAME}::${LMDBAL_NAME} instead of LMDBAL::LMDBAL.
As an embedded subproject
If you're using LMDBAL as an embedded library, you might want to control its build options, for example, you can run
set(LMDBAL_BUILD_STATIC ON CACHE BOOL "" FORCE)
... before including the library in your project. This will build the library as a static one.
Then you want to run something like this:
add_subdirectory(pathTo/yourEmbedded/libraries/lmdbal)
add_library(LMDBAL::LMDBAL ALIAS LMDBAL) # optional
target_link_libraries(yourTarget PRIVATE LMDBAL::LMDBAL)
The headers are already exported as PUBLIC, so you usually do not need an extra target_include_directories call.
Usage
Creating a database no longer flips the environment into the opened state immediately.
LMDBAL::Base::open() returns a LMDBAL::Session object that keeps the environment alive while it exists.
Destroying the session (or calling session.close()) closes the database and aborts any remaining public transactions.
#include "base.h"
#include "storage.h"
#include "session.h"
LMDBAL::Base base(QStringLiteral("myDataBase"));
auto* storage = base.addStorage<uint32_t, uint32_t>("storage");
LMDBAL::Session session = base.open();
storage->addRecord(54, 75);
session.close(); // optional – calling it explicitly can surface errors early
Make sure every storage or cache is registered before you open the database.
addStorage accepts an optional duplicates flag when the same key may appear multiple times:
auto* withDuplicates = base.addStorage<int, int>("storageWithDuplicates", true);
Write operations can be grouped inside transactions:
#include "transaction.h"
LMDBAL::WriteTransaction txn = base.beginTransaction();
storage->addRecord(1, 2, txn);
storage->addRecord(3, 4, txn);
txn.commit();
Read-only access can be obtained through LMDBAL::Base::beginReadOnlyTransaction() to keep a stable snapshot while writers are active.
Building
LMDBAL uses CMake as a build system.
Please check the prerequisites and install them before building.
Here is an easy way to build the project:
$ git clone https://git.macaw.me/blue/lmdbal
$ cd lmdbal
$ mkdir build
$ cd build
$ cmake .. [ *optional keys* ]
$ cmake --build .
$ cmake --install . --prefix install
This will create a lmdbal/build directory with intermediate files, and lmdbal/build/install with everything ready to be installed into your system.
After cmake .. you can specify keys to alter the building process.
In this context building keys are transferred like so:
cmake .. -D KEY1=VALUE1 -D KEY2=VALUE2 ...
List of keys
Here is the list of keys you can pass to configuration phase of cmake ..:
CMAKE_BUILD_TYPE-Debugbuilds with symbols and run-time checks,Releasebuilds with optimizations (default isDebug);LMDBAL_BUILD_STATIC-ONbuilds a static library,OFFbuilds a shared library (default isOFF);LMDBAL_BUILD_TESTS-ONbuilds unit tests,OFFskips them (default isOFF);LMDBAL_BUILD_DOC_MAN-ONbuilds the man page documentation (default isOFF);LMDBAL_BUILD_DOC_HTML-ONbuilds the HTML documentation (default isOFF);LMDBAL_BUILD_DOC_XML-ONbuilds the XML documentation (default isOFF);LMDBAL_BUILD_DOXYGEN_AWESOME-ONbuilds the Doxygen Awesome theme if any documentation is enabled (default isOFF);QT_VERSION_MAJOR-5links against Qt5,6links against Qt6, if not specified CMake tries to pick the best match;LMDBAL_NAME- overrides the main target name, the install directory will follow the lowercase version (useful for packaging variants likeLMDBAL-QT6);LMDBAL_STRICT-ONenables extra warnings and treats them as errors (default isOFF);LMDBAL_ASAN-ONenables address sanitizer (GNU/Clang only, default isOFF);LMDBAL_TSAN-ONenables thread sanitizer (GNU/Clang only, default isOFF);LMDBAL_UBSAN-ONenables undefined behavior sanitizer (GNU/Clang only, default isOFF).
Running tests
If you built the library with -D LMDBAL_BUILD_TESTS=ON, then there will be a lmdbal/build/test/runUnitTests executable file. You can run it as
./test/runUnitTests
... if you're in the same directory with it.
The tests assume they can create cache files under the current user's cache directory (QStandardPaths::CacheLocation),
so adjust XDG_CACHE_HOME if your environment has that location locked down.
License
This project is available under the GPL-3.0 license or any later version. The file cmake/FindLMDB.cmake is available under the GPL-3.0 license only — see the LICENSE.md file for details.