mysql.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package videoshot
  2. import (
  3. "context"
  4. "database/sql"
  5. "go-common/app/service/main/archive/model/videoshot"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _inSQL = "INSERT INTO archive_video_shot (id,count,ctime,mtime) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE count=?,mtime=? "
  10. _getSQL = "SELECT id,count,ctime,mtime FROM archive_video_shot WHERE id=?"
  11. )
  12. // videoshot get a videoshot by id.
  13. func (d *Dao) videoshot(c context.Context, cid int64) (shot *videoshot.Videoshot, err error) {
  14. d.infoProm.Incr("videoshot")
  15. row := d.getStmt.QueryRow(c, cid)
  16. shot = &videoshot.Videoshot{}
  17. if err = row.Scan(&shot.Cid, &shot.Count, &shot.CTime, &shot.MTime); err != nil {
  18. if err == sql.ErrNoRows {
  19. shot = nil
  20. err = nil
  21. } else {
  22. log.Error("row.Scan() error(%v)", err)
  23. }
  24. }
  25. return
  26. }
  27. // addVideoshot add a videoshot into mysql.
  28. func (d *Dao) addVideoshot(c context.Context, shot *videoshot.Videoshot) (cid int64, err error) {
  29. res, err := d.inStmt.Exec(c, shot.Cid, shot.Count, shot.CTime, shot.MTime, shot.Count, shot.MTime)
  30. if err != nil {
  31. log.Error("inStmt.Exec error(%v)", err)
  32. return
  33. }
  34. cid, err = res.LastInsertId()
  35. return
  36. }