Skip to content

Commit

Permalink
Add cypherl output format
Browse files Browse the repository at this point in the history
  • Loading branch information
gitbuda committed May 20, 2023
1 parent 58e3b8d commit 7f0655c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ DEFINE_bool(use_ssl, false, "Use SSL when connecting to the server.");
DEFINE_bool(fit_to_screen, false, "Fit output width to screen width.");
DEFINE_bool(term_colors, false, "Use terminal colors syntax highlighting.");
DEFINE_string(output_format, "tabular",
"Query output format can be csv or tabular. If output format is "
"Query output format can be csv, tabular or cypherl. If output format is "
"not tabular `fit-to-screen` flag is ignored.");
DEFINE_bool(verbose_execution_info, false,
"Output the additional information about query such as query cost, parsing, planning and execution times.");
DEFINE_validator(output_format, [](const char *, const std::string &value) {
if (value == constants::kCsvFormat || value == constants::kTabularFormat) {
if (value == constants::kCsvFormat || value == constants::kTabularFormat || value == constants::kCypherlFormat) {
return true;
}
return false;
Expand Down
1 change: 1 addition & 0 deletions src/utils/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ constexpr const std::string_view kCommandDocs = ":docs";
// Supported formats.
constexpr const std::string_view kCsvFormat = "csv";
constexpr const std::string_view kTabularFormat = "tabular";
constexpr const std::string_view kCypherlFormat = "cypherl";

// Supported modes.
constexpr const std::string_view kSerialMode = "serial";
Expand Down
14 changes: 14 additions & 0 deletions src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,12 +1186,26 @@ void PrintCsv(const std::vector<std::string> &header, const std::vector<mg_memor
}
}

void PrintCypherl(const std::vector<std::string> &header, const std::vector<mg_memory::MgListPtr> &records) {
MG_ASSERT(header.size() == 1, "Cypherl output format required exactly 1 output column.");
for (size_t record_i = 0; record_i < records.size(); ++record_i) {
const auto &fields = records[record_i];
for (uint32_t field_i = 0; field_i < mg_list_size(fields.get()); ++field_i) {
const auto *query_ptr = mg_value_string(mg_list_at(fields.get(), field_i));
auto query = std::string(mg_string_data(query_ptr), mg_string_size(query_ptr));
std::cout << query << std::endl;
}
}
}

void Output(const std::vector<std::string> &header, const std::vector<mg_memory::MgListPtr> &records,
const OutputOptions &out_opts, const CsvOptions &csv_opts) {
if (out_opts.output_format == constants::kTabularFormat) {
PrintTabular(header, records, out_opts.fit_to_screen);
} else if (out_opts.output_format == constants::kCsvFormat) {
PrintCsv(header, records, csv_opts);
} else if (out_opts.output_format == constants::kCypherlFormat) {
PrintCypherl(header, records);
}
}

Expand Down

0 comments on commit 7f0655c

Please sign in to comment.