myTinySQL v0.2.0-2-g5000098
A tiny SQL interpreter over fixed-width text files
Loading...
Searching...
No Matches
Functions
Output.cpp File Reference

Console text, and the JSON answers of the browser server's API. More...

#include "Output.hpp"
#include <format>
#include "Util.hpp"

Go to the source code of this file.

Functions

std::string tinysql::anonymous_namespace{Output.cpp}::fit (std::string_view text, std::size_t width, char filler)
 Cuts or pads text to an exact width.
 
std::string tinysql::anonymous_namespace{Output.cpp}::headerLine (const ResultSet &table)
 Builds the dashed header line of a console table, e.g. ID-------- NOME----.
 
std::string tinysql::anonymous_namespace{Output.cpp}::jsonString (std::string_view text)
 Writes text as a JSON string: in double quotes, with quotes, backslashes and control characters escaped.
 
std::string tinysql::renderText (const StatementResult &result)
 Formats one result for the console.
 
std::string tinysql::renderJson (const std::vector< StatementResult > &results)
 Builds the JSON answer of POST /api/sql: one object per statement that has something to show.
 
std::string tinysql::renderTablesJson (const std::vector< TableSchema > &tables)
 Builds the JSON answer of GET /api/tables: every table with its columns.
 

Detailed Description

Console text, and the JSON answers of the browser server's API.

Definition in file Output.cpp.

Function Documentation

◆ renderJson()

std::string tinysql::renderJson ( const std::vector< StatementResult > &  results)

Builds the JSON answer of POST /api/sql: one object per statement that has something to show.

Example: {"results":[{"sql":"DELETE FROM EMPLOY WHERE ID = 3","ok":true,"message":"1 row deleted from EMPLOY", "table":"EMPLOY"}]}. A SELECT or DESCRIBE also has "columns" (name, width in the data file, and whether the browser may edit the cell), "rows" (arrays of strings) and "idColumn" (index of the ID, or null).

Parameters
resultsThe results of a script, in order; silent ones (COLUMN, comments) are left out.
Returns
The JSON text.

Definition at line 95 of file Output.cpp.

◆ renderTablesJson()

std::string tinysql::renderTablesJson ( const std::vector< TableSchema > &  tables)

Builds the JSON answer of GET /api/tables: every table with its columns.

Example: {"tables":[{"name":"EMPLOY","readOnly":false,"autoId":true,"columns":[{"name":"ID","width":10},...]}]}. readOnly is true for SYSTEM_TABLE, which the page must not change.

Parameters
tablesThe tables, from Catalog::tables().
Returns
The JSON text.

Definition at line 131 of file Output.cpp.

◆ renderText()

std::string tinysql::renderText ( const StatementResult &  result)

Formats one result for the console.

Parameters
resultThe result of one statement.
Returns
An echo of the statement, then a dashed header line and fixed-width rows, a message, or an error; empty for a silent result.

Definition at line 67 of file Output.cpp.