mysql_machine_node.go 929 B

123456789101112131415161718192021222324252627282930313233343536
  1. package dao
  2. import (
  3. "go-common/app/admin/ep/merlin/model"
  4. pkgerr "github.com/pkg/errors"
  5. )
  6. // DelMachineNodeByMachineID delete node by machine id.
  7. func (d *Dao) DelMachineNodeByMachineID(mID int64) error {
  8. return pkgerr.WithStack(d.db.Where("machine_id = ?", mID).Delete(&model.MachineNode{}).Error)
  9. }
  10. // GenMachineNodes generate some machine nodes.
  11. func (d *Dao) GenMachineNodes(nodes []*model.MachineNode) (err error) {
  12. tx := d.db.Begin()
  13. if err = tx.Error; err != nil {
  14. return
  15. }
  16. for _, n := range nodes {
  17. if err = tx.Create(n).Error; err != nil {
  18. tx.Rollback()
  19. return
  20. }
  21. }
  22. if err = tx.Commit().Error; err != nil {
  23. tx.Rollback()
  24. }
  25. return
  26. }
  27. // QueryMachineNodes query machine nodes by machine id.
  28. func (d *Dao) QueryMachineNodes(mID int64) (nodes []*model.MachineNode, err error) {
  29. err = pkgerr.WithStack(d.db.Model(&model.MachineNode{}).Where("machine_id = ?", mID).Find(&nodes).Error)
  30. return
  31. }