You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Environments (please complete the following information):**
- OS: [e.g. Windows]
- go-zero version [e.g. v1.7.4]
- goctl version [e.g. 1.21.6]
**More description**
The text was updated successfully, but these errors were encountered:
kevwan
changed the title
【sqlx】不支持结构体的小写变量名
[sqlx] does not support struct fields with lowercase (unexported) names.
Mar 30, 2025
Underlying QueryRowsCtx, reflect.Value.Interface() is used to parse the fields of struct. But unexported fields can't be accessed with reflect, possible for safety reason. Actually, if you json.Marshal/Unmarshal a struct, unexported fields won't be marshaled/unmarshaled.
So I believe the simplest solution is to use uppercase names. Or use an intermediate struct with all uppercase names for query if you need lowercase names.
Describe the bug
sqlx不支持结构体小写的变量名
To Reproduce
Steps to reproduce the behavior, if applicable:
The code is
func main() {
DbQuery()
}
func NewMysql() sqlx.SqlConn {
mysql := sqlx.NewMysql("xxx")
db, err := mysql.RawDB()
if err != nil {
panic(err)
}
}
func DbQuery() {
mysql := NewMysql()
var resp []BaseOption
ctx, cancel := context.WithTimeout(context.Background(), time.Second60)
defer cancel()
}
type (
BaseModel struct {
Id uint64
db:"id"
Deleted uint64
db:"deleted"
CreatedDate time.Time
db:"created_date"
CreatedUserName string
db:"created_user_name"
CreatedUserId uint64
db:"created_user_id"
ModifiedDate sql.NullTime
db:"modified_date"
ModifiedUserName sql.NullString
db:"modified_user_name"
ModifiedUserId sql.NullInt64
db:"modified_user_id"
}
BaseOption struct {
//数据库表映射的结构体
Name string
db:"name"
Value string
db:"value"
description sql.NullString
db:"description"
//****小写变量名BaseModel
db:"-"
}
)
func (m *BaseOption) GetDesc() string {
return m.description.String
}
func (m *BaseOption) SetDesc() {
}
value not addressable or interfaceable
The text was updated successfully, but these errors were encountered: