#pragma once #include #include #include namespace { template typename std::enable_if::type add_column_name(std::string&) { } template typename std::enable_if::type add_column_name(std::string& out) { using ColumnType = typename std::remove_reference(std::declval>()))>::type; out += ColumnType::name; if (N != sizeof...(T) - 1) out += ","; add_column_name(out); } } template void create_index(sqlite3* db, const std::string& name, const std::string& table) { std::string res{"CREATE INDEX IF NOT EXISTS "}; res += name + " ON " + table + "("; add_column_name<0, Columns...>(res); res += ")"; char* error; const auto result = sqlite3_exec(db, res.data(), nullptr, nullptr, &error); if (result != SQLITE_OK) { log_error("Error executing query: ", error); sqlite3_free(error); } }