mysql_dm_special.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package dao
  2. import (
  3. "context"
  4. "strings"
  5. "time"
  6. "go-common/library/database/sql"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _addDmSpecialLocationSQL = "INSERT INTO dm_special_content_location (type,oid,locations,ctime) VALUES(?,?,?,?) ON DUPLICATE KEY UPDATE locations=?"
  11. _getDmSpecialLocationSQL = "SELECT locations FROM dm_special_content_location WHERE oid=? AND type=?"
  12. )
  13. // UpsertDmSpecialLocation .
  14. func (d *Dao) UpsertDmSpecialLocation(c context.Context, tp int32, oid int64, locations string) (err error) {
  15. if _, err = d.dmWriter.Exec(c, _addDmSpecialLocationSQL, tp, oid, locations, time.Now(), locations); err != nil {
  16. log.Error("AddDmSpecialLocation.Exec error(%v)", err)
  17. }
  18. return
  19. }
  20. // DMSpecialLocations .
  21. func (d *Dao) DMSpecialLocations(c context.Context, tp int32, oid int64) (locations []string, err error) {
  22. row := d.dmReader.QueryRow(c, _getDmSpecialLocationSQL, oid, tp)
  23. var s string
  24. if err = row.Scan(&s); err != nil {
  25. if err == sql.ErrNoRows {
  26. err = nil
  27. } else {
  28. log.Error("DMSpecialLocations.Query error(%v)", err)
  29. }
  30. return
  31. }
  32. locations = strings.Split(s, ",")
  33. return
  34. }