query/test/utils/record_printer.hpp

44 lines
875 B
C++

#ifndef MATADOR_RECORD_PRINTER_HPP
#define MATADOR_RECORD_PRINTER_HPP
#include "matador/sql/record.hpp"
#include <iosfwd>
#include <map>
namespace matador::sql {
class field;
class record;
}
namespace matador::test {
class record_printer final {
public:
explicit record_printer(std::ostream &os);
void print_header(const sql::record &rec) const;
void print(const sql::record &rec) const;
template < class Type, template <typename ...> class ContainerType >
void print(ContainerType<Type> &records) const {
bool first = true;
for (const auto &rec: records) {
if (first) {
print_header(rec);
first = false;
}
print(rec);
}
}
private:
[[nodiscard]] static int width(const sql::field &f) ;
private:
std::ostream &os_;
std::map<utils::basic_type, int> type_widths_;
};
}
#endif //MATADOR_RECORD_PRINTER_HPP