-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
113 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package export | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/turbot/pipe-fittings/v2/constants" | ||
"github.com/turbot/pipe-fittings/v2/querydisplay" | ||
"github.com/turbot/pipe-fittings/v2/queryresult" | ||
) | ||
|
||
type CsvExporter struct { | ||
ExporterBase | ||
} | ||
|
||
// Export processes the query result and writes CSV output to a file | ||
func (e *CsvExporter) Export(ctx context.Context, input ExportSourceData, filePath string) error { | ||
result, ok := input.(*queryresult.Result[*queryresult.QueryTimingMetadata]) | ||
if !ok { | ||
return fmt.Errorf("CsvExporter input must be a queryresult.Result") | ||
} | ||
|
||
// Generate csv output | ||
jsonString, _, _ := querydisplay.BuildCSV(ctx, result) | ||
|
||
// Write to file | ||
return Write(filePath, strings.NewReader(jsonString)) | ||
} | ||
|
||
func (e *CsvExporter) FileExtension() string { | ||
return constants.CsvExtension | ||
} | ||
|
||
func (e *CsvExporter) Name() string { | ||
return constants.OutputFormatCSV | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package export | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/turbot/pipe-fittings/v2/constants" | ||
"github.com/turbot/pipe-fittings/v2/querydisplay" | ||
"github.com/turbot/pipe-fittings/v2/queryresult" | ||
) | ||
|
||
type JsonExporter struct { | ||
ExporterBase | ||
} | ||
|
||
// Export processes the query result and writes JSON output to a file | ||
func (e *JsonExporter) Export(ctx context.Context, input ExportSourceData, filePath string) error { | ||
result, ok := input.(*queryresult.Result[*queryresult.QueryTimingMetadata]) | ||
if !ok { | ||
return fmt.Errorf("JsonExporter input must be a queryresult.Result") | ||
} | ||
|
||
// Generate JSON output | ||
jsonString, _, _ := querydisplay.BuildJSON(ctx, result) | ||
|
||
// Write to file | ||
return Write(filePath, strings.NewReader(jsonString)) | ||
} | ||
|
||
func (e *JsonExporter) FileExtension() string { | ||
return constants.JsonExtension | ||
} | ||
|
||
func (e *JsonExporter) Name() string { | ||
return constants.OutputFormatJSON | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters