resource.go 884 B

1234567891011121314151617181920212223242526272829303132
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type Resource struct {
  7. Id int `orm:"column(id);" description:"资源id"`
  8. ResourceUrl string `description:"资源地址"`
  9. CreateTime time.Time `description:"创建时间"`
  10. ResourceType int `description:"资源类型,1:图片,2:音频,3:视频 "`
  11. }
  12. type ResourceResp struct {
  13. Id int64 `orm:"column(id);" description:"用户id"`
  14. ResourceUrl string `description:"资源地址"`
  15. PlaySeconds uint32 `description:"播放时长,单位秒"`
  16. }
  17. func AddResource(item *Resource) (newId int64, err error) {
  18. o := orm.NewOrmUsingDB("rddp")
  19. newId, err = o.Insert(item)
  20. return
  21. }
  22. func GetResourceById(id string) (item *Resource, err error) {
  23. o := orm.NewOrmUsingDB("rddp")
  24. sql := "SELECT * FROM resource WHERE id=? "
  25. err = o.Raw(sql, id).QueryRow(&item)
  26. return
  27. }