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)
64 const size_t width = fname.size();
65 column_width[fid] = width;
71 std::map<Field_Id, std::vector<std::string>> columns;
72 std::vector<Record_Id> id_column;
75 const Record_Id last_record_id = readable.get_last_record_id(table_id);
80 readable.is_used(table_id, record_id) &&
81 (length == 0 || (record_id >= start && record_id < start + length))
85 id_column.emplace_back(record_id);
87 for (
const auto &[fid, fname]: fields)
89 std::ostringstream ss;
92 const std::string &s = ss.str();
94 if (column_width[fid] < width)
95 column_width[fid] = width;
96 columns[fid].emplace_back(s);
106 std::ostringstream ss;
107 ss << last_record_id;
109 id_width = ss.str().size();
111 size_t table_width = id_width;
112 for (
const auto &[fid, fname]: fields)
114 if (max_column_width && column_width[fid] > max_column_width)
115 column_width[fid] = max_column_width;
116 table_width += column_width[fid] + 1;
122 out << std::string(table_width,
'-') <<
'\n';
123 out << std::string(id_width,
' ');
124 for (
const auto &[fid, fname]: fields)
137 type_id == Type::Type_Id::string
141 out << std::string(table_width,
'-') <<
'\n';
146 for (
size_t i = 0; i < rows; i++)
148 out << std::setw(
int(id_width)) << id_column[i];
150 for (
const auto &[fid, fname]: fields)
164 type_id == Type::Type_Id::string
171 else if (command ==
"record")
173 const Table_Id table_id = parse_table(parameters, readable);
175 if (!(parameters >> record_id))
177 if (!readable.is_used(table_id, record_id))
180 const auto &fields = readable.get_fields(table_id);
181 size_t max_field_size = 0;
182 for (
const auto &[fid, fname]: fields)
183 if (fname.size() > max_field_size)
184 max_field_size = fname.size();
186 for (
const auto &[fid, fname]: fields)
188 out << std::setw(
int(max_field_size)) << fname <<
": ";
193 else if (command ==
"table_size")
195 const Table_Id table_id = parse_table(parameters, readable);
196 const auto &freedom = readable.get_freedom(table_id);
197 out << freedom.get_used_count() <<
'\n';
199 else if (command ==
"schema")
202 dump(readable, dump_writable,
true);
204 else if (command ==
"dump")
207 dump(readable, dump_writable);
209 else if (command ==
"sql")
212 dump(readable, dump_writable);
214 else if (command ==
"json")
216 bool use_base64 =
false;
217 parameters >> use_base64;
220 else if (command ==
"help")
222 out << R
"RRR(Displaying data
224 table <table_name> [<max_column_width>] [start] [length]
225 record <table_name> [<record_id>]
226 table_size <table_name>