35 const std::string &command,
36 std::istream ¶meters,
41 if (command ==
"table")
43 const Table_Id table_id = parse_table(parameters, readable);
45 size_t max_column_width = 25;
55 parameters >> start >> length;
59 const auto &fields = readable.get_fields(table_id);
60 std::map<Field_Id, size_t> column_width;
62 for (
const auto &[fid, fname]: fields)
63 column_width[fid] = fname.size();
68 std::map<Field_Id, std::vector<std::string>> columns;
69 std::vector<Record_Id> id_column;
72 const Record_Id size = readable.get_size(table_id);
73 for (
Record_Id record_id{0}; record_id < size; ++record_id)
77 readable.is_used(table_id, record_id) &&
78 (length == 0 || (record_id >= start && record_id < start + length))
82 id_column.emplace_back(record_id);
84 for (
const auto &[fid, fname]: fields)
86 std::ostringstream ss;
89 const std::string &s = ss.str();
91 if (column_width[fid] < width)
92 column_width[fid] = width;
93 columns[fid].emplace_back(s);
103 std::ostringstream ss;
106 id_width = ss.str().size();
108 size_t table_width = id_width;
109 for (
const auto &[fid, fname]: fields)
111 if (max_column_width && column_width[fid] > max_column_width)
112 column_width[fid] = max_column_width;
113 table_width += column_width[fid] + 1;
119 out << std::string(table_width,
'-') <<
'\n';
120 out << std::string(id_width,
' ');
121 for (
const auto &[fid, fname]: fields)
134 type_id == Type::Type_Id::string
138 out << std::string(table_width,
'-') <<
'\n';
143 for (
size_t i = 0; i < rows; i++)
145 out << std::setw(
int(id_width)) << id_column[i];
147 for (
const auto &[fid, fname]: fields)
161 type_id == Type::Type_Id::string
168 else if (command ==
"record")
170 const Table_Id table_id = parse_table(parameters, readable);
172 if (!(parameters >> record_id))
175 const auto &freedom = readable.get_freedom(table_id);
177 if (!readable.is_used(table_id, record_id))
180 out << record_id <<
" is not used.\n";
181 out <<
"first_used: " << freedom.get_first_used() <<
'\n';
182 out <<
"last_used: " << freedom.get_last_used() <<
'\n';
183 out <<
"used_count: " << freedom.get_used_count() <<
'\n';
184 out <<
"size: " << freedom.get_size() <<
'\n';
185 out <<
"dense: " << freedom.is_dense() <<
'\n';
189 out <<
"id = " << record_id;
190 out <<
"; next = " << freedom.get_next(record_id);
191 out <<
"; previous = " << freedom.get_previous(record_id) <<
'\n';
193 const auto &fields = readable.get_fields(table_id);
194 size_t max_field_size = 0;
195 for (
const auto &[fid, fname]: fields)
196 if (fname.size() > max_field_size)
197 max_field_size = fname.size();
199 for (
const auto &[fid, fname]: fields)
201 out << std::setw(
int(max_field_size)) << fname <<
": ";
207 else if (command ==
"schema")
210 dump(readable, dump_writable,
true);
212 else if (command ==
"dump")
215 dump(readable, dump_writable);
217 else if (command ==
"sql")
220 dump(readable, dump_writable);
222 else if (command ==
"json")
224 bool use_base64 =
false;
225 parameters >> use_base64;
228 else if (command ==
"help")
230 out << R
"RRR(Displaying data
232 table <table_name> [<max_column_width>] [start] [length]
233 record <table_name> [<record_id>]