Consider the following example:
package main
import (
"fmt"
"github.com/jmoiron/sqlx"
_ "github.com/go-sql-driver/mysql"
)
type Data struct {
Stuff string
}
func main() {
db, _ := sqlx.Connect("mysql", "root:root@(localhost:3306)/data")
var datas []Data
db.Select(&datas, "select 'a,b' stuff from data limit 10")
fmt.Println(datas)
}
What I'd like to do is have Stuff
as []string
, where it would be split by ,
. I guess I could add an extra []string
field and loop over the results populating this field and removing the source data, but that seems inefficient. What's the canonical way to do this in sqlx
?