MCPcopy Create free account
hub / github.com/bytebase/bytebase / formatExportToZip

Function formatExportToZip

backend/api/v1/sql_service.go:1287–1314  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

1285// formatExportToZip formats query results and writes them directly to a ZIP entry.
1286// This function streams the formatted data to minimize memory usage.
1287func 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.
1317func exportSQLWithContext(

Callers 1

exportResultToZipFunction · 0.85

Calls 8

CreateZipWriterFunction · 0.92
CSVToWriterFunction · 0.92
JSONToWriterFunction · 0.92
XLSXToWriterFunction · 0.92
exportSQLWithContextFunction · 0.85
ErrorfMethod · 0.80
StringMethod · 0.65
GetPasswordMethod · 0.45

Tested by

no test coverage detected