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 {