location.go 717 B

123456789101112131415161718192021222324252627
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/bbq/user/api"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. )
  8. var (
  9. locationQuery = "select `loc_id`, `pid`, `name` from `bbq_location` where `loc_id` = ?;"
  10. )
  11. // GetLocation return the location info
  12. func (d *Dao) GetLocation(c context.Context, locId int32) (*api.LocationItem, error) {
  13. row := d.db.QueryRow(c, locationQuery, locId)
  14. var location api.LocationItem
  15. err := row.Scan(&location.Id, &location.Pid, &location.Name)
  16. if err == sql.ErrNoRows {
  17. return nil, nil
  18. }
  19. if err != nil {
  20. log.Errorv(c, log.KV("event", "mysql_select"), log.KV("table", "bbq_location"), log.KV("loc_id", locId))
  21. return nil, err
  22. }
  23. return &location, nil
  24. }