diff --git a/models/tools/dbcolumns.go b/models/tools/dbcolumns.go index de4f509b..3040eb08 100644 --- a/models/tools/dbcolumns.go +++ b/models/tools/dbcolumns.go @@ -59,7 +59,7 @@ func (e *DBColumns) GetList() ([]DBColumns, error) { table = orm.Eloquent.Select("*").Table("information_schema.columns") table = table.Where("table_schema= ? ", config2.GenConfig.DBName) - table = table.Where("TABLE_NAME = ?", e.TableName) + table = table.Where("TABLE_NAME = ?", e.TableName).Order("ORDINAL_POSITION asc") } else { tools.Assert(true, "目前只支持mysql数据库", 500) } diff --git a/pkg/table/analysis.go b/pkg/table/analysis.go new file mode 100644 index 00000000..2813e628 --- /dev/null +++ b/pkg/table/analysis.go @@ -0,0 +1,24 @@ +package table + +import ( + "hash/crc32" + "strconv" +) + +// Crc32Hash 用于32张分表 +func Crc32Hash(src string) string { + sum := crc32.ChecksumIEEE([]byte(src)) % 32 + return strconv.Itoa(int(sum)) +} + +// Crc16Hash 用于16张分表 +func Crc16Hash(src string) string { + sum := crc32.ChecksumIEEE([]byte(src)) % 16 + return strconv.Itoa(int(sum)) +} + +// Crc8Hash 用于8张分表 +func Crc8Hash(src string) string { + sum := crc32.ChecksumIEEE([]byte(src)) % 8 + return strconv.Itoa(int(sum)) +}