0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-30 04:38:52 +02:00

modules/console: Improve/add db__cache subcmds.

This commit is contained in:
Jason Volk 2018-08-18 18:00:45 -07:00
parent 8537cca439
commit 926a125303

View file

@ -1472,19 +1472,24 @@ try
{
const params param{line, " ",
{
"dbname", "column"
"dbname", "column", "[key]"
}};
const auto dbname
const auto &dbname
{
param.at(0)
};
const auto colname
const auto &colname
{
param[1]
};
const auto &key
{
param[2]
};
auto &database
{
db::database::get(dbname)
@ -1504,6 +1509,30 @@ try
<< std::endl;
}};
const auto remove{[&out, &database]
(const string_view &colname, const string_view &key)
{
db::column column
{
database, colname
};
const bool removed[]
{
db::remove(cache(column), key),
db::remove(cache_compressed(column), key)
};
out << "Removed key from";
if(removed[0])
out << " [uncompressed cache]";
if(removed[1])
out << " [compressed cache]";
out << std::endl;
}};
if(!colname || colname == "**")
{
for(const auto &colname : database.column_names)
@ -1512,7 +1541,56 @@ try
return true;
}
clear(colname);
if(!key)
{
clear(colname);
return true;
}
remove(colname, key);
return true;
}
catch(const std::out_of_range &e)
{
out << "No open database by that name" << std::endl;
return true;
}
bool
console_cmd__db__cache__fetch(opt &out, const string_view &line)
try
{
const params param{line, " ",
{
"dbname", "column", "key"
}};
const auto dbname
{
param.at(0)
};
const auto colname
{
param[1]
};
const auto key
{
param[2]
};
auto &database
{
db::database::get(dbname)
};
db::column column
{
database, colname
};
db::fetch(cache(column), column, key);
return true;
}
catch(const std::out_of_range &e)