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 d972549 commit ccac4b3
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,22 @@ async function executeQueryTable(query: string): Promise<string[]> {
reject(err);
} else {
// Print the SQL query within ```sql tags
const chunks = ['```sql\n', query, ' \n', '```\n', '\n'];
const chunks = [];
// const chunks = ['```sql\n', query, ' \n', '```\n', '\n'];
// Format the result into a markdown table
if (result.length > 0) {
chunks.push('```\n');
chunks.push('### Query Results\n');
chunks.push('\n');
const headers = Object.keys(result[0]);
chunks.push('| ' + headers.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');
} else {
chunks.push('No results found.\n');
}
chunks.push('```');
chunks.push('\n');
resolve(chunks);
}
});
Expand Down Expand Up @@ -142,7 +140,7 @@ app.post("/", async (c) => {
// Check if the message contains a SQL query
if (containsSQLQuery(userPrompt)) {
try {
const resultChunks = await executeQueryPretty(userPrompt);
const resultChunks = await executeQueryTable(userPrompt);
// stream.write(createTextEvent(`Hi ${user.data.login}! Here are your query results:\n`));
for (const chunk of resultChunks) {
stream.write(createTextEvent(chunk));
Expand Down

0 comments on commit ccac4b3

Please sign in to comment.