Go 1.27.1, and the code it can say more simply

The module declares go 1.27.1. go fix applied the modernizers; omitzero
is not applied, since it changes what the JSON says.

Co-authored-by: Hanzo Dev <[email protected]>
This commit is contained in:
2026-09-16 19:56:19 -07:00
co-authored by Hanzo Dev
parent 26f6663bfc
commit d54045b5f0
54 changed files with 162 additions and 203 deletions
+2 -2
View File
@@ -340,7 +340,7 @@ func AssignValue(dv reflect.Value, src any) error {
}
switch dv.Kind() {
case reflect.Ptr:
case reflect.Pointer:
if dv.IsNil() {
dv.Set(reflect.New(dv.Type().Elem()))
}
@@ -387,7 +387,7 @@ func AssignValue(dv reflect.Value, src any) error {
if data == nil {
return nil
}
if dv.Kind() != reflect.Ptr {
if dv.Kind() != reflect.Pointer {
dv = dv.Addr()
}
return json.DefaultJSONHandler.Unmarshal(data, dv.Interface())
+2 -2
View File
@@ -24,7 +24,7 @@ var DefaultCacheSize = 200
// MapToSlice map query and struct as sql and args
func MapToSlice(query string, mp any) (string, []any, error) {
vv := reflect.ValueOf(mp)
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Map {
if vv.Kind() != reflect.Pointer || vv.Elem().Kind() != reflect.Map {
return "", []any{}, ErrNoMapPointer
}
@@ -46,7 +46,7 @@ func MapToSlice(query string, mp any) (string, []any, error) {
// StructToSlice converts a query and struct as sql and args
func StructToSlice(query string, st any) (string, []any, error) {
vv := reflect.ValueOf(st)
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Struct {
if vv.Kind() != reflect.Pointer || vv.Elem().Kind() != reflect.Struct {
return "", []any{}, ErrNoStructPointer
}
+2 -2
View File
@@ -105,8 +105,8 @@ func TestNeedLogSQL(t *testing.T) {
func TestReflectNew(t *testing.T) {
db := &DB{reflectCache: make(map[reflect.Type]*cacheStruct)}
val := db.reflectNew(reflect.TypeOf(int(0)))
if val.Kind() != reflect.Ptr || val.Elem().Int() != 0 {
val := db.reflectNew(reflect.TypeFor[int]())
if val.Kind() != reflect.Pointer || val.Elem().Int() != 0 {
t.Fatalf("unexpected reflect value: %#v", val)
}
}
+6 -6
View File
@@ -70,7 +70,7 @@ func BenchmarkOriQuery(b *testing.B) {
b.Error(err)
}
for i := 0; i < 50; i++ {
for range 50 {
_, err = db.Exec("insert into user (`name`, title, age, alias, nick_name, created) values (?,?,?,?,?, ?)",
"xlw", "tester", 1.2, "lunny", "lunny xiao", time.Now())
if err != nil {
@@ -125,7 +125,7 @@ func BenchmarkStructQuery(b *testing.B) {
b.Error(err)
}
for i := 0; i < 50; i++ {
for range 50 {
_, err = db.Exec("insert into user (`name`, title, age, alias, nick_name, created) values (?,?,?,?,?, ?)",
"xlw", "tester", 1.2, "lunny", "lunny xiao", time.Now())
if err != nil {
@@ -170,7 +170,7 @@ func BenchmarkStruct2Query(b *testing.B) {
b.Error(err)
}
for i := 0; i < 50; i++ {
for range 50 {
_, err = db.Exec("insert into user (`name`, title, age, alias, nick_name, created) values (?,?,?,?,?,?)",
"xlw", "tester", 1.2, "lunny", "lunny xiao", time.Now())
if err != nil {
@@ -216,7 +216,7 @@ func BenchmarkSliceInterfaceQuery(b *testing.B) {
b.Error(err)
}
for i := 0; i < 50; i++ {
for range 50 {
_, err = db.Exec("insert into user (`name`, title, age, alias, nick_name,created) values (?,?,?,?,?,?)",
"xlw", "tester", 1.2, "lunny", "lunny xiao", time.Now())
if err != nil {
@@ -325,7 +325,7 @@ func BenchmarkSliceStringQuery(b *testing.B) {
b.Error(err)
}
for i := 0; i < 50; i++ {
for range 50 {
_, err = db.Exec("insert into user (name, title, age, alias, nick_name, created) values (?,?,?,?,?,?)",
"xlw", "tester", 1.2, "lunny", "lunny xiao", time.Now())
if err != nil {
@@ -376,7 +376,7 @@ func BenchmarkMapInterfaceQuery(b *testing.B) {
b.Error(err)
}
for i := 0; i < 50; i++ {
for range 50 {
_, err = db.Exec("insert into user (name, title, age, alias, nick_name,created) values (?,?,?,?,?,?)",
"xlw", "tester", 1.2, "lunny", "lunny xiao", time.Now())
if err != nil {
+7 -7
View File
@@ -45,7 +45,7 @@ func (rs *Rows) ScanStructByIndex(dest ...any) error {
vvvs := make([]reflect.Value, len(dest))
for i, s := range dest {
vv := reflect.ValueOf(s)
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Struct {
if vv.Kind() != reflect.Pointer || vv.Elem().Kind() != reflect.Struct {
return errors.New("dest should be a struct's pointer")
}
@@ -60,8 +60,8 @@ func (rs *Rows) ScanStructByIndex(dest ...any) error {
i := 0
for _, vvv := range vvvs {
for j := 0; j < vvv.NumField(); j++ {
newDest[i] = vvv.Field(j).Addr().Interface()
for _, field := range vvv.Fields() {
newDest[i] = field.Addr().Interface()
i++
}
}
@@ -99,7 +99,7 @@ func fieldByName(v reflect.Value, name string) reflect.Value {
// ScanStructByName scan data to a struct's pointer according field name
func (rs *Rows) ScanStructByName(dest any) error {
vv := reflect.ValueOf(dest)
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Struct {
if vv.Kind() != reflect.Pointer || vv.Elem().Kind() != reflect.Struct {
return errors.New("dest should be a struct's pointer")
}
@@ -125,7 +125,7 @@ func (rs *Rows) ScanStructByName(dest any) error {
// ScanSlice scan data to a slice's pointer, slice's length should equal to columns' number
func (rs *Rows) ScanSlice(dest any) error {
vv := reflect.ValueOf(dest)
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Slice {
if vv.Kind() != reflect.Pointer || vv.Elem().Kind() != reflect.Slice {
return errors.New("dest should be a slice's pointer")
}
@@ -137,7 +137,7 @@ func (rs *Rows) ScanSlice(dest any) error {
newDest := make([]any, len(cols))
for j := 0; j < len(cols); j++ {
for j := range cols {
if j >= vvv.Len() {
newDest[j] = reflect.New(vvv.Type().Elem()).Interface()
} else {
@@ -160,7 +160,7 @@ func (rs *Rows) ScanSlice(dest any) error {
// ScanMap scan data to a map's pointer
func (rs *Rows) ScanMap(dest any) error {
vv := reflect.ValueOf(dest)
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Map {
if vv.Kind() != reflect.Pointer || vv.Elem().Kind() != reflect.Map {
return errors.New("dest should be a map's pointer")
}
+6 -6
View File
@@ -51,7 +51,7 @@ func (db *DB) Prepare(query string) (*Stmt, error) {
// ExecMapContext execute with map
func (s *Stmt) ExecMapContext(ctx context.Context, mp any) (sql.Result, error) {
vv := reflect.ValueOf(mp)
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Map {
if vv.Kind() != reflect.Pointer || vv.Elem().Kind() != reflect.Map {
return nil, errors.New("mp should be a map's pointer")
}
@@ -70,7 +70,7 @@ func (s *Stmt) ExecMap(mp any) (sql.Result, error) {
// ExecStructContext executes with struct
func (s *Stmt) ExecStructContext(ctx context.Context, st any) (sql.Result, error) {
vv := reflect.ValueOf(st)
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Struct {
if vv.Kind() != reflect.Pointer || vv.Elem().Kind() != reflect.Struct {
return nil, errors.New("mp should be a map's pointer")
}
@@ -124,7 +124,7 @@ func (s *Stmt) Query(args ...any) (*Rows, error) {
// QueryMapContext query with map
func (s *Stmt) QueryMapContext(ctx context.Context, mp any) (*Rows, error) {
vv := reflect.ValueOf(mp)
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Map {
if vv.Kind() != reflect.Pointer || vv.Elem().Kind() != reflect.Map {
return nil, errors.New("mp should be a map's pointer")
}
@@ -144,7 +144,7 @@ func (s *Stmt) QueryMap(mp any) (*Rows, error) {
// QueryStructContext query with struct
func (s *Stmt) QueryStructContext(ctx context.Context, st any) (*Rows, error) {
vv := reflect.ValueOf(st)
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Struct {
if vv.Kind() != reflect.Pointer || vv.Elem().Kind() != reflect.Struct {
return nil, errors.New("mp should be a map's pointer")
}
@@ -175,7 +175,7 @@ func (s *Stmt) QueryRow(args ...any) *Row {
// QueryRowMapContext query row with map
func (s *Stmt) QueryRowMapContext(ctx context.Context, mp any) *Row {
vv := reflect.ValueOf(mp)
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Map {
if vv.Kind() != reflect.Pointer || vv.Elem().Kind() != reflect.Map {
return &Row{nil, errors.New("mp should be a map's pointer")}
}
@@ -195,7 +195,7 @@ func (s *Stmt) QueryRowMap(mp any) *Row {
// QueryRowStructContext query row with struct
func (s *Stmt) QueryRowStructContext(ctx context.Context, st any) *Row {
vv := reflect.ValueOf(st)
if vv.Kind() != reflect.Ptr || vv.Elem().Kind() != reflect.Struct {
if vv.Kind() != reflect.Pointer || vv.Elem().Kind() != reflect.Struct {
return &Row{nil, errors.New("st should be a struct's pointer")}
}
+2 -6
View File
@@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"regexp"
"slices"
"strconv"
"strings"
@@ -1074,12 +1075,7 @@ func (db *gbase8s) primaryKeys(queryer core.Queryer, ctx context.Context, tableN
}
func inSlice(target string, list []string) bool {
for _, item := range list {
if item == target {
return true
}
}
return false
return slices.Contains(list, target)
}
// Replace all consecutive whitespace characters with a single space using regex
+1 -2
View File
@@ -703,8 +703,7 @@ func (p *odbcDriver) Parse(driverName, dataSourceName string) (*URI, error) {
}
dbName = u.Query().Get("database")
} else {
kv := strings.Split(dataSourceName, ";")
for _, c := range kv {
for c := range strings.SplitSeq(dataSourceName, ";") {
vv := strings.Split(strings.TrimSpace(c), "=")
if len(vv) == 2 {
if strings.EqualFold(vv[0], "database") {
+1 -2
View File
@@ -745,8 +745,7 @@ func (p *mysqlDriver) Parse(driverName, dataSourceName string) (*URI, error) {
uri.DBName = match
case "params":
if len(match) > 0 {
kvs := strings.Split(match, "&")
for _, kv := range kvs {
for kv := range strings.SplitSeq(match, "&") {
splits := strings.Split(kv, "=")
if len(splits) == 2 {
if splits[0] == "charset" {
+1 -1
View File
@@ -1278,7 +1278,7 @@ func getIndexColName(indexdef string) []string {
var colNames []string
cs := strings.Split(indexdef, "(")
for _, v := range strings.Split(strings.Split(cs[1], ")")[0], ",") {
for v := range strings.SplitSeq(strings.Split(cs[1], ")")[0], ",") {
colNames = append(colNames, strings.Split(strings.TrimLeft(v, " "), " ")[0])
}
+1 -2
View File
@@ -417,8 +417,7 @@ func (db *sqlite3) GetColumns(queryer core.Queryer, ctx context.Context, tableNa
if strings.HasPrefix(strings.TrimSpace(colStr), "PRIMARY KEY") {
parts := strings.Split(strings.TrimSpace(colStr), "(")
if len(parts) == 2 {
pkCols := strings.Split(strings.TrimRight(strings.TrimSpace(parts[1]), ")"), ",")
for _, pk := range pkCols {
for pk := range strings.SplitSeq(strings.TrimRight(strings.TrimSpace(parts[1]), ")"), ",") {
if col, ok := cols[strings.Trim(strings.TrimSpace(pk), "`")]; ok {
col.IsPrimaryKey = true
}
+1 -1
View File
@@ -53,7 +53,7 @@ func NewEngineGroup(args1, args2 any, policies ...GroupPolicy) (*EngineGroup, er
slaves, ok4 := args2.([]*Engine)
if ok3 && ok4 {
master.engineGroup = &eg
for i := 0; i < len(slaves); i++ {
for i := range slaves {
slaves[i].engineGroup = &eg
}
eg.Engine = master
+3 -3
View File
@@ -34,7 +34,7 @@ func RandomPolicy() GroupPolicyHandler {
// WeightRandomPolicy implmentes randomly chose the slave of slaves
func WeightRandomPolicy(weights []int) GroupPolicyHandler {
rands := make([]int, 0, len(weights))
for i := 0; i < len(weights); i++ {
for i := range weights {
for n := 0; n < weights[i]; n++ {
rands = append(rands, i)
}
@@ -72,7 +72,7 @@ func RoundRobinPolicy() GroupPolicyHandler {
// WeightRoundRobinPolicy returns a group policy handler
func WeightRoundRobinPolicy(weights []int) GroupPolicyHandler {
rands := make([]int, 0, len(weights))
for i := 0; i < len(weights); i++ {
for i := range weights {
for n := 0; n < weights[i]; n++ {
rands = append(rands, i)
}
@@ -103,7 +103,7 @@ func LeastConnPolicy() GroupPolicyHandler {
slaves := g.Slaves()
connections := 0
idx := 0
for i := 0; i < len(slaves); i++ {
for i := range slaves {
openConnections := slaves[i].DB().Stats().OpenConnections
if i == 0 {
connections = openConnections
+1 -1
View File
@@ -1,6 +1,6 @@
module github.com/hanzoai/xorm
go 1.26.8
go 1.27.1
require (
gitee.com/travelliu/dm v1.8.11192
@@ -6,6 +6,7 @@ package statements
import (
"reflect"
"slices"
"strings"
"testing"
"time"
@@ -190,10 +191,5 @@ func containsCol(cols []string, name string) bool {
}
func containsArg(args []any, target any) bool {
for _, arg := range args {
if arg == target {
return true
}
}
return false
return slices.Contains(args, target)
}
+6 -6
View File
@@ -13,11 +13,11 @@ import (
)
var (
ptrPkType = reflect.TypeOf(&schemas.PK{})
pkType = reflect.TypeOf(schemas.PK{})
stringType = reflect.TypeOf("")
intType = reflect.TypeOf(int64(0))
uintType = reflect.TypeOf(uint64(0))
ptrPkType = reflect.TypeFor[*schemas.PK]()
pkType = reflect.TypeFor[schemas.PK]()
stringType = reflect.TypeFor[string]()
intType = reflect.TypeFor[int64]()
uintType = reflect.TypeFor[uint64]()
)
// ErrIDConditionWithNoTable represents an error there is no reference table with an ID condition
@@ -59,7 +59,7 @@ func (statement *Statement) ID(id any) *Statement {
if idType.ConvertibleTo(pkType) {
statement.idParam = idValue.Convert(pkType).Interface().(schemas.PK)
}
case reflect.Ptr:
case reflect.Pointer:
if idType.ConvertibleTo(ptrPkType) {
statement.idParam = idValue.Convert(ptrPkType).Elem().Interface().(schemas.PK)
}
+1 -1
View File
@@ -315,7 +315,7 @@ func (statement *Statement) GenExistSQL(bean ...any) (string, []any, error) {
if len(bean) > 0 {
b = bean[0]
beanValue := reflect.ValueOf(bean[0])
if beanValue.Kind() != reflect.Ptr {
if beanValue.Kind() != reflect.Pointer {
return "", nil, errors.New("needs a pointer")
}
+1 -2
View File
@@ -22,8 +22,7 @@ func col2NewCols(columns ...string) []string {
for _, col := range columns {
col = strings.ReplaceAll(col, "`", "")
col = strings.ReplaceAll(col, `"`, "")
ccols := strings.Split(col, ",")
for _, c := range ccols {
for c := range strings.SplitSeq(col, ",") {
newColumns = append(newColumns, strings.TrimSpace(c))
}
}
+3 -3
View File
@@ -376,7 +376,7 @@ func (statement *Statement) GenDelIndexSQL() []string {
func (statement *Statement) asDBCond(fieldValue reflect.Value, fieldType reflect.Type, col *schemas.Column, allUseBool, requiredField bool) (any, bool, error) {
switch fieldType.Kind() {
case reflect.Ptr:
case reflect.Pointer:
if fieldValue.IsNil() {
return nil, true, nil
}
@@ -580,7 +580,7 @@ func (statement *Statement) buildConds2(table *schemas.Table, bean any,
}
fieldType := reflect.TypeOf(fieldValue.Interface())
if fieldType.Kind() == reflect.Ptr {
if fieldType.Kind() == reflect.Pointer {
if fieldValue.IsNil() {
if includeNil {
conds = append(conds, builder.Eq{colName: nil})
@@ -667,7 +667,7 @@ func (statement *Statement) formatTimeArg(arg any) (any, bool) {
if !rv.IsValid() {
return nil, false
}
if rv.Kind() == reflect.Ptr {
if rv.Kind() == reflect.Pointer {
if rv.IsNil() {
if rv.Type().Elem().ConvertibleTo(schemas.TimeType) {
return nil, true
+1 -1
View File
@@ -154,7 +154,7 @@ func (statement *Statement) BuildUpdates(tableValue reflect.Value,
goto APPEND
}
if fieldType.Kind() == reflect.Ptr {
if fieldType.Kind() == reflect.Pointer {
if fieldValue.IsNil() {
if includeNil {
args = append(args, nil)
+4 -4
View File
@@ -19,8 +19,8 @@ import (
)
var (
nullFloatType = reflect.TypeOf(sql.NullFloat64{})
bigFloatType = reflect.TypeOf(big.Float{})
nullFloatType = reflect.TypeFor[sql.NullFloat64]()
bigFloatType = reflect.TypeFor[big.Float]()
)
// Value2Interface convert a field value of a struct to interface for putting into database
@@ -44,7 +44,7 @@ func (statement *Statement) Value2Interface(col *schemas.Column, fieldValue refl
}
}
isNil := fieldValue.Kind() == reflect.Ptr && fieldValue.IsNil()
isNil := fieldValue.Kind() == reflect.Pointer && fieldValue.IsNil()
if !isNil {
if fieldConvert, ok := fieldValue.Interface().(convert.Conversion); ok {
data, err := fieldConvert.ToDB()
@@ -66,7 +66,7 @@ func (statement *Statement) Value2Interface(col *schemas.Column, fieldValue refl
fieldType := fieldValue.Type()
k := fieldType.Kind()
if k == reflect.Ptr {
if k == reflect.Pointer {
if fieldValue.IsNil() {
return nil, nil
}
+6 -6
View File
@@ -10,24 +10,24 @@ import (
)
func TestNewCreatesValues(t *testing.T) {
sliceType := reflect.TypeOf([]string{})
sliceType := reflect.TypeFor[[]string]()
sliceValue := New(sliceType, 2, 3)
if sliceValue.Kind() != reflect.Ptr || sliceValue.Elem().Len() != 2 {
if sliceValue.Kind() != reflect.Pointer || sliceValue.Elem().Len() != 2 {
t.Fatalf("unexpected slice value: %#v", sliceValue)
}
if sliceValue.Elem().Cap() != 3 {
t.Fatalf("expected slice cap 3, got %d", sliceValue.Elem().Cap())
}
mapType := reflect.TypeOf(map[string]int{})
mapType := reflect.TypeFor[map[string]int]()
mapValue := New(mapType, 0, 4)
if mapValue.Kind() != reflect.Ptr || mapValue.Elem().Len() != 0 {
if mapValue.Kind() != reflect.Pointer || mapValue.Elem().Len() != 0 {
t.Fatalf("unexpected map value: %#v", mapValue)
}
intType := reflect.TypeOf(0)
intType := reflect.TypeFor[int]()
intValue := New(intType, 0, 0)
if intValue.Kind() != reflect.Ptr || intValue.Elem().Int() != 0 {
if intValue.Kind() != reflect.Pointer || intValue.Elem().Int() != 0 {
t.Fatalf("unexpected int value: %#v", intValue)
}
}
+1 -1
View File
@@ -13,7 +13,7 @@ func SliceEq(left, right []string) bool {
}
sort.Strings(left)
sort.Strings(right)
for i := 0; i < len(left); i++ {
for i := range left {
if left[i] != right[i] {
return false
}
+4 -5
View File
@@ -65,7 +65,7 @@ func IsZero(k any) bool {
return IsValueZero(reflect.ValueOf(k))
}
var zeroType = reflect.TypeOf((*Zeroable)(nil)).Elem()
var zeroType = reflect.TypeFor[Zeroable]()
// IsValueZero returns true if the reflect Value is a zero
func IsValueZero(v reflect.Value) bool {
@@ -78,7 +78,7 @@ func IsValueZero(v reflect.Value) bool {
return v.Uint() == 0
case reflect.String:
return v.Len() == 0
case reflect.Ptr:
case reflect.Pointer:
if v.IsNil() {
return true
}
@@ -106,10 +106,9 @@ func IsStructZero(v reflect.Value) bool {
}
}
for i := 0; i < v.NumField(); i++ {
field := v.Field(i)
for _, field := range v.Fields() {
switch field.Kind() {
case reflect.Ptr:
case reflect.Pointer:
field = field.Elem()
if field.Kind() == reflect.Struct {
if !IsStructZero(field) {
+3 -3
View File
@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"reflect"
"slices"
"github.com/hanzoai/xorm"
"github.com/hanzoai/xorm/schemas"
@@ -121,8 +122,7 @@ func (m *Migrate) RollbackLast() error {
}
func (m *Migrate) getLastRunnedMigration() (*Migration, error) {
for i := len(m.migrations) - 1; i >= 0; i-- {
migration := m.migrations[i]
for _, migration := range slices.Backward(m.migrations) {
run, err := m.migrationDidRun(migration)
if err != nil {
return nil, err
@@ -202,7 +202,7 @@ func (m *Migrate) createMigrationTableIfNotExists() error {
}, 255, 0, false)
idCol.IsPrimaryKey = true
table := schemas.NewTable(m.options.TableName, reflect.TypeOf(new(schemas.Table)))
table := schemas.NewTable(m.options.TableName, reflect.TypeFor[*schemas.Table]())
table.AddColumn(idCol)
sql, _, err := m.db.Dialect().CreateTableSQL(context.Background(), m.db.DB(), table, m.options.TableName)
+1 -3
View File
@@ -185,9 +185,7 @@ func (mapper GonicMapper) Table2Obj(name string) string {
newstr := make([]rune, 0)
name = strings.ToLower(name)
parts := strings.Split(name, "_")
for _, p := range parts {
for p := range strings.SplitSeq(name, "_") {
_, isInitialism := mapper[strings.ToUpper(p)]
for i, r := range p {
if i == 0 || isInitialism {
+4 -4
View File
@@ -19,8 +19,8 @@ type TableComment interface {
}
var (
tpTableName = reflect.TypeOf((*TableName)(nil)).Elem()
tpTableComment = reflect.TypeOf((*TableComment)(nil)).Elem()
tpTableName = reflect.TypeFor[TableName]()
tpTableComment = reflect.TypeFor[TableComment]()
tvCache sync.Map
tcCache sync.Map
)
@@ -32,7 +32,7 @@ func GetTableName(mapper Mapper, v reflect.Value) string {
}
switch {
case v.Kind() == reflect.Ptr:
case v.Kind() == reflect.Pointer:
v = v.Elem()
if v.Type().Implements(tpTableName) {
return v.Interface().(TableName).TableName()
@@ -70,7 +70,7 @@ func GetTableComment(v reflect.Value) string {
}
switch {
case v.Kind() == reflect.Ptr:
case v.Kind() == reflect.Pointer:
v = v.Elem()
if v.Type().Implements(tpTableComment) {
return v.Interface().(TableComment).TableComment()
+1 -1
View File
@@ -132,7 +132,7 @@ func (t *MyTable) TableName() string {
func TestMyTable(t *testing.T) {
var table MyTable
for i := 0; i < 10; i++ {
for i := range 10 {
table.Idx = i
assert.EqualValues(t, fmt.Sprintf("mytable_%d", i), GetTableName(SameMapper{}, reflect.ValueOf(&table)))
}
+3 -3
View File
@@ -30,9 +30,9 @@ func newRows(session *Session, bean any) (*Rows, error) {
var err error
beanValue := reflect.ValueOf(bean)
if beanValue.Kind() != reflect.Ptr {
if beanValue.Kind() != reflect.Pointer {
return nil, errors.New("needs a pointer to a value")
} else if beanValue.Elem().Kind() == reflect.Ptr {
} else if beanValue.Elem().Kind() == reflect.Pointer {
return nil, errors.New("a pointer to a pointer is not allowed")
}
@@ -105,7 +105,7 @@ func (rows *Rows) Scan(beans ...any) error {
bean := beans[0]
tp := reflect.TypeOf(bean)
if tp.Kind() == reflect.Ptr {
if tp.Kind() == reflect.Pointer {
tp = tp.Elem()
}
beanKind := tp.Kind()
+5 -5
View File
@@ -131,7 +131,7 @@ func genScanResultsByBean(bean any) (any, bool, error) {
func (engine *Engine) scanStringInterface(rows *core.Rows, fields []string, types []*sql.ColumnType) ([]any, error) {
scanResults := make([]any, len(types))
for i := 0; i < len(types); i++ {
for i := range types {
var s sql.NullString
scanResults[i] = &s
}
@@ -195,7 +195,7 @@ func (engine *Engine) scan(rows *core.Rows, _ []string, types []*sql.ColumnType,
func (engine *Engine) scanInterfaces(rows *core.Rows, fields []string, types []*sql.ColumnType) ([]any, error) {
scanResultContainers := make([]any, len(types))
for i := 0; i < len(types); i++ {
for i := range types {
scanResult, err := engine.driver.GenScanResult(types[i].DatabaseTypeName())
if err != nil {
return nil, err
@@ -214,7 +214,7 @@ func (engine *Engine) scanInterfaces(rows *core.Rows, fields []string, types []*
func (engine *Engine) row2mapInterface(rows *core.Rows, types []*sql.ColumnType, fields []string) (map[string]any, error) {
resultsMap := make(map[string]any, len(fields))
scanResultContainers := make([]any, len(fields))
for i := 0; i < len(fields); i++ {
for i := range fields {
scanResult, err := engine.driver.GenScanResult(types[i].DatabaseTypeName())
if err != nil {
return nil, err
@@ -278,7 +278,7 @@ func (engine *Engine) ScanInterfaceMaps(rows *core.Rows) (resultsSlice []map[str
func (engine *Engine) row2mapStr(rows *core.Rows, types []*sql.ColumnType, fields []string) (map[string]string, error) {
scanResults := make([]any, len(fields))
for i := 0; i < len(fields); i++ {
for i := range fields {
var s sql.NullString
scanResults[i] = &s
}
@@ -393,7 +393,7 @@ func (engine *Engine) row2sliceStr(rows *core.Rows, types []*sql.ColumnType, fie
}
results := make([]string, 0, len(fields))
for i := 0; i < len(fields); i++ {
for i := range fields {
results = append(results, scanResults[i].(*sql.NullString).String)
}
return results, nil
+1 -1
View File
@@ -86,7 +86,7 @@ func (col *Column) ValueOf(bean any) (*reflect.Value, error) {
func (col *Column) ValueOfV(dataStruct *reflect.Value) (*reflect.Value, error) {
v := *dataStruct
for _, i := range col.FieldIndex {
if v.Kind() == reflect.Ptr {
if v.Kind() == reflect.Pointer {
if v.IsNil() {
v.Set(reflect.New(v.Type().Elem()))
}
+2 -6
View File
@@ -7,6 +7,7 @@ package schemas
import (
"bytes"
"encoding/gob"
"slices"
"github.com/hanzoai/xorm/internal/utils"
)
@@ -22,12 +23,7 @@ func NewPK(pks ...any) *PK {
// IsZero return true if primay keys are zero
func (p *PK) IsZero() bool {
for _, k := range *p {
if utils.IsZero(k) {
return true
}
}
return false
return slices.ContainsFunc(*p, utils.IsZero)
}
// ToString convert to SQL string
+1 -1
View File
@@ -75,7 +75,7 @@ func (q Quoter) JoinWrite(b *strings.Builder, a []string, sep string) error {
}
n := len(sep) * (len(a) - 1)
for i := 0; i < len(a); i++ {
for i := range a {
n += len(a[i])
}
+1 -1
View File
@@ -31,7 +31,7 @@ func init() {
var name string
for i := 0; i < len(testsGetColumn); i++ {
for i := range testsGetColumn {
// as in Table.AddColumn func
name = strings.ToLower(testsGetColumn[i].name)
+25 -25
View File
@@ -245,36 +245,36 @@ var (
// enumerates all types
var (
IntType = reflect.TypeOf((*int)(nil)).Elem()
Int8Type = reflect.TypeOf((*int8)(nil)).Elem()
Int16Type = reflect.TypeOf((*int16)(nil)).Elem()
Int32Type = reflect.TypeOf((*int32)(nil)).Elem()
Int64Type = reflect.TypeOf((*int64)(nil)).Elem()
IntType = reflect.TypeFor[int]()
Int8Type = reflect.TypeFor[int8]()
Int16Type = reflect.TypeFor[int16]()
Int32Type = reflect.TypeFor[int32]()
Int64Type = reflect.TypeFor[int64]()
UintType = reflect.TypeOf((*uint)(nil)).Elem()
Uint8Type = reflect.TypeOf((*uint8)(nil)).Elem()
Uint16Type = reflect.TypeOf((*uint16)(nil)).Elem()
Uint32Type = reflect.TypeOf((*uint32)(nil)).Elem()
Uint64Type = reflect.TypeOf((*uint64)(nil)).Elem()
UintType = reflect.TypeFor[uint]()
Uint8Type = reflect.TypeFor[uint8]()
Uint16Type = reflect.TypeFor[uint16]()
Uint32Type = reflect.TypeFor[uint32]()
Uint64Type = reflect.TypeFor[uint64]()
Float32Type = reflect.TypeOf((*float32)(nil)).Elem()
Float64Type = reflect.TypeOf((*float64)(nil)).Elem()
Float32Type = reflect.TypeFor[float32]()
Float64Type = reflect.TypeFor[float64]()
Complex64Type = reflect.TypeOf((*complex64)(nil)).Elem()
Complex128Type = reflect.TypeOf((*complex128)(nil)).Elem()
Complex64Type = reflect.TypeFor[complex64]()
Complex128Type = reflect.TypeFor[complex128]()
StringType = reflect.TypeOf((*string)(nil)).Elem()
BoolType = reflect.TypeOf((*bool)(nil)).Elem()
ByteType = reflect.TypeOf((*byte)(nil)).Elem()
StringType = reflect.TypeFor[string]()
BoolType = reflect.TypeFor[bool]()
ByteType = reflect.TypeFor[byte]()
BytesType = reflect.SliceOf(ByteType)
TimeType = reflect.TypeOf((*time.Time)(nil)).Elem()
BigFloatType = reflect.TypeOf((*big.Float)(nil)).Elem()
NullFloat64Type = reflect.TypeOf((*sql.NullFloat64)(nil)).Elem()
NullStringType = reflect.TypeOf((*sql.NullString)(nil)).Elem()
NullInt32Type = reflect.TypeOf((*sql.NullInt32)(nil)).Elem()
NullInt64Type = reflect.TypeOf((*sql.NullInt64)(nil)).Elem()
NullBoolType = reflect.TypeOf((*sql.NullBool)(nil)).Elem()
TimeType = reflect.TypeFor[time.Time]()
BigFloatType = reflect.TypeFor[big.Float]()
NullFloat64Type = reflect.TypeFor[sql.NullFloat64]()
NullStringType = reflect.TypeFor[sql.NullString]()
NullInt32Type = reflect.TypeFor[sql.NullInt32]()
NullInt64Type = reflect.TypeFor[sql.NullInt64]()
NullBoolType = reflect.TypeFor[sql.NullBool]()
)
// Type2SQLType generate SQLType acorrding Go's type
@@ -322,7 +322,7 @@ func Type2SQLType(t reflect.Type) (st SQLType) {
// TODO need to handle association struct
st = SQLType{Text, 0, 0}
}
case reflect.Ptr:
case reflect.Pointer:
st = Type2SQLType(t.Elem())
default:
st = SQLType{Text, 0, 0}
+4 -4
View File
@@ -447,7 +447,7 @@ func (session *Session) row2Slice(rows *core.Rows, fields []string, types []*sql
}
scanResults := make([]any, len(fields))
for i := 0; i < len(fields); i++ {
for i := range fields {
var cell any
scanResults[i] = &cell
}
@@ -492,7 +492,7 @@ func setJSON(fieldValue *reflect.Value, fieldType reflect.Type, scanResult any)
func asKind(vv reflect.Value, tp reflect.Type) (any, error) {
switch tp.Kind() {
case reflect.Ptr:
case reflect.Pointer:
return asKind(vv.Elem(), tp.Elem())
case reflect.Int64:
return vv.Int(), nil
@@ -561,7 +561,7 @@ func (session *Session) convertBeanField(col *schemas.Column, fieldValue *reflec
return nil
}
if fieldValue.Kind() == reflect.Ptr && fieldValue.IsNil() {
if fieldValue.Kind() == reflect.Pointer && fieldValue.IsNil() {
fieldValue.Set(reflect.New(fieldValue.Type().Elem()))
return fieldValue.Interface().(convert.Conversion).FromDB(data)
}
@@ -576,7 +576,7 @@ func (session *Session) convertBeanField(col *schemas.Column, fieldValue *reflec
}
switch fieldType.Kind() {
case reflect.Ptr:
case reflect.Pointer:
var e reflect.Value
if fieldValue.IsNil() {
e = reflect.New(fieldType.Elem()).Elem()
+8 -8
View File
@@ -105,7 +105,7 @@ func (session *Session) find(rowsSlicePtr any, condiBean ...any) error {
tp := tpStruct
if session.statement.RefTable == nil {
switch sliceElementType.Kind() {
case reflect.Ptr:
case reflect.Pointer:
if sliceElementType.Elem().Kind() == reflect.Struct {
pv := reflect.New(sliceElementType.Elem())
if err := session.statement.SetRefValue(pv); err != nil {
@@ -234,11 +234,11 @@ func ParseColumnsSchema(fieldNames []string, types []*sql.ColumnType, table *sch
func (session *Session) noCacheFind(table *schemas.Table, containerValue reflect.Value, sqlStr string, args ...any) error {
elemType := containerValue.Type().Elem()
var isPointer bool
if elemType.Kind() == reflect.Ptr {
if elemType.Kind() == reflect.Pointer {
isPointer = true
elemType = elemType.Elem()
}
if elemType.Kind() == reflect.Ptr {
if elemType.Kind() == reflect.Pointer {
return errors.New("pointer to pointer is not supported")
}
@@ -431,7 +431,7 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr an
if ckb == t {
return true
}
return t.Kind() == reflect.Ptr && t.Elem() == ckb
return t.Kind() == reflect.Pointer && t.Elem() == ckb
}
if !isHit() {
ides = append(ides, id)
@@ -493,7 +493,7 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr an
vs := reflect.Indirect(reflect.ValueOf(beans))
for i := 0; i < vs.Len(); i++ {
rv := vs.Index(i)
if rv.Kind() != reflect.Ptr {
if rv.Kind() != reflect.Pointer {
rv = rv.Addr()
}
id, err := table.IDOfV(rv)
@@ -512,7 +512,7 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr an
}
}
for j := 0; j < len(temps); j++ {
for j := range temps {
bean := temps[j]
if bean == nil {
session.engine.logger.Warnf("[cache] cache no hit: %v, %v, %v", tableName, ids[j], temps)
@@ -520,7 +520,7 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr an
continue
}
if sliceValue.Kind() == reflect.Slice {
if t.Kind() == reflect.Ptr {
if t.Kind() == reflect.Pointer {
sliceValue.Set(reflect.Append(sliceValue, reflect.ValueOf(bean)))
} else {
sliceValue.Set(reflect.Append(sliceValue, reflect.Indirect(reflect.ValueOf(bean))))
@@ -542,7 +542,7 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr an
ikey = key
}
if t.Kind() == reflect.Ptr {
if t.Kind() == reflect.Pointer {
sliceValue.SetMapIndex(reflect.ValueOf(ikey), reflect.ValueOf(bean))
} else {
sliceValue.SetMapIndex(reflect.ValueOf(ikey), reflect.Indirect(reflect.ValueOf(bean)))
+2 -2
View File
@@ -71,9 +71,9 @@ func (session *Session) get(beans ...any) (bool, error) {
beanValue := reflect.ValueOf(beans[0])
switch {
case beanValue.Kind() != reflect.Ptr:
case beanValue.Kind() != reflect.Pointer:
return false, errors.New("needs a pointer to a value")
case beanValue.Elem().Kind() == reflect.Ptr:
case beanValue.Elem().Kind() == reflect.Pointer:
return false, errors.New("a pointer to a pointer is not allowed")
case beanValue.IsNil():
return false, ErrObjectIsNil
+3 -3
View File
@@ -96,7 +96,7 @@ func (session *Session) insertMultipleStruct(rowsSlicePtr any) (int64, error) {
autoInsertClosures []func(any)
)
for i := 0; i < size; i++ {
for i := range size {
v := sliceValue.Index(i)
var vv reflect.Value
switch v.Kind() {
@@ -203,7 +203,7 @@ func (session *Session) insertMultipleStruct(rowsSlicePtr any) (int64, error) {
session.cacheInsert(tableName)
for i := 0; i < size; i++ {
for i := range size {
elemValue := reflect.Indirect(sliceValue.Index(i)).Addr().Interface()
for _, closure := range autoInsertClosures {
closure(elemValue)
@@ -211,7 +211,7 @@ func (session *Session) insertMultipleStruct(rowsSlicePtr any) (int64, error) {
}
lenAfterClosures := len(session.afterClosures)
for i := 0; i < size; i++ {
for i := range size {
elemValue := reflect.Indirect(sliceValue.Index(i)).Addr().Interface()
// handle AfterInsertProcessor
+1 -1
View File
@@ -38,7 +38,7 @@ func (session *Session) sum(res, bean any, columnNames ...string) error {
}
v := reflect.ValueOf(res)
if v.Kind() != reflect.Ptr {
if v.Kind() != reflect.Pointer {
return errors.New("need a pointer to a variable")
}
+1 -1
View File
@@ -39,7 +39,7 @@ func (session *Session) genAutoCond(condiBean any) (builder.Cond, error) {
ct := reflect.TypeOf(condiBean)
k := ct.Kind()
if k == reflect.Ptr {
if k == reflect.Pointer {
k = ct.Elem().Kind()
}
if k != reflect.Struct {
+6 -6
View File
@@ -28,13 +28,13 @@ type TableIndices interface {
TableIndices() []*schemas.Index
}
var tpTableIndices = reflect.TypeOf((*TableIndices)(nil)).Elem()
var tpTableIndices = reflect.TypeFor[TableIndices]()
type TableCollations interface {
TableCollations() []*schemas.Collation
}
var tpTableCollations = reflect.TypeOf((*TableCollations)(nil)).Elem()
var tpTableCollations = reflect.TypeFor[TableCollations]()
// Parser represents a parser for xorm tag
type Parser struct {
@@ -139,7 +139,7 @@ func addIndex(indexName string, table *schemas.Table, col *schemas.Column, index
var ErrIgnoreField = errors.New("field will be ignored")
func (parser *Parser) getSQLTypeByType(t reflect.Type) (schemas.SQLType, error) {
if t.Kind() == reflect.Ptr {
if t.Kind() == reflect.Pointer {
t = t.Elem()
}
if t.Kind() == reflect.Struct {
@@ -322,7 +322,7 @@ func isNotTitle(n string) bool {
// Parse parses a struct as a table information
func (parser *Parser) Parse(v reflect.Value) (*schemas.Table, error) {
t := v.Type()
if t.Kind() == reflect.Ptr {
if t.Kind() == reflect.Pointer {
t = t.Elem()
v = v.Elem()
}
@@ -392,7 +392,7 @@ func tableIndices(v reflect.Value) []*schemas.Index {
return v.Interface().(TableIndices).TableIndices()
}
if v.Kind() == reflect.Ptr {
if v.Kind() == reflect.Pointer {
v = v.Elem()
if v.Type().Implements(tpTableIndices) {
return v.Interface().(TableIndices).TableIndices()
@@ -411,7 +411,7 @@ func tableCollations(v reflect.Value) []*schemas.Collation {
return v.Interface().(TableCollations).TableCollations()
}
if v.Kind() == reflect.Ptr {
if v.Kind() == reflect.Pointer {
v = v.Elem()
if v.Type().Implements(tpTableCollations) {
return v.Interface().(TableCollations).TableCollations()
+1 -1
View File
@@ -358,7 +358,7 @@ func ExtendsTagHandler(ctx *Context) error {
fieldValue := ctx.fieldValue
isPtr := false
switch fieldValue.Kind() {
case reflect.Ptr:
case reflect.Pointer:
f := fieldValue.Type().Elem()
if f.Kind() == reflect.Struct {
fieldPtr := fieldValue
+1 -1
View File
@@ -97,7 +97,7 @@ func TestSplitTag(t *testing.T) {
tags, err := splitTag(kase.tag)
assert.NoError(t, err)
assert.EqualValues(t, len(tags), len(kase.tags))
for i := 0; i < len(tags); i++ {
for i := range tags {
assert.Equal(t, kase.tags[i], tags[i])
}
})
+3 -3
View File
@@ -11,9 +11,9 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/hanzoai/xorm"
"github.com/hanzoai/xorm/schemas"
"github.com/stretchr/testify/assert"
)
func TestStoreEngine(t *testing.T) {
@@ -132,7 +132,7 @@ func TestCreateMultiTables(t *testing.T) {
user := &UserinfoMultiTable{}
assert.NoError(t, session.Begin())
for i := 0; i < 10; i++ {
for i := range 10 {
tableName := fmt.Sprintf("user_%v", i)
assert.NoError(t, session.DropTable(tableName))
@@ -461,7 +461,7 @@ func TestSync2_2(t *testing.T) {
assert.NoError(t, PrepareEngine())
tableNames := make(map[string]bool)
for i := 0; i < 10; i++ {
for i := range 10 {
tableName := fmt.Sprintf("test_sync2_index_%d", i)
tableNames[tableName] = true
assert.NoError(t, testEngine.Table(tableName).Sync(new(TestSync2Index)))
+5 -13
View File
@@ -8,12 +8,12 @@ import (
"testing"
"time"
"github.com/shopspring/decimal"
"github.com/hanzoai/builder"
"github.com/hanzoai/xorm"
"github.com/hanzoai/xorm/internal/utils"
"github.com/hanzoai/xorm/names"
"github.com/hanzoai/xorm/schemas"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
)
@@ -875,21 +875,13 @@ func TestFindExtends3(t *testing.T) {
assertSync(t, new(FindExtendsAA))
cnt, err := testEngine.Insert(&FindExtendsAA{
FindExtendsBB: FindExtendsBB{
FindExtendsCC: FindExtendsCC{
Name: "cc1",
},
},
Name: "cc1",
})
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)
cnt, err = testEngine.Insert(&FindExtendsAA{
FindExtendsBB: FindExtendsBB{
FindExtendsCC: FindExtendsCC{
Name: "cc2",
},
},
Name: "cc2",
})
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)
@@ -974,14 +966,14 @@ func TestFindCacheLimit(t *testing.T) {
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)
for i := 0; i < 8; i++ {
for range 8 {
var beans []InviteCode
err = testEngine.Limit(1, 0).Find(&beans)
assert.NoError(t, err)
assert.EqualValues(t, 1, len(beans))
}
for i := 0; i < 8; i++ {
for range 8 {
var beans2 []*InviteCode
err = testEngine.Limit(1, 0).Find(&beans2)
assert.NoError(t, err)
+1 -3
View File
@@ -414,9 +414,7 @@ func TestJSONString(t *testing.T) {
assertSync(t, new(JsonAnonymousStruct))
_, err = testEngine.Insert(&JsonAnonymousStruct{
JsonString: JsonString{
Content: "1",
},
Content: "1",
})
assert.NoError(t, err)
+1 -3
View File
@@ -688,9 +688,7 @@ func TestAnonymousStruct(t *testing.T) {
assertSync(t, new(PlainFoo))
_, err := testEngine.Insert(&PlainFoo{
PlainObject: PlainObject{
Desc: "test",
},
Desc: "test",
Width: 10,
Height: 20,
+1 -1
View File
@@ -60,7 +60,7 @@ func TestBufferIterate(t *testing.T) {
assert.NoError(t, testEngine.Sync(new(UserBufferIterate)))
size := 20
for i := 0; i < size; i++ {
for range size {
cnt, err := testEngine.Insert(&UserBufferIterate{
IsMan: true,
})
+1 -1
View File
@@ -400,7 +400,7 @@ func TestQueryBLOBInMySQL(t *testing.T) {
const N = 10
data := []Avatar{}
for i := 0; i < N; i++ {
for i := range N {
// allocate a []byte that is as twice big as the last one
// so that the underlying buffer will need to reallocate when querying
bs := repeatBytes(1<<(i+2), 'A'+byte(i))
+5 -9
View File
@@ -10,12 +10,12 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/hanzoai/xorm"
"github.com/hanzoai/xorm/internal/statements"
"github.com/hanzoai/xorm/internal/utils"
"github.com/hanzoai/xorm/names"
"github.com/hanzoai/xorm/schemas"
"github.com/stretchr/testify/assert"
)
func TestUpdateMap(t *testing.T) {
@@ -230,8 +230,7 @@ func TestForUpdate(t *testing.T) {
wg := &sync.WaitGroup{}
// lock is used
wg.Add(1)
go func() {
wg.Go(func() {
f2 := new(ForUpdate)
session2.Where("`id` = ?", 1).ForUpdate()
has, err := session2.Get(f2) // wait release lock
@@ -243,15 +242,13 @@ func TestForUpdate(t *testing.T) {
case f2.Name != "updated by session1":
t.Errorf("read lock failed")
}
wg.Done()
}()
})
// lock is NOT used
wg.Add(1)
wg2 := &sync.WaitGroup{}
wg2.Add(1)
go func() {
wg2.Go(func() {
f3 := new(ForUpdate)
session3.Where("`id` = ?", 1)
has, err := session3.Get(f3) // wait release lock
@@ -264,8 +261,7 @@ func TestForUpdate(t *testing.T) {
t.Errorf("read lock failed")
}
wg.Done()
wg2.Done()
}()
})
wg2.Wait()
+4 -10
View File
@@ -10,11 +10,11 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/hanzoai/xorm/convert"
"github.com/hanzoai/xorm/internal/utils"
"github.com/hanzoai/xorm/names"
"github.com/hanzoai/xorm/schemas"
"github.com/stretchr/testify/assert"
)
type tempUser struct {
@@ -226,9 +226,7 @@ func TestExtends2(t *testing.T) {
assert.NoError(t, err)
msg := Message{
MessageBase: MessageBase{
Id: msgtype.Id,
},
Id: msgtype.Id,
Title: "test",
Content: "test",
Uid: sender.Id,
@@ -287,9 +285,7 @@ func TestExtends3(t *testing.T) {
assert.NoError(t, err)
msg := Message{
MessageBase: MessageBase{
Id: msgtype.Id,
},
Id: msgtype.Id,
Title: "test",
Content: "test",
Uid: sender.Id,
@@ -351,9 +347,7 @@ func TestExtends4(t *testing.T) {
assert.NoError(t, err)
msg := Message{
MessageBase: MessageBase{
Id: msgtype.Id,
},
Id: msgtype.Id,
Title: "test",
Content: "test",
Uid: sender.Id,
+1 -1
View File
@@ -211,7 +211,7 @@ func MainTest(m *testing.M) {
conns := strings.Split(connString, "::")
var res int
for i := 0; i < len(dbs); i++ {
for i := range dbs {
dbType = dbs[i]
connString = conns[i]
testEngine = nil
+1 -1
View File
@@ -96,7 +96,7 @@ func TestNullStructInsert(t *testing.T) {
assert.EqualValues(t, 2, item.Id)
items := []NullStruct{}
for i := 0; i < 5; i++ {
for i := range 5 {
item := NullStruct{
Name: sql.NullString{String: "haolei_" + strconv.Itoa(i+1), Valid: true},
Age: sql.NullInt64{Int64: 30 + int64(i), Valid: true},