formatExportToZip formats query results and writes them directly to a ZIP entry. This function streams the formatted data to minimize memory usage.
( ctx context.Context, zipw *zip.Writer, filename string, stores *store.Store, instance *store.InstanceMessage, database *store.DatabaseMessage, result *v1pb.QueryResult, request *v1pb.ExportRequest, )
| 1285 | // formatExportToZip formats query results and writes them directly to a ZIP entry. |
| 1286 | // This function streams the formatted data to minimize memory usage. |
| 1287 | func formatExportToZip( |
| 1288 | ctx context.Context, |
| 1289 | zipw *zip.Writer, |
| 1290 | filename string, |
| 1291 | stores *store.Store, |
| 1292 | instance *store.InstanceMessage, |
| 1293 | database *store.DatabaseMessage, |
| 1294 | result *v1pb.QueryResult, |
| 1295 | request *v1pb.ExportRequest, |
| 1296 | ) error { |
| 1297 | writer, err := export.CreateZipWriter(zipw, filename, request.GetPassword()) |
| 1298 | if err != nil { |
| 1299 | return err |
| 1300 | } |
| 1301 | |
| 1302 | switch request.Format { |
| 1303 | case v1pb.ExportFormat_CSV: |
| 1304 | return export.CSVToWriter(writer, result) |
| 1305 | case v1pb.ExportFormat_JSON: |
| 1306 | return export.JSONToWriter(writer, result) |
| 1307 | case v1pb.ExportFormat_SQL: |
| 1308 | return exportSQLWithContext(ctx, writer, stores, instance, database, result, request) |
| 1309 | case v1pb.ExportFormat_XLSX: |
| 1310 | return export.XLSXToWriter(writer, result) |
| 1311 | default: |
| 1312 | return errors.Errorf("unsupported export format: %s", request.Format.String()) |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | // exportSQLWithContext exports SQL INSERT statements with proper context. |
| 1317 | func exportSQLWithContext( |
no test coverage detected