Merge pull request #214 from matchstalk/table/dev

分表基础算法
This commit is contained in:
wenjianzhang authored and GitHub committed 2020-08-26 22:32:11 +08:00
commit 93cfe443d6
2 files changed
+25 -1

No files matched your search

+1 -1
View File
@@ -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)
}
+24
View File
@@ -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))
}