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.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. }
  45. )
  46. func newTClusterResourceModel(conn sqlx.SqlConn) *defaultTClusterResourceModel {
  47. return &defaultTClusterResourceModel{
  48. conn: conn,
  49. table: "`t_cluster_resource`",
  50. }
  51. }
  52. func (m *defaultTClusterResourceModel) withSession(session sqlx.Session) *defaultTClusterResourceModel {
  53. return &defaultTClusterResourceModel{
  54. conn: sqlx.NewSqlConnFromSession(session),
  55. table: "`t_cluster_resource`",
  56. }
  57. }
  58. func (m *defaultTClusterResourceModel) Delete(ctx context.Context, clusterId int64) error {
  59. query := fmt.Sprintf("delete from %s where `cluster_id` = ?", m.table)
  60. _, err := m.conn.ExecCtx(ctx, query, clusterId)
  61. return err
  62. }
  63. func (m *defaultTClusterResourceModel) FindOne(ctx context.Context, clusterId int64) (*TClusterResource, error) {
  64. query := fmt.Sprintf("select %s from %s where `cluster_id` = ? limit 1", tClusterResourceRows, m.table)
  65. var resp TClusterResource
  66. err := m.conn.QueryRowCtx(ctx, &resp, query, clusterId)
  67. switch err {
  68. case nil:
  69. return &resp, nil
  70. case sqlc.ErrNotFound:
  71. return nil, ErrNotFound
  72. default:
  73. return nil, err
  74. }
  75. }
  76. func (m *defaultTClusterResourceModel) Insert(ctx context.Context, data *TClusterResource) (sql.Result, error) {
  77. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, tClusterResourceRowsExpectAutoSet)
  78. 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)
  79. return ret, err
  80. }
  81. func (m *defaultTClusterResourceModel) Update(ctx context.Context, data *TClusterResource) error {
  82. query := fmt.Sprintf("update %s set %s where `cluster_id` = ?", m.table, tClusterResourceRowsWithPlaceHolder)
  83. _, 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.ClusterId)
  84. return err
  85. }
  86. func (m *defaultTClusterResourceModel) tableName() string {
  87. return m.table
  88. }

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.