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.

tclusterresourcemodel_gen.go 4.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Code generated by goctl. DO NOT EDIT.
  2. package models
  3. import (
  4. "context"
  5. "database/sql"
  6. "fmt"
  7. "strings"
  8. "github.com/zeromicro/go-zero/core/stores/builder"
  9. "github.com/zeromicro/go-zero/core/stores/sqlc"
  10. "github.com/zeromicro/go-zero/core/stores/sqlx"
  11. "github.com/zeromicro/go-zero/core/stringx"
  12. )
  13. var (
  14. tClusterResourceFieldNames = builder.RawFieldNames(&TClusterResource{})
  15. tClusterResourceRows = strings.Join(tClusterResourceFieldNames, ",")
  16. tClusterResourceRowsExpectAutoSet = strings.Join(stringx.Remove(tClusterResourceFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
  17. tClusterResourceRowsWithPlaceHolder = strings.Join(stringx.Remove(tClusterResourceFieldNames, "`cluster_id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
  18. )
  19. type (
  20. tClusterResourceModel interface {
  21. Insert(ctx context.Context, data *TClusterResource) (sql.Result, error)
  22. FindOne(ctx context.Context, clusterId int64) (*TClusterResource, error)
  23. Update(ctx context.Context, data *TClusterResource) error
  24. Delete(ctx context.Context, clusterId int64) error
  25. }
  26. defaultTClusterResourceModel struct {
  27. conn sqlx.SqlConn
  28. table string
  29. }
  30. TClusterResource struct {
  31. ClusterId int64 `db:"cluster_id"`
  32. ClusterName string `db:"cluster_name"`
  33. ClusterType int64 `db:"cluster_type"` // 类型0->容器,1->智算,2->超算,3-虚拟机
  34. CpuAvail float64 `db:"cpu_avail"`
  35. CpuTotal float64 `db:"cpu_total"`
  36. MemAvail float64 `db:"mem_avail"`
  37. MemTotal float64 `db:"mem_total"`
  38. DiskAvail float64 `db:"disk_avail"`
  39. DiskTotal float64 `db:"disk_total"`
  40. GpuAvail float64 `db:"gpu_avail"`
  41. GpuTotal float64 `db:"gpu_total"`
  42. CardTotal int64 `db:"card_total"` // 算力卡数量
  43. CardTopsTotal float64 `db:"card_tops_total"` // 算力总量tops
  44. AdapterId int64 `db:"adapter_id"`
  45. CardHours float64 `db:"card_hours"`
  46. Balance float64 `db:"balance"`
  47. TaskCompleted int64 `db:"task_completed"`
  48. }
  49. )
  50. func newTClusterResourceModel(conn sqlx.SqlConn) *defaultTClusterResourceModel {
  51. return &defaultTClusterResourceModel{
  52. conn: conn,
  53. table: "`t_cluster_resource`",
  54. }
  55. }
  56. func (m *defaultTClusterResourceModel) withSession(session sqlx.Session) *defaultTClusterResourceModel {
  57. return &defaultTClusterResourceModel{
  58. conn: sqlx.NewSqlConnFromSession(session),
  59. table: "`t_cluster_resource`",
  60. }
  61. }
  62. func (m *defaultTClusterResourceModel) Delete(ctx context.Context, clusterId int64) error {
  63. query := fmt.Sprintf("delete from %s where `cluster_id` = ?", m.table)
  64. _, err := m.conn.ExecCtx(ctx, query, clusterId)
  65. return err
  66. }
  67. func (m *defaultTClusterResourceModel) FindOne(ctx context.Context, clusterId int64) (*TClusterResource, error) {
  68. query := fmt.Sprintf("select %s from %s where `cluster_id` = ? limit 1", tClusterResourceRows, m.table)
  69. var resp TClusterResource
  70. err := m.conn.QueryRowCtx(ctx, &resp, query, clusterId)
  71. switch err {
  72. case nil:
  73. return &resp, nil
  74. case sqlc.ErrNotFound:
  75. return nil, ErrNotFound
  76. default:
  77. return nil, err
  78. }
  79. }
  80. func (m *defaultTClusterResourceModel) Insert(ctx context.Context, data *TClusterResource) (sql.Result, error) {
  81. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, tClusterResourceRowsExpectAutoSet)
  82. ret, err := m.conn.ExecCtx(ctx, query, data.ClusterId, data.ClusterName, data.ClusterType, data.CpuAvail, data.CpuTotal, data.MemAvail, data.MemTotal, data.DiskAvail, data.DiskTotal, data.GpuAvail, data.GpuTotal, data.CardTotal, data.CardTopsTotal, data.AdapterId)
  83. return ret, err
  84. }
  85. func (m *defaultTClusterResourceModel) Update(ctx context.Context, data *TClusterResource) error {
  86. query := fmt.Sprintf("update %s set %s where `cluster_id` = ?", m.table, tClusterResourceRowsWithPlaceHolder)
  87. _, err := m.conn.ExecCtx(ctx, query, data.ClusterName, data.ClusterType, data.CpuAvail, data.CpuTotal, data.MemAvail, data.MemTotal, data.DiskAvail, data.DiskTotal, data.GpuAvail, data.GpuTotal, data.CardTotal, data.CardTopsTotal, data.AdapterId, data.ClusterId)
  88. return err
  89. }
  90. func (m *defaultTClusterResourceModel) tableName() string {
  91. return m.table
  92. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.