You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dataset.go 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package models
  2. import (
  3. "fmt"
  4. "code.gitea.io/gitea/modules/timeutil"
  5. )
  6. // Issue represents an issue or pull request of repository.
  7. type Dataset struct {
  8. ID int64 `xorm:"pk autoincr"`
  9. Title string `xorm:"INDEX NOT NULL"`
  10. Status int32 `xorm:"INDEX"`
  11. Category string
  12. Description string `xorm:"TEXT"`
  13. DownloadTimes int64
  14. License string
  15. Task string
  16. ReleaseID int64 `xorm:"INDEX"`
  17. UserID int64 `xorm:"INDEX"`
  18. CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  19. UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
  20. Attachments []*Attachment `xorm:"-"`
  21. }
  22. func CreateDataset(dataset *Dataset) (err error) {
  23. if _, err = x.Insert(dataset); err != nil {
  24. return err
  25. }
  26. return nil
  27. }
  28. // AddDatasetAttachments adds a Dataset attachments
  29. func AddDatasetAttachments(DatasetID int64, attachmentUUIDs []string) (err error) {
  30. // Check attachments
  31. attachments, err := GetAttachmentsByUUIDs(attachmentUUIDs)
  32. if err != nil {
  33. return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %v", attachmentUUIDs, err)
  34. }
  35. for i := range attachments {
  36. attachments[i].DatasetID = DatasetID
  37. // No assign value could be 0, so ignore AllCols().
  38. if _, err = x.ID(attachments[i].ID).Update(attachments[i]); err != nil {
  39. return fmt.Errorf("update attachment [%d]: %v", attachments[i].ID, err)
  40. }
  41. }
  42. return
  43. }
  44. // GetDatasetByID returns Dataset with given ID.
  45. func GetDatasetByID(id int64) (*Dataset, error) {
  46. rel := new(Dataset)
  47. has, err := x.
  48. ID(id).
  49. Get(rel)
  50. if err != nil {
  51. return nil, err
  52. } else if !has {
  53. return nil, ErrDatasetNotExist{id}
  54. }
  55. return rel, nil
  56. }
  57. func UpdateDataset(ctx DBContext, rel *Dataset) error {
  58. _, err := ctx.e.ID(rel.ID).AllCols().Update(rel)
  59. return err
  60. }