fix(scan): 修复对struct存在重复属性导致的崩溃
新增了在递归scan对象属性的时候发现嵌套属性名称和当前属性名称一致的时候做了友好错误提示
This commit is contained in:
parent
dde9b6f74e
commit
ca03e37c18
@ -65,7 +65,7 @@ func (b *Mapper) extractStructData(data ...any) (map[string][]*TableRowMateria,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if tableName == "" {
|
if tableName == "" {
|
||||||
return nil, fmt.Errorf("not import TableName() string func for struct type: %s", uniqueTypeName)
|
return nil, fmt.Errorf("not func TableName() string func for struct type: %s", uniqueTypeName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ func TestBuilderInsert(t *testing.T) {
|
|||||||
Ts: time.Now(), LoadUnitId: "负载单体ID", PInt: &p, NullInt32: sql.NullInt32{Int32: 32, Valid: true},
|
Ts: time.Now(), LoadUnitId: "负载单体ID", PInt: &p, NullInt32: sql.NullInt32{Int32: 32, Valid: true},
|
||||||
},
|
},
|
||||||
&TaosUser{
|
&TaosUser{
|
||||||
TaosTAG: &TaosTAG{DevId: "User001", DevType: "User类型", DataType: "User数据类型001"},
|
TaosTAG: &TaosTAG{DevId: "User001", DevType: "User类型", DataType: "User数据类型001", Alias: "三儿"},
|
||||||
Ts: time.Now(), Name: "张三",
|
Ts: time.Now(), Name: "张三",
|
||||||
}, &TaosUser{
|
}, &TaosUser{
|
||||||
TaosTAG: &TaosTAG{DevId: "User002", DevType: "User类型", DataType: "User数据类型002"},
|
TaosTAG: &TaosTAG{DevId: "User002", DevType: "User类型", DataType: "User数据类型002"},
|
||||||
|
6
scan.go
6
scan.go
@ -81,7 +81,11 @@ func scan(data interface{}) (*StructMate, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
sr.Field2IndexCache[field.Name] = append(sr.Field2IndexCache[field.Name], i)
|
if len(sr.Field2IndexCache[field.Name]) > 0 {
|
||||||
|
return nil, fmt.Errorf("duplicate field [%s %s `db:%s`]", field.Name, field.Type.Name(), columnName)
|
||||||
|
}
|
||||||
|
|
||||||
|
sr.Field2IndexCache[field.Name] = append([]int{}, i)
|
||||||
sr.DBName2IndexCache[columnName] = append(sr.DBName2IndexCache[columnName], i)
|
sr.DBName2IndexCache[columnName] = append(sr.DBName2IndexCache[columnName], i)
|
||||||
sr.Filed2DBNameCache[field.Name] = columnName
|
sr.Filed2DBNameCache[field.Name] = columnName
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user