Is there any way for go's native mysql library to scan a result directly to a structure?

No other orm, is used after QueryRow. The result currently needs to be specified one by one in scan. Is there any way to directly scan a struct, to save a lot of trouble

Mar.07,2021

The RawSetters in the orm of

beego has QueryRow and QueryRows methods, which can put the results of the query directly into the structure you define.


type User struct {
    Id       int
    UserName string
}

var users []User
num, err := o.Raw("SELECT id, user_name FROM user WHERE id = ?", 1).QueryRows(&users)
if err == nil {
    fmt.Println("user nums: ", num)
}
Menu