Was putting together a quick dumper for MySQL to JSON in Go. However I find that everything that I retrieve from the database is a []byte
array. Thus instead of n
There's not much you can do because the driver
- database/sql
interaction is pretty much a one way street and the driver can't help you with anything when the data is handed over to database/sql
.
You could try your luck with http://godoc.org/github.com/arnehormann/sqlinternals/mysqlinternals
cols, err := mysqlinternals.Columns(rows)
values := make([]interface{}, len(cols))
and iterate over cols
refType, err := cols[i].ReflectGoType()
values[i] = reflect.Zero(refType).Interface()
rows.Next()
and err = rows.Scan(values...)
. Don't recreate values
, copy and reuse it.I guess this will still be pretty slow, but you should be able to get somewhere with it. If you encounter problems, please file an issue - I'll get to it as soon as I can.