Is there a simpler way of executing MySQL commands in Go using the github.com/go-sql-driver/mysql
package?
Essentially this is the current command I am using:
db.Exec("INSERT INTO table1 (id, title, name, dob, address, email, notes) VALUES (?, ?, ?, ?, ?, ?, ?)", id, title, name, dob, address, email, notes)
And how I'm using this command would be:
var people []people
for _, person := range people {
db.Exec("INSERT INTO table1 (id, title, name, dob, address, email, notes) VALUES (?, ?, ?, ?, ?, ?, ?)", person.id, person.title, person.name, person.dob, person.address, person.email, person.notes)
}
https://godoc.org/github.com/jmoiron/sqlx#NamedExec makes it slightly better. It could be, something like:
result, err := db.NamedExec(`INSERT INTO table1 (id, title, name, dob, address, email, notes) VALUES (:id, :title, :name, :dob, :address, :email, :notes)`,
person)
Do have a look at my model.go example for further details.