bump uptrace/bun dependencies from 1.2.6 to 1.2.8 (#3645)

This commit is contained in:
kim
2025-01-14 14:23:28 +00:00
committed by GitHub
parent e77c7e16b6
commit b8ef9fc4bc
89 changed files with 907 additions and 4123 deletions

View File

@ -4,6 +4,7 @@ import (
"database/sql"
"fmt"
"reflect"
"sort"
"strings"
"time"
@ -22,7 +23,7 @@ const (
)
var (
baseModelType = reflect.TypeOf((*BaseModel)(nil)).Elem()
baseModelType = reflect.TypeFor[BaseModel]()
tableNameInflector = inflection.Plural
)
@ -75,7 +76,7 @@ type structField struct {
Table *Table
}
func (table *Table) init(dialect Dialect, typ reflect.Type, canAddr bool) {
func (table *Table) init(dialect Dialect, typ reflect.Type) {
table.dialect = dialect
table.Type = typ
table.ZeroValue = reflect.New(table.Type).Elem()
@ -90,7 +91,7 @@ func (table *Table) init(dialect Dialect, typ reflect.Type, canAddr bool) {
table.Fields = make([]*Field, 0, typ.NumField())
table.FieldMap = make(map[string]*Field, typ.NumField())
table.processFields(typ, canAddr)
table.processFields(typ)
hooks := []struct {
typ reflect.Type
@ -110,7 +111,7 @@ func (table *Table) init(dialect Dialect, typ reflect.Type, canAddr bool) {
}
}
func (t *Table) processFields(typ reflect.Type, canAddr bool) {
func (t *Table) processFields(typ reflect.Type) {
type embeddedField struct {
prefix string
index []int
@ -250,6 +251,30 @@ func (t *Table) processFields(typ reflect.Type, canAddr bool) {
t.addUnique(subfield, embfield.prefix, v)
}
}
if len(embedded) > 0 {
// https://github.com/uptrace/bun/issues/1095
// < v1.2, all fields follow the order corresponding to the struct
// >= v1.2, < v1.2.8, fields of nested structs have been moved to the end.
// >= v1.2.8, The default behavior remains the same as initially,
sortFieldsByStruct(t.allFields)
sortFieldsByStruct(t.Fields)
sortFieldsByStruct(t.PKs)
sortFieldsByStruct(t.DataFields)
}
}
func sortFieldsByStruct(fields []*Field) {
sort.Slice(fields, func(i, j int) bool {
left, right := fields[i], fields[j]
for k := 0; k < len(left.Index) && k < len(right.Index); k++ {
if left.Index[k] != right.Index[k] {
return left.Index[k] < right.Index[k]
}
}
// NOTE: should not reach
return true
})
}
func (t *Table) addUnique(field *Field, prefix string, tagOptions []string) {