What's the recommended way to connect to MySQL from Go?

前端 未结 2 596
予麋鹿
予麋鹿 2020-11-30 16:45

I am looking for a reliable solution to connect to a MySQL database from Go. I\'ve seen some libraries around but it is difficult to determine the different states of comple

2条回答
  •  伪装坚强ぢ
    2020-11-30 16:56

    few things to take note the select 1 row example :

    row := con.QueryRow("select mdpr, x, y, z from sometable where id=?",id) 
    cb := new(SomeThing) 
    err := row.Scan(&cb.Mdpr, &cb.X, &cb.Y, &cb.Z)
    

    there is a missing row.Next() in this example. it need to call the row.Next() to grab the first row returned.

    also there is some inflexibility to the library which in some way try to promote data minimalism. if you try to select columns that is not Scan it will throw errors (not just warnings)

提交回复
热议问题