Skip to content

Instantly share code, notes, and snippets.

@PumpkinSeed
PumpkinSeed / sql.go
Last active June 11, 2023 12:56
Extension for sql package
func structScan(rows *sql.Rows, model interface{}) error {
v := reflect.ValueOf(model)
if v.Kind() != reflect.Ptr {
return errors.New("must pass a pointer, not a value, to StructScan destination") // @todo add new error message
}
v = reflect.Indirect(v)
t := v.Type()
cols, _ := rows.Columns()