1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-23 02:38:35 +00:00

Upgrade xorm to v1.1.0 (#15869)

This commit is contained in:
Lunny Xiao
2021-05-15 03:17:06 +08:00
committed by GitHub
parent e2f39c2b64
commit f6be429781
55 changed files with 1309 additions and 438 deletions

View File

@@ -8,6 +8,7 @@ import (
"fmt"
)
// IndexName returns index name
func IndexName(tableName, idxName string) string {
return fmt.Sprintf("IDX_%v_%v", tableName, idxName)
}

View File

@@ -8,6 +8,7 @@ import (
"reflect"
)
// ReflectValue returns value of a bean
func ReflectValue(bean interface{}) reflect.Value {
return reflect.Indirect(reflect.ValueOf(bean))
}

View File

@@ -8,6 +8,7 @@ import (
"strings"
)
// IsSubQuery returns true if it contains a sub query
func IsSubQuery(tbName string) bool {
const selStr = "select"
if len(tbName) <= len(selStr)+1 {

View File

@@ -8,10 +8,12 @@ import (
"strings"
)
// IndexNoCase index a string in a string with no care of capitalize
func IndexNoCase(s, sep string) int {
return strings.Index(strings.ToLower(s), strings.ToLower(sep))
}
// SplitNoCase split a string by a seperator with no care of capitalize
func SplitNoCase(s, sep string) []string {
idx := IndexNoCase(s, sep)
if idx < 0 {
@@ -20,6 +22,7 @@ func SplitNoCase(s, sep string) []string {
return strings.Split(s, s[idx:idx+len(sep)])
}
// SplitNNoCase split n by a seperator with no care of capitalize
func SplitNNoCase(s, sep string, n int) []string {
idx := IndexNoCase(s, sep)
if idx < 0 {

View File

@@ -9,6 +9,7 @@ import (
"time"
)
// Zeroable represents an interface which could know if it's a zero value
type Zeroable interface {
IsZero() bool
}
@@ -21,39 +22,39 @@ func IsZero(k interface{}) bool {
return true
}
switch k.(type) {
switch t := k.(type) {
case int:
return k.(int) == 0
return t == 0
case int8:
return k.(int8) == 0
return t == 0
case int16:
return k.(int16) == 0
return t == 0
case int32:
return k.(int32) == 0
return t == 0
case int64:
return k.(int64) == 0
return t == 0
case uint:
return k.(uint) == 0
return t == 0
case uint8:
return k.(uint8) == 0
return t == 0
case uint16:
return k.(uint16) == 0
return t == 0
case uint32:
return k.(uint32) == 0
return t == 0
case uint64:
return k.(uint64) == 0
return t == 0
case float32:
return k.(float32) == 0
return t == 0
case float64:
return k.(float64) == 0
return t == 0
case bool:
return k.(bool) == false
return !t
case string:
return k.(string) == ""
return t == ""
case *time.Time:
return k.(*time.Time) == nilTime || IsTimeZero(*k.(*time.Time))
return t == nilTime || IsTimeZero(*t)
case time.Time:
return IsTimeZero(k.(time.Time))
return IsTimeZero(t)
case Zeroable:
return k.(Zeroable) == nil || k.(Zeroable).IsZero()
case reflect.Value: // for go version less than 1.13 because reflect.Value has no method IsZero
@@ -65,6 +66,7 @@ func IsZero(k interface{}) bool {
var zeroType = reflect.TypeOf((*Zeroable)(nil)).Elem()
// IsValueZero returns true if the reflect Value is a zero
func IsValueZero(v reflect.Value) bool {
switch v.Kind() {
case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Slice:
@@ -88,6 +90,7 @@ func IsValueZero(v reflect.Value) bool {
return false
}
// IsStructZero returns true if the Value is a struct and all fields is zero
func IsStructZero(v reflect.Value) bool {
if !v.IsValid() || v.NumField() == 0 {
return true
@@ -120,6 +123,7 @@ func IsStructZero(v reflect.Value) bool {
return true
}
// IsArrayZero returns true is a slice of array is zero
func IsArrayZero(v reflect.Value) bool {
if !v.IsValid() || v.Len() == 0 {
return true
@@ -134,11 +138,13 @@ func IsArrayZero(v reflect.Value) bool {
return true
}
// represents all zero times
const (
ZeroTime0 = "0000-00-00 00:00:00"
ZeroTime1 = "0001-01-01 00:00:00"
)
// IsTimeZero return true if a time is zero
func IsTimeZero(t time.Time) bool {
return t.IsZero() || t.Format("2006-01-02 15:04:05") == ZeroTime0 ||
t.Format("2006-01-02 15:04:05") == ZeroTime1