[chore]: Bump github.com/uptrace/bun/dialect/sqlitedialect

Bumps [github.com/uptrace/bun/dialect/sqlitedialect](https://github.com/uptrace/bun) from 1.2.6 to 1.2.8.
- [Release notes](https://github.com/uptrace/bun/releases)
- [Changelog](https://github.com/uptrace/bun/blob/master/CHANGELOG.md)
- [Commits](https://github.com/uptrace/bun/compare/v1.2.6...v1.2.8)

---
updated-dependencies:
- dependency-name: github.com/uptrace/bun/dialect/sqlitedialect
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot] 2025-01-14 13:12:59 +00:00 committed by GitHub
commit afd5f8a80a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
48 changed files with 631 additions and 139 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) {