(data: SQLExportData)
| 11 | * 将 SQL 结果格式化为 CSV |
| 12 | */ |
| 13 | export function formatAsCSV(data: SQLExportData): string { |
| 14 | const header = data.columns.join(',') |
| 15 | const rows = data.rows.map((row) => |
| 16 | row.map((cell) => (cell === null ? '' : `"${String(cell).replace(/"/g, '""')}"`)).join(',') |
| 17 | ) |
| 18 | return [header, ...rows].join('\n') |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * 将 SQL 结果格式化为 JSON(数组对象形式) |