ups.go 679 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package manager
  2. import (
  3. "context"
  4. "go-common/library/log"
  5. )
  6. const (
  7. _upsSQL = "SELECT mid,type FROM ups"
  8. )
  9. // Uppers get uppers by type.
  10. func (d *Dao) Uppers(c context.Context) (um map[int8]map[int64]struct{}, err error) {
  11. rows, err := d.db.Query(c, _upsSQL)
  12. if err != nil {
  13. log.Error("d.db.Query error(%v)", err)
  14. return
  15. }
  16. defer rows.Close()
  17. um = map[int8]map[int64]struct{}{}
  18. for rows.Next() {
  19. var (
  20. mid int64
  21. tp int8
  22. )
  23. if err = rows.Scan(&mid, &tp); err != nil {
  24. log.Error("rows.Scan error(%v)", err)
  25. return
  26. }
  27. if mm, ok := um[tp]; ok {
  28. mm[mid] = struct{}{}
  29. } else {
  30. um[tp] = map[int64]struct{}{mid: struct{}{}}
  31. }
  32. }
  33. return
  34. }