table

package
v0.0.0-...-201b726 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const COLOR_COLUMN_HEAD = "92D050"
View Source
const COLOR_JSON_HEAD_ITEM = "FABF8F"
View Source
const COLOR_TABLE_LOGICAL_NAME = "00B0F0"
View Source
const COLOR_TABLE_NAME = "92CDDC"
View Source
const CONNECT_STRING = "host=%s port=%d user=%s password=%s dbname=%s sslmode=disable"
View Source
const DB_MYSQL int = 4
View Source
const DB_ORACLE int = 1
View Source
const DB_POSTGRES int = 3
View Source
const DB_SQLITE int = 5
View Source
const DB_SQLSERVER int = 2
View Source
const DEFALT_SQL = " select * from " + PLACEHOLDER_TABLE + " "
View Source
const DEFAULT_TEMPLATE_FILE = "./table/template.xlsx"
View Source
const FLAG_CSV = "CSV"
View Source
const FLAG_SQL = "SQL"
View Source
const FONT_MINGCHAO = "MS 明朝"
View Source
const PLACEHOLDER_TABLE = "#TABLE#"
View Source
const STYLE_DATA string = `` /* 298-byte string literal not displayed */
View Source
const STYLE_HEAD string = `` /* 358-byte string literal not displayed */
View Source
const TABLE_IN_FILE string = "./table/table_input.yml"

Variables

View Source
var ALPHA = regexp.MustCompile("^[a-zA-Z]*")
View Source
var NUM = regexp.MustCompile("[0-9]*$")
View Source
var S_BOOL = []string{"bool", "boolean"}
View Source
var S_DATE_TIME = []string{"date", "time"}
View Source
var S_JSON = []string{"json", "jsonb"}
View Source
var S_NUMBER = []string{"integer", "number", "int"}
View Source
var S_TEXT = []string{"char", "varchar", "varchar2", "text"}
View Source
var S_YES = []string{"○", "〇", "Y"}

Functions

func CheckTableData

func CheckTableData(tableData TableData) ([]string, bool)

func Connect

func Connect() *sql.DB

func CovertTableDefineToMap

func CovertTableDefineToMap(tableDefineList []TableDefine) map[string]TableDefine

表定义一览转换成映射

键为表名,值为表定义

func CreateStyle

func CreateStyle(xlsx *excelize.File, styleTmpl string, cellFont string, backColor string) int

样式

func CreateTemplate

func CreateTemplate(tblIn *TableIn)

输出数据模板

func ExecuteQuery

func ExecuteQuery()

func ExportDataToXlsx

func ExportDataToXlsx(db *sql.DB,
	mTableDefine map[string]TableDefine,
	mSql map[string]string,
	tmplCfg *TemplateConfig,
	tmplFile string,
	testDataFile string)

从数据库表中获取数据,反映到Xlsx模板

sSql为空字符串的场合,抽取表中所有数据

func GetColRowInMergeCell

func GetColRowInMergeCell(mergeCell []excelize.MergeCell, colIdx int, row int) (colIdxMergeStart int, colIdxMergeEnd int)

在所有合并的单元格中找到目标单元格所在的合并单元格的行和列

func GetContinousCountInCol

func GetContinousCountInCol(xlsx *excelize.File, sheetName string, col string, rowStart int) int

获取指定列里连续有数据的行数

func GetContinousCountInRow

func GetContinousCountInRow(xlsx *excelize.File, sheetName string, col string, rowStart int) int

获取指定行里连续有数据的列数

func GetContinousValueInRow

func GetContinousValueInRow(xlsx *excelize.File, sheetName string, colIdxStart int, row int) []string

获取指定行里连续的数据

func GetCsvValue

func GetCsvValue(v string, t string, dbType int) string

func GetRange

func GetRange(c string, r int) string

单元格

func GetRowTableName

func GetRowTableName(xlsx *excelize.File, sheetName string, tableName string, tmplCfg *TemplateConfig) (int, error)

获取表名所在行(列为模板配置文件所在列)

查找表名在Sheet里的位置,作为相对偏移位置

func GetTableData

func GetTableData(testDataFile string, tableNames []string, tmplCfg *TemplateConfig) map[string]TableData

把Excel中的数据导入到数据库

func GetValueForJsonType

func GetValueForJsonType(v string, t string) string

func GetValueForType

func GetValueForType(v string, t string, flag string) string

func ToCsv

func ToCsv(tableData map[string]TableData, tblIn *TableIn) []string

func ToCsvSingle

func ToCsvSingle(tableData TableData, tblIn *TableIn) []string

func ToSqlInsert

func ToSqlInsert(tableDatas map[string]TableData, tableDefine map[string]TableDefine) []string

func ToSqlInsertSingle

func ToSqlInsertSingle(tableData TableData, tableDefine TableDefine) []string

Types

type ColumnInfo

type ColumnInfo struct {
	No                string
	ColumnLogicalName string
	ColumnName        string
	Type              string
	JsonItem          []JsonItemInfo
	Length            int
	LengthEx          int
	PK                bool
	NotNull           bool
	Default           string
	Description       string
	Remark            string
	IsJson            bool
	Data              string
}

type JsonItemInfo

type JsonItemInfo struct {
	ItemNo          string
	ItemLogicalName string
	ItemName        string
	ItemType        string
	ItemLength      int
	ItemLengthEx    int
}

JSON(JSONB)项目

type TableData

type TableData struct {
	TableLogicalName string
	TableName        string
	DataList         [][]ColumnInfo
	ExInfo           string
}

表数据

func GetSingleTableData

func GetSingleTableData(testDataFile string, tableName string, tmplCfg *TemplateConfig) TableData

把Excel中的数据导入到数据库

type TableDefine

type TableDefine struct {
	TableLogicalName string
	TableName        string
	Column           []ColumnInfo
	ExInfo           string
	HasJsonColumn    bool
}

func GetTableDefine

func GetTableDefine(tblIn *TableIn) ([]TableDefine, error)

获取表定义

type TableDesineConfig

type TableDesineConfig struct {
	SheetNameTableDefine []string `yaml:"sheetNameTableDefine"`
	ColNo                string   `yaml:"colNo"`
	ColColumnLogicalName string   `yaml:"colColumnLogicalName"`
	ColColumnName        string   `yaml:"colColumnName"`
	ColPK                string   `yaml:"colPK"`
	ColType              string   `yaml:"colType"`
	ColLength            string   `yaml:"colLength"`
	ColItemLogicalName   string   `yaml:"colItemLogicalName"`
	ColItemName          string   `yaml:"colItemName"`
	ColItemType          string   `yaml:"colItemType"`
	ColItemLength        string   `yaml:"colItemLength"`
	ColNotNull           string   `yaml:"colNotNull"`
	ColDefault           string   `yaml:"colDefault"`
	ColDescription       string   `yaml:"colDescription"`
	ColRemark            string   `yaml:"colRemark"`
	StartRow             int      `yaml:"startRow"`
	LastRow              int
}

表定义配置

type TableIn

type TableIn struct {
	// 表设计文件(XLSX)
	TableDesineFile []string `yaml:"tableDesineFile"`
	// 表设计 配置文件
	TableDesineConfigFile string `yaml:"tableDesineConfigFile"`

	// 表定义文件(JSON)
	TableDefineFile string `yaml:"tableDefineFile"`

	// 数据模板 配置文件
	TemplateConfigFile string `yaml:"templateConfigFile"`
	// 数据模板输出对象表
	TemplateOutTargetTable []string `yaml:"templateOutTargetTable"`
	// 数据模板输出文件
	TemplateFile string `yaml:"templateFile"`

	// 测试数据文件
	TestDataFile string `yaml:"testDataFile"`
	// 数据库类型
	DatabaseType int `yaml:"databaseType"`
	// CSV目录
	CsvPath string `yaml:"csvPath"`
}

处理输入

var GlobalTableIn TableIn

type TemplateConfig

type TemplateConfig struct {
	IsMultiSheet     bool   `yaml:"isMultiSheet"`
	SingleSheetName  string `yaml:"singleSheetName"`
	CountDefaultdata int    `yaml:"countDefaultdata"`
	CountSeparateRow int    `yaml:"countSeparateRow"`

	ColTableLogicalName string `yaml:"colTableLogicalName"`
	ColTableName        string `yaml:"colTableName"`
	RowTableLogicalName int    `yaml:"rowTableLogicalName"`
	RowTableName        int    `yaml:"rowTableName"`

	RowColumnLogicalName int `yaml:"rowColumnLogicalName"`
	RowColumnName        int `yaml:"rowColumnName"`
	RowType              int `yaml:"rowType"`
	RowLength            int `yaml:"rowLength"`

	RowJsonColumnLogicalName int `yaml:"rowJsonColumnLogicalName"`
	RowJsonColumnName        int `yaml:"rowJsonColumnName"`
	RowJsonType              int `yaml:"rowJsonType"`

	RowItemLogicalName int `yaml:"rowItemLogicalName"`
	RowItemName        int `yaml:"rowItemName"`
	RowItemType        int `yaml:"rowItemType"`
	RowItemLength      int `yaml:"rowItemLength"`

	StartColData string `yaml:"startColData"`

	CellFont                  string `yaml:"cellFont"`
	TableLogicalNameBackColor string `yaml:"tableLogicalNameBackColor"`
	TableNameBackColor        string `yaml:"tableNameBackColor"`
	ColumnHeadBackColor       string `yaml:"columnHeadBackColor"`
	JsonHeadItemBackColor     string `yaml:"jsonHeadItemBackColor"`
}

模板定义配置

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL