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)
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e485f3-271e8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e485f3-271e8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?