mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-08 23:53:30 +08:00
- 新增默认关闭的 DROP IF EXISTS SQL 导出选项和数据删除提示 - 覆盖数据库、Schema、单表、批量导出及工作台入口 - 按方言生成逆序 DROP 前导段并保持纯数据与旧 API 兼容 Fixes #514
94 lines
3.3 KiB
Go
94 lines
3.3 KiB
Go
package app
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
maxXLSXRowsPerSheet = 1048575
|
|
defaultXLSXRowsPerSheet = maxXLSXRowsPerSheet
|
|
)
|
|
|
|
type ExportFileOptions struct {
|
|
Format string `json:"format"`
|
|
Columns []string `json:"columns,omitempty"`
|
|
XLSXMaxRowsPerSheet int `json:"xlsxMaxRowsPerSheet,omitempty"`
|
|
JobID string `json:"jobId,omitempty"`
|
|
TotalRowsHint int64 `json:"totalRowsHint,omitempty"`
|
|
TotalRowsKnown bool `json:"totalRowsKnown,omitempty"`
|
|
IncludeDropIfExists bool `json:"includeDropIfExists,omitempty"`
|
|
InsertSQLDialect string `json:"insertSQLDialect,omitempty"`
|
|
InsertSQLTargetTable string `json:"insertSQLTargetTable,omitempty"`
|
|
InsertSQLColumnTypes map[string]string `json:"insertSQLColumnTypes,omitempty"`
|
|
InsertSQLTargetColumns map[string]string `json:"insertSQLTargetColumns,omitempty"`
|
|
InsertSQLAllowEmptyTargetTable bool `json:"insertSQLAllowEmptyTargetTable,omitempty"`
|
|
}
|
|
|
|
func normalizeExportFileOptions(format string, options ExportFileOptions) ExportFileOptions {
|
|
resolvedFormat := strings.ToLower(strings.TrimSpace(format))
|
|
if explicitFormat := strings.ToLower(strings.TrimSpace(options.Format)); explicitFormat != "" {
|
|
resolvedFormat = explicitFormat
|
|
}
|
|
return ExportFileOptions{
|
|
Format: resolvedFormat,
|
|
Columns: normalizeExportColumns(options.Columns),
|
|
XLSXMaxRowsPerSheet: normalizeXLSXRowsPerSheet(options.XLSXMaxRowsPerSheet),
|
|
JobID: strings.TrimSpace(options.JobID),
|
|
TotalRowsHint: normalizeExportTotalRowsHint(options.TotalRowsHint, options.TotalRowsKnown),
|
|
TotalRowsKnown: options.TotalRowsKnown,
|
|
IncludeDropIfExists: options.IncludeDropIfExists,
|
|
InsertSQLDialect: strings.ToLower(strings.TrimSpace(options.InsertSQLDialect)),
|
|
InsertSQLTargetTable: strings.TrimSpace(options.InsertSQLTargetTable),
|
|
InsertSQLColumnTypes: options.InsertSQLColumnTypes,
|
|
InsertSQLTargetColumns: options.InsertSQLTargetColumns,
|
|
InsertSQLAllowEmptyTargetTable: options.InsertSQLAllowEmptyTargetTable,
|
|
}
|
|
}
|
|
|
|
func normalizeExportColumns(columns []string) []string {
|
|
if columns == nil {
|
|
return nil
|
|
}
|
|
result := make([]string, 0, len(columns))
|
|
seen := make(map[string]struct{}, len(columns))
|
|
for _, column := range columns {
|
|
if strings.TrimSpace(column) == "" {
|
|
continue
|
|
}
|
|
if _, exists := seen[column]; exists {
|
|
continue
|
|
}
|
|
seen[column] = struct{}{}
|
|
result = append(result, column)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func validateExportColumnsSelection(options ExportFileOptions) error {
|
|
if options.Columns != nil && len(options.Columns) == 0 {
|
|
return errors.New("at least one export column must be selected")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func normalizeXLSXRowsPerSheet(value int) int {
|
|
if value <= 0 {
|
|
return defaultXLSXRowsPerSheet
|
|
}
|
|
if value > maxXLSXRowsPerSheet {
|
|
return maxXLSXRowsPerSheet
|
|
}
|
|
return value
|
|
}
|
|
|
|
func normalizeExportTotalRowsHint(value int64, known bool) int64 {
|
|
if !known {
|
|
return 0
|
|
}
|
|
if value < 0 {
|
|
return 0
|
|
}
|
|
return value
|
|
}
|