Files
MyGoNavi/internal/app/export_options.go
autumn 4df1dac2c2 feat(data-grid): 支持查询结果导出 INSERT SQL
- 导出弹窗新增 INSERT SQL 格式并支持选中行、当前页和全部结果
- 单表查询自动映射真实表名与字段类型,连表结果使用带方言引号的 <table_name> 占位符
- 复用流式导出与批量 INSERT 生成逻辑,兼容 PostgreSQL 布尔字面量
- 补充前后端回归测试,覆盖单表、连表、别名和占位表场景
2026-07-16 10:58:00 +08:00

61 lines
2.4 KiB
Go

package app
import "strings"
const (
maxXLSXRowsPerSheet = 1048575
defaultXLSXRowsPerSheet = maxXLSXRowsPerSheet
)
type ExportFileOptions struct {
Format string `json:"format"`
XLSXMaxRowsPerSheet int `json:"xlsxMaxRowsPerSheet,omitempty"`
JobID string `json:"jobId,omitempty"`
TotalRowsHint int64 `json:"totalRowsHint,omitempty"`
TotalRowsKnown bool `json:"totalRowsKnown,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,
XLSXMaxRowsPerSheet: normalizeXLSXRowsPerSheet(options.XLSXMaxRowsPerSheet),
JobID: strings.TrimSpace(options.JobID),
TotalRowsHint: normalizeExportTotalRowsHint(options.TotalRowsHint, options.TotalRowsKnown),
TotalRowsKnown: options.TotalRowsKnown,
InsertSQLDialect: strings.ToLower(strings.TrimSpace(options.InsertSQLDialect)),
InsertSQLTargetTable: strings.TrimSpace(options.InsertSQLTargetTable),
InsertSQLColumnTypes: options.InsertSQLColumnTypes,
InsertSQLTargetColumns: options.InsertSQLTargetColumns,
InsertSQLAllowEmptyTargetTable: options.InsertSQLAllowEmptyTargetTable,
}
}
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
}