document.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package models
  2. import (
  3. "time"
  4. "github.com/lifei6671/godoc/conf"
  5. )
  6. // Document struct.
  7. type Document struct {
  8. DocumentId int `orm:"pk;auto;unique;column(document_id)" json:"document_id"`
  9. DocumentName string `orm:"column(document_name);size(500)" json:"document_name"`
  10. // Identify 文档唯一标识
  11. Identify string `orm:"column(identify);size(100);unique" json:"identify"`
  12. BookId int `orm:"column(book_id);type(int);index" json:"book_id"`
  13. OrderSort int `orm:"column(order_sort);default(0);type(int)" json:"order_sort"`
  14. // Markdown markdown格式文档.
  15. Markdown string `orm:"column(markdown);type(longtext)" json:"markdown"`
  16. // Release 发布后的Html格式内容.
  17. Release string `orm:"column(release);type(longtext)" json:"release"`
  18. // Content 未发布的 Html 格式内容.
  19. Content string `orm:"column(content);type(longtext)" json:"content"`
  20. CreateTime time.Time `orm:"column(create_time);type(datetime)" json:"create_time"`
  21. CreateAt int `orm:"column(create_at);type(int)" json:"create_at"`
  22. ModifyTime time.Time `orm:"column(modify_time);type(datetime);auto_now" json:"modify_time"`
  23. ModifyAt int `orm:"column(modify_at);type(int)" json:"modify_at"`
  24. Version int64 `orm:"type(bigint);column(version)" json:"version"`
  25. }
  26. // TableName 获取对应数据库表名.
  27. func (m *Document) TableName() string {
  28. return "documents"
  29. }
  30. // TableEngine 获取数据使用的引擎.
  31. func (m *Document) TableEngine() string {
  32. return "INNODB"
  33. }
  34. func (m *Document) TableNameWithPrefix() string {
  35. return conf.GetDatabasePrefix() + m.TableName()
  36. }
  37. func NewDocument() *Document {
  38. return &Document{}
  39. }