From 8d27bf523838b3d27b85c957023749752b7ccdc2 Mon Sep 17 00:00:00 2001 From: jicg <284077319@qq.com> Date: Tue, 16 Oct 2018 08:50:57 +0800 Subject: [PATCH] =?UTF-8?q?bug=EF=BC=9Akey=E5=9C=A8mysql=E4=B8=AD=E6=98=AF?= =?UTF-8?q?=E5=85=B3=E9=94=AE=E5=AD=97=20=E9=9C=80=E8=A6=81=E6=94=B9?= =?UTF-8?q?=E6=88=90`key`=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/message.go | 2 +- models/note.go | 8 ++++---- models/praise.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/models/message.go b/models/message.go index 83cef87..467305e 100644 --- a/models/message.go +++ b/models/message.go @@ -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) { diff --git a/models/note.go b/models/note.go index 21fdfdc..3bc6cdf 100644 --- a/models/note.go +++ b/models/note.go @@ -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(¬e).Error + return note, db.db.Model(&Note{}).Where("`key` = ? and user_id = ?", key, userid).Take(¬e).Error } func (db *DB) QueryNoteByKey(key string) (note Note, err error) { - return note, db.db.Model(&Note{}).Where("key = ? ", key).Take(¬e).Error + return note, db.db.Model(&Note{}).Where("`key` = ? ", key).Take(¬e).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(¬e).Error diff --git a/models/praise.go b/models/praise.go index 4798620..ae87b21 100644 --- a/models/praise.go +++ b/models/praise.go @@ -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 {