comment_vote.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package models
  2. import (
  3. "time"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/mindoc-org/mindoc/conf"
  6. )
  7. type CommentVote struct {
  8. VoteId int `orm:"column(vote_id);pk;auto;unique" json:"vote_id"`
  9. CommentId int `orm:"column(comment_id);type(int);index" json:"comment_id"`
  10. CommentMemberId int `orm:"column(comment_member_id);type(int);index;default(0)" json:"comment_member_id"`
  11. VoteMemberId int `orm:"column(vote_member_id);type(int);index" json:"vote_member_id"`
  12. VoteState int `orm:"column(vote_state);type(int)" json:"vote_state"`
  13. CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
  14. }
  15. // TableName 获取对应数据库表名.
  16. func (m *CommentVote) TableName() string {
  17. return "comment_votes"
  18. }
  19. // TableEngine 获取数据使用的引擎.
  20. func (m *CommentVote) TableEngine() string {
  21. return "INNODB"
  22. }
  23. func (m *CommentVote) TableNameWithPrefix() string {
  24. return conf.GetDatabasePrefix() + m.TableName()
  25. }
  26. func (u *CommentVote) TableUnique() [][]string {
  27. return [][]string{
  28. []string{"comment_id", "vote_member_id"},
  29. }
  30. }
  31. func NewCommentVote() *CommentVote {
  32. return &CommentVote{}
  33. }
  34. func (m *CommentVote) InsertOrUpdate() (*CommentVote, error) {
  35. o := orm.NewOrm()
  36. if m.VoteId > 0 {
  37. _, err := o.Update(m)
  38. return m, err
  39. } else {
  40. _, err := o.Insert(m)
  41. return m, err
  42. }
  43. }