Skip to content

Commit

Permalink
use sql count+1
Browse files Browse the repository at this point in the history
  • Loading branch information
nibazshab committed Jan 31, 2025
1 parent ed06aa8 commit b1cf267
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func dbGetDataByID(data *Data) *Data {
}

func dbUpdateDataInfo(data *Data) {
db.Model(&Data{ID: data.ID}).Updates(data)
db.Model(data).Update("count", gorm.Expr("count + ?", 1))
}

func dbWriteData(data *Data) bool {
Expand Down
3 changes: 1 addition & 2 deletions handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ func handleReqData(c *gin.Context) {
}

infoData := &Data{
ID: dbHashId,
Count: reqData.Count + 1,
ID: dbHashId,
}
dbUpdateDataInfo(infoData)
} else {
Expand Down

0 comments on commit b1cf267

Please sign in to comment.