Compare commits

...

2 Commits

Author SHA1 Message Date
fdb66f92f5 Add export path picker 2024-03-05 21:41:51 +05:00
7c6ca4c81b Add buffered disk writes 2024-03-05 21:41:27 +05:00
4 changed files with 44 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"bufio"
"encoding/csv"
"fmt"
"os"
@ -22,12 +23,14 @@ func (c *CsvExporter) Convert(filePath string, rows chan []any) error {
return err
}
buf := bufio.NewWriterSize(f, 4*1024*1024)
enc, err := c.Encoding.Encoder()
if err != nil {
return err
}
w := csv.NewWriter(enc.Writer(f))
w := csv.NewWriter(enc.Writer(buf))
w.Comma = ';'
rowNum := 0
@ -51,6 +54,12 @@ func (c *CsvExporter) Convert(filePath string, rows chan []any) error {
return err
}
err = buf.Flush()
if err != nil {
f.Close()
return err
}
err = f.Close()
if err != nil {
return err

View File

@ -2,6 +2,7 @@ package main
import (
"archive/zip"
"bufio"
"encoding/csv"
"os"
"path/filepath"
@ -22,7 +23,9 @@ func (c *CsvZipExporter) Convert(filePath string, rows chan []any) error {
return err
}
z := zip.NewWriter(f)
buf := bufio.NewWriterSize(f, 4*1024*1024)
z := zip.NewWriter(buf)
zw, err := z.Create(filepath.Base(filePath) + ".csv")
if err != nil {
@ -65,6 +68,12 @@ func (c *CsvZipExporter) Convert(filePath string, rows chan []any) error {
return err
}
err = buf.Flush()
if err != nil {
f.Close()
return err
}
err = f.Close()
if err != nil {
return err

View File

@ -25,6 +25,7 @@ type Job struct {
scriptFilePath string
exportFileFormat ExportFormat
encoding Encoding
exportPath string
config Config
@ -72,7 +73,7 @@ func (j *Job) export(inputRows chan Row) error {
return err
}
fileName := filepath.Base(j.scriptFilePath)
fileName := filepath.Join(j.exportPath, filepath.Base(j.scriptFilePath))
fileName = strings.TrimSuffix(fileName, filepath.Ext(fileName))
outputRows := make(chan []any)

View File

@ -33,6 +33,8 @@ type TMainForm struct {
ExportFormatComboBox *vcl.TComboBox
CharsetLabel *vcl.TLabel
CharsetComboBox *vcl.TComboBox
ExportPathLabel *vcl.TLabel
ExportPathPicker *vcl.TDirectoryEdit
BottomPanel *vcl.TPanel
LaunchButton *vcl.TBitBtn
@ -157,6 +159,24 @@ func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
f.CharsetComboBox.SetTop(700)
f.CharsetComboBox.SetStyle(types.CsDropDownList)
f.ExportPathLabel = vcl.NewLabel(f)
f.ExportPathLabel.SetParent(f.GroupBox)
f.ExportPathLabel.SetCaption("Путь сохранения результата")
f.ExportPathLabel.SetAlign(types.AlTop)
f.ExportPathLabel.SetTop(800)
f.ExportPathLabel.BorderSpacing().SetTop(8)
f.ExportPathLabel.BorderSpacing().SetLeft(8)
f.ExportPathLabel.BorderSpacing().SetRight(8)
f.ExportPathPicker = vcl.NewDirectoryEdit(f)
f.ExportPathPicker.SetParent(f.GroupBox)
f.ExportPathPicker.SetAlign(types.AlTop)
f.ExportPathPicker.BorderSpacing().SetTop(2)
f.ExportPathPicker.BorderSpacing().SetLeft(8)
f.ExportPathPicker.BorderSpacing().SetRight(8)
f.ExportPathPicker.SetTop(900)
f.ExportPathPicker.SetFlat(true)
f.BottomPanel = vcl.NewPanel(f)
f.BottomPanel.SetParent(f.TabSheet1)
f.BottomPanel.SetAlign(types.AlBottom)
@ -258,7 +278,8 @@ func (f *TMainForm) OnLaunchButtonClick(sender vcl.IObject) {
configFilePath: filepath.Join(CONFIG_FILES_DIR, f.ConfigComboBox.Text()) + "." + CONFIG_FILE_EXT,
scriptFilePath: filepath.Join(SQL_FILES_DIR, f.SqlFileComboBox.Text()) + "." + SQL_FILE_EXT,
exportFileFormat: ExportFormat(f.ExportFormatComboBox.Text()),
encoding: Encoding(f.CharsetComboBox.Text())}
encoding: Encoding(f.CharsetComboBox.Text()),
exportPath: f.ExportPathPicker.Directory()}
err := job.init()
if err != nil {