LMDBAL 0.5.4
LMDB (Lightning Memory-Mapped Database Manager) Abstraction Layer
|
Database abstraction. More...
Public Member Functions | |
Base (const QString &name, uint16_t mapSize=10) | |
Creates the database. | |
~Base () | |
Destroys the database. | |
void | open () |
Opens the database. | |
void | close () |
Closes the database. | |
bool | ready () const |
Returns database state. | |
bool | removeDirectory () |
Removes database directory. | |
QString | createDirectory () |
Creates database directory. | |
QString | getName () const |
Returns database name. | |
QString | getPath () const |
Returns database name. | |
void | drop () |
Drops the database. | |
Transaction | beginReadOnlyTransaction () const |
Begins read-only transaction. | |
WriteTransaction | beginTransaction () |
Begins writable transaction. | |
template<class K , class V > | |
LMDBAL::Storage< K, V > * | addStorage (const std::string &storageName, bool duplicates=false) |
Adds LMDBAL::Storage to the database. | |
template<class K , class V > | |
LMDBAL::Cache< K, V > * | addCache (const std::string &storageName) |
Adds LMDBAL::Cache to the database. | |
template<class K , class V > | |
LMDBAL::Storage< K, V > * | getStorage (const std::string &storageName) |
Returns LMDBAL::Storage handle. | |
template<class K , class V > | |
LMDBAL::Cache< K, V > * | getCache (const std::string &storageName) |
Returns LMDBAL::Cache handle. | |
Friends | |
class | iStorage |
class | Transaction |
class | WriteTransaction |
Database abstraction.
This is a basic class that represents the database as a collection of storages. Storages is something key-value database has instead of tables in classic SQL databases.
LMDBAL::Base::Base | ( | const QString & | _name, |
uint16_t | _mapSize = 10 ) |
Creates the database.
[in] | _name | - name of the database, it is going to affect folder name that is created to store data |
[in] | _mapSize | - LMDB map size (MiB), multiplied by 1024^2 and passed to mdb_env_set_mapsize during the call of LMDBAL::Base::open() |
LMDBAL::Cache< K, V > * LMDBAL::Base::addCache | ( | const std::string & | storageName | ) |
Adds LMDBAL::Cache to the database.
Defines that the database is going to have the following cache. The LMDBAL::Base must be closed
[in] | storageName | - cache name |
K | - key type of the cache |
V | - value type of the cahce |
LMDBAL::Opened | thrown if this method is called on the opened database |
LMDBAL::StorageDuplicate | thrown if somebody tries to add cache with repeating name |
LMDBAL::Storage< K, V > * LMDBAL::Base::addStorage | ( | const std::string & | storageName, |
bool | duplicates = false ) |
Adds LMDBAL::Storage to the database.
Defines that the database is going to have the following storage. The LMDBAL::Base must be closed
[in] | storageName | - storage name |
[in] | duplicates | - true if key duplicates are allowed (false by default) |
K | - key type of the storage |
V | - value type of the storage |
LMDBAL::Opened | thrown if this method is called on the opened database |
LMDBAL::StorageDuplicate | thrown if somebody tries to add storage with repeating name |
LMDBAL::Transaction LMDBAL::Base::beginReadOnlyTransaction | ( | ) | const |
Begins read-only transaction.
This is the legitimate way to retrieve LMDBAL::Transaction. LMDBAL::Transaction is considered runnig right after creation by this method. You can terminate transaction manually calling LMDBAL::Transaction::terminate but it's not required, because transaction will be terminated automatically (if it was not terminated manually) upon the call of the destructor.
You can not use termitated transaction any more.
LMDBAL::Closed | - thrown if the database is closed |
LMDBAL::Unknown | - thrown if something unexpected happened |
LMDBAL::WriteTransaction LMDBAL::Base::beginTransaction | ( | ) |
Begins writable transaction.
This is the legitimate way to retrieve LMDBAL::WriteTransaction. LMDBAL::WriteTransaction is considered runnig right after creation by this method. You can commit all the changes made by this transaction calling LMDBAL::WriteTransaction::commit. You can cancel any changes made bu this transaction calling LMDBAL::WriteTransaction::abort (or LMDBAL::Transaction::terminate which LMDBAL::WriteTransaction inherits), but it's not required, because transaction will be aborted automatically (if it was not terminated (committed OR aborted) manually) upon the call of the destructor.
You can not use termitated transaction any more.
LMDBAL::Closed | - thrown if the database is closed |
LMDBAL::Unknown | - thrown if something unexpected happened |
void LMDBAL::Base::close | ( | ) |
Closes the database.
Closes all lmdb handles, aborts all public transactions. This function will do nothing on closed database
LMDBAL::Unknown | - thrown if something went wrong aborting transactions |
QString LMDBAL::Base::createDirectory | ( | ) |
Creates database directory.
Creates or opens existing directory with the given name in the location acquired with QStandardPaths::writableLocation(QStandardPaths::CacheLocation) so, the file system destination of your data would depend on the QCoreApplication configuration of your app. This function does nothing if the directory was already created
LMDBAL::Opened | - thrown if called on opened database |
LMDBAL::Directory | - if the database couldn't create the folder |
void LMDBAL::Base::drop | ( | ) |
Drops the database.
Clears all caches and storages of the database
LMDBAL::Closed | - thrown if the database is closed |
LMDBAL::Unknown | - thrown if something unexpected happend |
LMDBAL::Cache< K, V > * LMDBAL::Base::getCache | ( | const std::string & | storageName | ) |
Returns LMDBAL::Cache handle.
Requested cache must have been added before opening database Note that template parameters is user responsibility zone! If user, for instance, had added cache <int, int> but calling this method with template parameters <std::string, std::string> on the same name of the previously added cache, or calling it on storage - the behaviour is undefined
[in] | storageName | - cache name |
K | - key type of the cache |
V | - value type of the cahce |
std::out_of_range | thrown if cache with the given name was not found |
QString LMDBAL::Base::getName | ( | ) | const |
Returns database name.
QString LMDBAL::Base::getPath | ( | ) | const |
Returns database name.
LMDBAL::Storage< K, V > * LMDBAL::Base::getStorage | ( | const std::string & | storageName | ) |
Returns LMDBAL::Storage handle.
Requested storage must have been added before opening database Note that template parameters is user responsibility zone! If user, for instance, had added storage <int, int> but calling this method with template parameters <std::string, std::string> on the same name of the previously added storage, or calling it on cache - the behaviour is undefined
[in] | storageName | - storage name |
K | - key type of the storage |
V | - value type of the storage |
std::out_of_range | thrown if storage with the given name was not found |
void LMDBAL::Base::open | ( | ) |
Opens the database.
Almost every LMDBAL::Base require it to be opened, this function does it. It laso creates the directory for the database if it was an initial launch. This function will do nothing on opened database
LMDBAL::Unknown | - thrown if something went wrong opening storages and caches |
bool LMDBAL::Base::ready | ( | ) | const |
Returns database state.
bool LMDBAL::Base::removeDirectory | ( | ) |
Removes database directory.
LMDBAL::Opened | - thrown if this function was called on opened database |