You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
package videoshot |
|
|
|
import ( |
|
"context" |
|
"database/sql" |
|
|
|
"go-common/app/service/main/archive/model/videoshot" |
|
"go-common/library/log" |
|
) |
|
|
|
const ( |
|
_inSQL = "INSERT INTO archive_video_shot (id,count,ctime,mtime) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE count=?,mtime=? " |
|
_getSQL = "SELECT id,count,ctime,mtime FROM archive_video_shot WHERE id=?" |
|
) |
|
|
|
// videoshot get a videoshot by id. |
|
func (d *Dao) videoshot(c context.Context, cid int64) (shot *videoshot.Videoshot, err error) { |
|
d.infoProm.Incr("videoshot") |
|
row := d.getStmt.QueryRow(c, cid) |
|
shot = &videoshot.Videoshot{} |
|
if err = row.Scan(&shot.Cid, &shot.Count, &shot.CTime, &shot.MTime); err != nil { |
|
if err == sql.ErrNoRows { |
|
shot = nil |
|
err = nil |
|
} else { |
|
log.Error("row.Scan() error(%v)", err) |
|
} |
|
} |
|
return |
|
} |
|
|
|
// addVideoshot add a videoshot into mysql. |
|
func (d *Dao) addVideoshot(c context.Context, shot *videoshot.Videoshot) (cid int64, err error) { |
|
res, err := d.inStmt.Exec(c, shot.Cid, shot.Count, shot.CTime, shot.MTime, shot.Count, shot.MTime) |
|
if err != nil { |
|
log.Error("inStmt.Exec error(%v)", err) |
|
return |
|
} |
|
cid, err = res.LastInsertId() |
|
return |
|
}
|
|
|