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())
31 const Record_Id last_record_id = db.get_last_record_id(tid);
32 std::vector<int64_t> &v = reference_translation[tid];
33 v.resize(
size_t(db.get_last_record_id(tid)) + 1);
38 if (!db.is_used(tid, record_id))
39 v[
size_t(record_id)] = -1;
41 v[size_t(record_id)] = position++;
43 table_size[tid] = position;
51 bool first_table =
true;
52 for (
const auto &[tid, tname]: db.get_tables())
54 const Record_Id last_record_id = db.get_last_record_id(tid);
61 out <<
" \"" << tname <<
"\":\n {\n";
63 out <<
" \"__size\": " << table_size[tid];
65 for (
const auto &[fid, fname]: db.get_fields(tid))
67 const Type &type = db.get_field_type(tid, fid);
70 out <<
" \"" << fname <<
"\": [";
72 bool first_value =
true;
75 if (db.is_used(tid, record_id))
87 case Type::Type_Id::reference:
89 Record_Id i = db.get_reference(tid, record_id, fid);
90 const auto it = reference_translation.find(type.
get_table_id());
91 if (it != reference_translation.end())
93 const std::vector<int64_t> &v = it->second;
94 if (
size_t(i) >= v.size())
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