diff options
Diffstat (limited to 'models/db')
-rw-r--r-- | models/db/convert.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/models/db/convert.go b/models/db/convert.go index bf9a74a9a4..039a681040 100644 --- a/models/db/convert.go +++ b/models/db/convert.go @@ -6,9 +6,12 @@ package db import ( "fmt" + "strconv" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "xorm.io/xorm" "xorm.io/xorm/schemas" ) @@ -39,3 +42,16 @@ func ConvertUtf8ToUtf8mb4() error { return nil } + +// Cell2Int64 converts a xorm.Cell type to int64, +// and handles possible irregular cases. +func Cell2Int64(val xorm.Cell) int64 { + switch (*val).(type) { + case []uint8: + log.Trace("Cell2Int64 ([]uint8): %v", *val) + + v, _ := strconv.ParseInt(string((*val).([]uint8)), 10, 64) + return v + } + return (*val).(int64) +} |