build.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package v2
  2. import (
  3. "database/sql"
  4. "go-common/app/infra/config/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. )
  8. // BuildsByAppID get builds by app id.
  9. func (d *Dao) BuildsByAppID(appID int64) (builds []string, err error) {
  10. var rows *sql.Rows
  11. if rows, err = d.DB.Select("name").Model(&model.Build{}).Where("app_id = ? ", appID).Rows(); err != nil {
  12. log.Error("BuildsByAppID(%v) error(%v)", appID, err)
  13. return
  14. }
  15. defer rows.Close()
  16. for rows.Next() {
  17. var build string
  18. if err = rows.Scan(&build); err != nil {
  19. log.Error("BuildsByAppID(%v) error(%v)", appID, err)
  20. return
  21. }
  22. builds = append(builds, build)
  23. }
  24. if len(builds) == 0 {
  25. err = ecode.NothingFound
  26. }
  27. return
  28. }
  29. // BuildsByAppIDs get builds by app id.
  30. func (d *Dao) BuildsByAppIDs(appIDs []int64) (builds []string, err error) {
  31. var rows *sql.Rows
  32. if rows, err = d.DB.Select("name").Model(&model.Build{}).Where("app_id in (?) ", appIDs).Rows(); err != nil {
  33. log.Error("BuildsByAppIDs(%v) error(%v)", appIDs, err)
  34. return
  35. }
  36. defer rows.Close()
  37. for rows.Next() {
  38. var build string
  39. if err = rows.Scan(&build); err != nil {
  40. log.Error("BuildsByAppIDs(%v) error(%v)", appIDs, err)
  41. return
  42. }
  43. builds = append(builds, build)
  44. }
  45. if len(builds) == 0 {
  46. err = ecode.NothingFound
  47. }
  48. return
  49. }
  50. // TagID get TagID by ID.
  51. func (d *Dao) TagID(appID int64, build string) (tagID int64, err error) {
  52. row := d.DB.Select("tag_id").Where("app_id =? and name= ?", appID, build).Model(&model.Build{}).Row()
  53. if err = row.Scan(&tagID); err != nil {
  54. log.Error("TagID(%v) error(%v)", build, err)
  55. if err == sql.ErrNoRows {
  56. err = ecode.NothingFound
  57. }
  58. }
  59. return
  60. }
  61. // BuildID get build by ID.
  62. func (d *Dao) BuildID(appID int64, build string) (buildID int64, err error) {
  63. row := d.DB.Select("id").Where("app_id =? and name= ?", appID, build).Model(&model.Build{}).Row()
  64. if err = row.Scan(&buildID); err != nil {
  65. log.Error("buildID(%v) error(%v)", buildID, err)
  66. if err == sql.ErrNoRows {
  67. err = ecode.NothingFound
  68. }
  69. }
  70. return
  71. }