Skip to content

Commit

Permalink
Update index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
lmangani authored Dec 13, 2024
1 parent ccac4b3 commit 2c78063
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,14 @@ async function executeQueryTable(query: string): Promise<string[]> {
// const chunks = ['```sql\n', query, ' \n', '```\n', '\n'];
// Format the result into a markdown table
if (result.length > 0) {
chunks.push('```\n');
const headers = Object.keys(result[0]);
chunks.push('| ' + headers.join(' | ') + ' |\n');
chunks.push('|' + headers.map(() => '---').join('|') + ' |\n');
chunks.push('| ' + headers.map(() => '---').join(' | ') + ' |\n');
result.forEach(row => {
const values = headers.map(header => row[header]);
chunks.push('| ' + values.join(' | ') + ' |\n');
});
chunks.push('```\n');
chunks.push('\n');
} else {
chunks.push('No results found.\n');
}
Expand Down

0 comments on commit 2c78063

Please sign in to comment.