Skip to content

Commit

Permalink
bug:key在mysql中是关键字 需要改成key
Browse files Browse the repository at this point in the history
  • Loading branch information
jicg committed Oct 16, 2018
1 parent 234a08c commit 8d27bf5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion models/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Message struct {
}

func (db *DB) QueryMessageByKey(key string) (message Message, err error) {
return message, db.db.Model(&Message{}).Where("key = ? ", key).Take(&message).Error
return message, db.db.Model(&Message{}).Where("`key` = ? ", key).Take(&message).Error
}

//func (db *DB) QueryMessageForAdmin() (messages []*Message, err error) {
Expand Down
8 changes: 4 additions & 4 deletions models/note.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ type Note struct {
}

func (db *DB) QueryNoteByKeyAndUserId(key string, userid int) (note Note, err error) {
return note, db.db.Model(&Note{}).Where("key = ? and user_id = ?", key, userid).Take(&note).Error
return note, db.db.Model(&Note{}).Where("`key` = ? and user_id = ?", key, userid).Take(&note).Error
}

func (db *DB) QueryNoteByKey(key string) (note Note, err error) {
return note, db.db.Model(&Note{}).Where("key = ? ", key).Take(&note).Error
return note, db.db.Model(&Note{}).Where("`key` = ? ", key).Take(&note).Error
}

func (db *DB) AllVisitCount(key string) error {
return db.db.Model(&Note{}).Where("key = ?", key).UpdateColumn("visit", gorm.Expr("visit + 1")).Error
return db.db.Model(&Note{}).Where("'key' = ?", key).UpdateColumn("visit", gorm.Expr("visit + 1")).Error
}

func (db *DB) DelNoteByKey(key string, userid int) (error) {
return db.db.Delete(Note{}, "key = ? and user_id = ? ", key, userid).Error
return db.db.Delete(Note{}, "`key` = ? and user_id = ? ", key, userid).Error
}
func (db *DB) QueryNotesByPage(page, limit int, title string) (note []*Note, err error) {
return note, db.db.Model(&Note{}).Where("title like ?", fmt.Sprintf("%%%s%%", title)).Offset((page - 1) * limit).Limit(limit).Order("updated_at DESC").Find(&note).Error
Expand Down
2 changes: 1 addition & 1 deletion models/praise.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (db *DB) UpdateNote4Praise(n *Note) error {
//}

func (db *DB) QueryPraiseLog(key string, user_id int, ttype string) (parselog PraiseLog, err error) {
return parselog, db.db.Where("key = ? and user_id =? and type = ? ", key, user_id, ttype).Take(&parselog).Error
return parselog, db.db.Where("`key` = ? and user_id =? and type = ? ", key, user_id, ttype).Take(&parselog).Error
}

func (db *DB) SavePraiseLog(p *PraiseLog) error {
Expand Down

0 comments on commit 8d27bf5

Please sign in to comment.