mindoc/models/comment_vote.go

52 lines
1.4 KiB
Go
Raw Normal View History

2017-05-01 19:12:52 +08:00
package models
import (
"time"
"github.com/beego/beego/v2/client/orm"
"github.com/mindoc-org/mindoc/conf"
2017-05-01 19:12:52 +08:00
)
type CommentVote struct {
VoteId int `orm:"column(vote_id);pk;auto;unique" json:"vote_id"`
CommentId int `orm:"column(comment_id);type(int);index" json:"comment_id"`
CommentMemberId int `orm:"column(comment_member_id);type(int);index;default(0)" json:"comment_member_id"`
VoteMemberId int `orm:"column(vote_member_id);type(int);index" json:"vote_member_id"`
VoteState int `orm:"column(vote_state);type(int)" json:"vote_state"`
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
2017-05-01 19:12:52 +08:00
}
// TableName 获取对应数据库表名.
func (m *CommentVote) TableName() string {
2017-05-01 20:40:53 +08:00
return "comment_votes"
2017-05-01 19:12:52 +08:00
}
2017-05-01 19:12:52 +08:00
// TableEngine 获取数据使用的引擎.
func (m *CommentVote) TableEngine() string {
return "INNODB"
}
func (m *CommentVote) TableNameWithPrefix() string {
2017-05-01 19:12:52 +08:00
return conf.GetDatabasePrefix() + m.TableName()
}
func (u *CommentVote) TableUnique() [][]string {
return [][]string{
[]string{"comment_id", "vote_member_id"},
}
}
2017-05-01 20:24:43 +08:00
func NewCommentVote() *CommentVote {
return &CommentVote{}
}
func (m *CommentVote) InsertOrUpdate() (*CommentVote, error) {
2017-05-01 19:12:52 +08:00
o := orm.NewOrm()
if m.VoteId > 0 {
_, err := o.Update(m)
return m, err
} else {
_, err := o.Insert(m)
2017-05-01 19:12:52 +08:00
return m, err
2017-05-01 19:12:52 +08:00
}
}