27 std::map<Table_Id, std::vector<int64_t>> reference_translation;
28 std::map<Table_Id, int64_t> table_size;
29 for (
const auto &[tid, tname]: db.get_tables())
32 std::vector<int64_t> &v = reference_translation[tid];
33 v.resize(
size_t(size));
35 for (
Record_Id record_id{0}; record_id < size; ++record_id)
37 if (!db.is_used(tid, record_id))
38 v[
size_t(record_id)] = -1;
40 v[size_t(record_id)] = position++;
42 table_size[tid] = position;
50 bool first_table =
true;
51 for (
const auto &[tid, tname]: db.get_tables())
60 out <<
" \"" << tname <<
"\":\n {\n";
62 out <<
" \"__size\": " << table_size[tid];
64 for (
const auto &[fid, fname]: db.get_fields(tid))
66 const Type &type = db.get_field_type(tid, fid);
69 out <<
" \"" << fname <<
"\": [";
71 bool first_value =
true;
72 for (
Record_Id record_id{0}; record_id < size; ++record_id)
74 if (db.is_used(tid, record_id))
86 case Type::Type_Id::reference:
88 Record_Id reference = db.get_reference(tid, record_id, fid);
89 const auto it = reference_translation.find(type.
get_table_id());
90 if (it != reference_translation.end())
92 const std::vector<int64_t> &v = it->second;
93 if (
to_underlying(reference) < 0 || size_t(reference) >= v.size())
96 out << v[size_t(reference)];
103 case Type::Type_Id::string:
105 const std::string &s = db.get_string(tid, record_id, fid);
110 case Type::Type_Id::blob:
112 const Blob blob = db.get_blob(tid, record_id, fid);
117 #define TYPE_MACRO(type, return_type, type_id, R, W)\
118 case Type::Type_Id::type_id:\
120 const auto x = db.get_##type_id(tid, record_id, fid);\
121 if (std::isnan(x) || std::isinf(x))\
124 result |= JSON_Error::infnan;\
127 write_##type_id(out, x);\
130 #define TYPE_MACRO_NO_REFERENCE
131 #define TYPE_MACRO_NO_STRING
132 #define TYPE_MACRO_NO_BLOB
133 #define TYPE_MACRO_NO_INT
136 #define TYPE_MACRO(type, return_type, type_id, R, W)\
137 case Type::Type_Id::type_id:\
139 const auto x = db.get_##type_id(tid, record_id, fid);\
140 write_##type_id(out, x);\
143 #define TYPE_MACRO_NO_REFERENCE
144 #define TYPE_MACRO_NO_STRING
145 #define TYPE_MACRO_NO_BLOB
146 #define TYPE_MACRO_NO_FLOAT