func NamedExec 有什么问题?

What is wrong with func NamedExec?

转到版本1.14.6
sqlx 版本latest

错误代码如下:

test := Test{
  Name: "John",
  Age:  30,
  Id:   "bskdvfjreo018g2c5pqg",
}
// table test has fields: id, name, age
_, err := sqlxdb.DB.NamedExec("NSERT INTO test(name,age,id)VALUES(:Name,:Age,:Id)", &test)
log.Println(err)

// log as follow:

// 2020/08/07 11:49:15 could not find name Name in &sqlx.Test{Id:"bskdvfjreo018g2c5pqg", Name:"John", CreateAt:0, Age:30}

谁知道 NamedExec 的第二个参数是否必须像 ":create_at" 而不是像 ":CreateAt" 那样传递值?

jmoiron/sqlx issue 419, check if adding json field name mapping (using struct field tag) 会有所帮助:

type User struct {
  Id        int       `json:"id"`
  Name      string    `json:"name"`
  Bio       string    `json:"about,omitempty"`
  Active    bool      `json:"active"`
  Admin     bool      `json:"-"`
  CreatedAt time.Time `json:"created_at"`
}

然后看看将 &test 传递给 NamedExec 是否会导致 NamedExec 使用 :created_at 而不是 :CreatedAt