forked from blue/lmdbal
creation of the directory is no a separate method
This commit is contained in:
parent
6ff22c9377
commit
6ae32e38b6
32
database.cpp
32
database.cpp
@ -51,16 +51,7 @@ void DataBase::open()
|
||||
{
|
||||
if (!opened) {
|
||||
mdb_env_create(&environment);
|
||||
QString path(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
|
||||
path += "/" + getName();
|
||||
QDir cache(path);
|
||||
|
||||
if (!cache.exists()) {
|
||||
bool res = cache.mkpath(path);
|
||||
if (!res) {
|
||||
throw Directory(path.toStdString());
|
||||
}
|
||||
}
|
||||
QString path = createDirectory();
|
||||
|
||||
mdb_env_set_maxdbs(environment, tables.size());
|
||||
mdb_env_set_mapsize(environment, size * 1024UL * 1024UL);
|
||||
@ -98,6 +89,27 @@ bool DataBase::removeDirectory()
|
||||
}
|
||||
}
|
||||
|
||||
QString DataBase::createDirectory()
|
||||
{
|
||||
if (opened) {
|
||||
throw Opened(name, "create database directory");
|
||||
}
|
||||
|
||||
QString path(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
|
||||
path += "/" + getName();
|
||||
QDir cache(path);
|
||||
|
||||
if (!cache.exists()) {
|
||||
bool res = cache.mkpath(path);
|
||||
if (!res) {
|
||||
throw Directory(path.toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
QString DataBase::getName() const
|
||||
{
|
||||
return QString::fromStdString(name);
|
||||
|
@ -44,9 +44,11 @@ public:
|
||||
void close();
|
||||
bool ready() const;
|
||||
bool removeDirectory();
|
||||
QString createDirectory();
|
||||
QString getName() const;
|
||||
void drop();
|
||||
|
||||
|
||||
template <class K, class V>
|
||||
Table<K, V>* addTable(const std::string& name);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user