rows.go 363 B

1234567891011121314151617181920212223
  1. package common
  2. import (
  3. "database/sql"
  4. "reflect"
  5. )
  6. type Rows struct {
  7. *sql.Rows
  8. }
  9. func scans(row any) []any {
  10. v := reflect.ValueOf(row).Elem()
  11. res := make([]interface{}, v.NumField())
  12. for i := 0; i < v.NumField(); i++ {
  13. res[i] = v.Field(i).Addr().Interface()
  14. }
  15. return res
  16. }
  17. func (r *Rows) Scans(row any) error {
  18. return r.Rows.Scan(scans(row)...)
  19. }