Commit 4d5e41b9 authored by Romain Casati's avatar Romain Casati
Browse files

Pretty console output for SQL queries (troncated output).

parent 9d1db11f
......@@ -34,20 +34,31 @@
await this.pageLoad();
};
html_table (json) {
troncate_table (json) {
const max_size = 150;
const columns = json.columns.map((c) => `<th>${c}</th>`).join('');
const head = `<thead><tr style="text-align: right;">${columns}</tr></thead>`;
if( json.values.length >= max_size ) {
const half_length = Math.floor(max_size / 3);
const head = json.values.slice(0, half_length);
const tail = json.values.slice(-half_length);
json.values = head.concat([json.columns.map(() => '')], tail);
}
};
html_table (json) {
this.troncate_table(json);
const columns = json.columns.map((c) => `<th>${c}</th>`).join('');
const head = `<thead><tr style="text-align: right;">${columns}</tr></thead>`;
const values = json.values.map((r) => '<tr>' + r.map((v) => `<td>${v}</td>`).join('') + '</tr>').join('');
const body = `<tbody>${values}</tbody>`;
return `<table class="dataframe" border="1">${head}${body}</table>`;
};
text_table (json) {
this.troncate_table(json);
const head = json.columns.join('\t');
const values = json.values.map((r) => r.join('\t')).join('\n');
return `${head}\n${values}`;
};
async evalAsync (code, outCallback, errCallback, data=null) {
// force interactivity in all modes
......@@ -60,7 +71,7 @@
if( result.length == 0 )
result = undefined
else
result = {'text/plain': JSON.stringify(result),
result = {'text/plain': this.text_table(result[0]),
'text/html': this.html_table(result[0])};
}
return [result, ++this.execution_count];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment