bumps our uptrace/bun dependencies to v1.2.10 (#3865)

This commit is contained in:
kim
2025-03-03 10:42:05 +00:00
committed by GitHub
parent ddd9210614
commit 67a2b3650c
37 changed files with 518 additions and 225 deletions

View File

@ -62,8 +62,9 @@ type Table struct {
FieldMap map[string]*Field
StructMap map[string]*structField
Relations map[string]*Relation
Unique map[string][]*Field
IsM2MTable bool // If true, this table is the "junction table" of an m2m relation.
Relations map[string]*Relation
Unique map[string][]*Field
SoftDeleteField *Field
UpdateSoftDeleteField func(fv reflect.Value, tm time.Time) error
@ -122,6 +123,7 @@ func (t *Table) processFields(typ reflect.Type) {
names := make(map[string]struct{})
embedded := make([]embeddedField, 0, 10)
ebdStructs := make(map[string]*structField, 0)
for i, n := 0, typ.NumField(); i < n; i++ {
sf := typ.Field(i)
@ -163,6 +165,17 @@ func (t *Table) processFields(typ reflect.Type) {
subfield: subfield,
})
}
if len(subtable.StructMap) > 0 {
for k, v := range subtable.StructMap {
// NOTE: conflict Struct name
if _, ok := ebdStructs[k]; !ok {
ebdStructs[k] = &structField{
Index: makeIndex(sf.Index, v.Index),
Table: subtable,
}
}
}
}
if tagstr != "" {
tag := tagparser.Parse(tagstr)
@ -197,6 +210,18 @@ func (t *Table) processFields(typ reflect.Type) {
subfield: subfield,
})
}
if len(subtable.StructMap) > 0 {
for k, v := range subtable.StructMap {
// NOTE: conflict Struct name
k = prefix + k
if _, ok := ebdStructs[k]; !ok {
ebdStructs[k] = &structField{
Index: makeIndex(sf.Index, v.Index),
Table: subtable,
}
}
}
}
continue
}
@ -252,6 +277,15 @@ func (t *Table) processFields(typ reflect.Type) {
}
}
if len(ebdStructs) > 0 && t.StructMap == nil {
t.StructMap = make(map[string]*structField)
}
for name, sfield := range ebdStructs {
if _, ok := t.StructMap[name]; !ok {
t.StructMap[name] = sfield
}
}
if len(embedded) > 0 {
// https://github.com/uptrace/bun/issues/1095
// < v1.2, all fields follow the order corresponding to the struct
@ -483,6 +517,7 @@ func (t *Table) newField(sf reflect.StructField, tag tagparser.Tag) *Field {
}
field := &Field{
Table: t,
StructField: sf,
IsPtr: sf.Type.Kind() == reflect.Ptr,
@ -862,6 +897,7 @@ func (t *Table) m2mRelation(field *Field) *Relation {
JoinTable: joinTable,
M2MTable: m2mTable,
}
m2mTable.markM2M()
if field.Tag.HasOption("join_on") {
rel.Condition = field.Tag.Options["join_on"]
@ -907,6 +943,10 @@ func (t *Table) m2mRelation(field *Field) *Relation {
return rel
}
func (t *Table) markM2M() {
t.IsM2MTable = true
}
//------------------------------------------------------------------------------
func (t *Table) Dialect() Dialect { return t.dialect }