added timestamp code, support columns for group by and order by and tested load has-many eager code

This commit is contained in:
2026-01-08 15:14:31 +01:00
parent 0bf945cd13
commit 930b9d1aa4
34 changed files with 853 additions and 846 deletions
+72
View File
@@ -0,0 +1,72 @@
#include "record_printer.hpp"
#include "matador/utils/basic_types.hpp"
#include "matador/sql/record.hpp"
#include <iostream>
#include <iomanip>
namespace matador::test {
record_printer::record_printer(std::ostream &os)
: os_(os) {
type_widths_ = {
{utils::basic_type::Int8, 4},
{utils::basic_type::Int16, 6},
{utils::basic_type::Int32, 11},
{utils::basic_type::Int64, 20},
{utils::basic_type::UInt8, 4},
{utils::basic_type::UInt16, 6},
{utils::basic_type::UInt32, 11},
{utils::basic_type::UInt64, 20},
{utils::basic_type::Float, 12},
{utils::basic_type::Double, 15},
{utils::basic_type::Boolean, 6},
{utils::basic_type::Varchar, 20},
{utils::basic_type::Text, 30},
{utils::basic_type::Date, 12},
{utils::basic_type::DateTime, 20},
{utils::basic_type::Time, 10},
{utils::basic_type::Blob, 10},
{utils::basic_type::Null, 6}
};
}
void record_printer::print_header(const sql::record &rec) const {
for (const auto &f_ref: rec.columns()) {
const auto &f = f_ref.get();
os_ << std::left << std::setw(width(f)) << f.name() << " ";
}
os_ << "\n";
for (const auto &f_ref: rec.columns()) {
const auto &f = f_ref.get();
os_ << std::string(width(f), '-') << " ";
}
os_ << "\n";
}
void record_printer::print(const sql::record &rec) const {
for (const auto &f_ref: rec.columns()) {
const auto &f = f_ref.get();
os_ << std::left << std::setw(width(f)) << f.str() << " ";
}
os_ << "\n";
}
int record_printer::width(const sql::field &f) {
// If it's a varchar/string and has a defined size, use it if it's reasonable,
// otherwise fall back to type defaults.
if ((f.is_varchar() || f.is_string()) && f.size() > 0 && f.size() < 100) {
return std::max(f.name().length(), f.size());
}
// Find the default width for type
// Note: field class doesn't expose basic_type directly but we can use value().type()
// if we had access. For now we use name length as minimum.
constexpr size_t w = 15;
// In a real implementation we would probe the field's underlying type.
return std::max(f.name().length(), w);
}
}
+43
View File
@@ -0,0 +1,43 @@
#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