From 9e9a1449ee64cd280de5cb623b18e23d8c33751f Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 20 Apr 2018 14:13:35 -0700 Subject: [PATCH] modules/console: Add cmd to set column or database runtime options. --- modules/console.cc | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/modules/console.cc b/modules/console.cc index 286ee3d83..c2e66b15f 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -873,6 +873,79 @@ console_cmd__db__stats(opt &out, const string_view &line) }); } +bool +console_cmd__db__set(opt &out, const string_view &line) +try +{ + const params param{line, " ", + { + "dbname", "column", "option", "value" + }}; + + const auto dbname + { + param.at(0) + }; + + const auto colname + { + param.at(1, "*"_sv) + }; + + const auto option + { + param.at(2) + }; + + const auto value + { + param.at(3) + }; + + auto &database + { + *db::database::dbs.at(dbname) + }; + + // Special branch for DBOptions + if(colname == "*") + { + db::setopt(database, option, value); + out << "done" << std::endl; + return true; + } + + const auto setopt{[&out, &database, &option, &value] + (const string_view &colname) + { + db::column column + { + database, colname + }; + + db::setopt(column, option, value); + out << colname << " :done" << std::endl; + }}; + + // Branch for querying the property for a single column + if(colname != "**") + { + setopt(colname); + return true; + } + + // Querying the property for all columns in a loop + for(const auto &colname : database.column_names) + setopt(colname); + + return true; +} +catch(const std::out_of_range &e) +{ + out << "No open database by that name" << std::endl; + return true; +} + bool console_cmd__db__files(opt &out, const string_view &line) try