MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / exportSQLResult

Function exportSQLResult

src/utils/sqlExport.ts:38–66  ·  view source on GitHub ↗
(
  data: SQLExportData,
  format: SQLExportFormat
)

Source from the content-addressed store, hash-verified

36 * 导出 SQL 结果到文件
37 */
38export async function exportSQLResult(
39 data: SQLExportData,
40 format: SQLExportFormat
41): Promise<{ success: boolean; filePath?: string; error?: string }> {
42 if (data.rows.length === 0) {
43 return { success: false, error: 'No data to export' }
44 }
45
46 const timestamp = dayjs().format('YYYYMMDD_HHmmss')
47 const filename = `sql_result_${timestamp}.${format}`
48
49 let content: string
50 let mimeType: string
51
52 if (format === 'json') {
53 content = formatAsJSON(data)
54 mimeType = 'application/json'
55 } else {
56 content = formatAsCSV(data)
57 mimeType = 'text/csv'
58 }
59
60 // 转换为 data URL 并保存
61 const dataUrl = `data:${mimeType};charset=utf-8,${encodeURIComponent(content)}`
62 const { useCacheService } = await import('@/services/cache/service')
63 const result = await useCacheService().saveToDownloads(filename, dataUrl)
64
65 return result
66}

Callers

nothing calls this directly

Calls 4

formatAsJSONFunction · 0.85
formatAsCSVFunction · 0.85
useCacheServiceFunction · 0.85
saveToDownloadsMethod · 0.65

Tested by

no test coverage detected