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.

tresourcespecmodel_gen.go 4.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Code generated by goctl. DO NOT EDIT.
  2. // versions:
  3. // goctl version: 1.8.1
  4. package models
  5. import (
  6. "context"
  7. "database/sql"
  8. "fmt"
  9. "gorm.io/gorm"
  10. "strings"
  11. "time"
  12. "github.com/zeromicro/go-zero/core/stores/builder"
  13. "github.com/zeromicro/go-zero/core/stores/sqlx"
  14. "github.com/zeromicro/go-zero/core/stringx"
  15. )
  16. var (
  17. tResourceSpecFieldNames = builder.RawFieldNames(&TResourceSpec{})
  18. tResourceSpecRows = strings.Join(tResourceSpecFieldNames, ",")
  19. tResourceSpecRowsExpectAutoSet = strings.Join(stringx.Remove(tResourceSpecFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
  20. tResourceSpecRowsWithPlaceHolder = strings.Join(stringx.Remove(tResourceSpecFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
  21. )
  22. type (
  23. tResourceSpecModel interface {
  24. Insert(ctx context.Context, data *TResourceSpec) (sql.Result, error)
  25. FindOne(ctx context.Context, id int64) (*TResourceSpec, error)
  26. Update(ctx context.Context, data *TResourceSpec) error
  27. Delete(ctx context.Context, id int64) error
  28. }
  29. defaultTResourceSpecModel struct {
  30. conn sqlx.SqlConn
  31. table string
  32. }
  33. TResourceSpec struct {
  34. Id int64 `db:"id" json:"id"` // 主键id
  35. SourceKey string `db:"source_key" json:"sourceKey"` // 数据源标识(type-name)
  36. Type string `db:"type" json:"type"` // 类型名称
  37. Name string `db:"name" json:"name"` // 规格名称
  38. TotalCount int64 `db:"total_count" json:"totalCount"` // 资源总量
  39. AvailableCount int64 `db:"available_count" json:"availableCount"` // 可用数量
  40. ChangeType int64 `db:"change_type" json:"changeType"` // 变更类型(0: 正常,1:变更,2:删除)
  41. Status int64 `db:"status" json:"status"` // 状态(0:未上架,1:已上架)
  42. Region string `db:"region" json:"region"` // 所属区域(可扩展多区域)
  43. ClusterId int64 `db:"cluster_id" json:"clusterId,string"` // 集群ID
  44. CostPerUnit float64 `db:"cost_per_unit" json:"costPerUnit"` // 单位时间积分消耗
  45. CostType string `db:"cost_type" json:"costType"` // 计费类型(hourly, daily, monthly,perUse)
  46. Tag string `db:"tag" json:"tag"` // 标签(Train: 训练,Inference:推理)
  47. UserId int64 `db:"user_id" json:"userId"` // 用户ID
  48. CreateTime time.Time `db:"create_time" json:"createTime"` // 创建时间
  49. UpdateTime time.Time `db:"update_time" json:"updateTime"` // 更新时间
  50. DeletedAt gorm.DeletedAt `db:"deleted_at" json:"-"` // 删除时间
  51. BaseResourceSpecs []TBaseResourceSpec `gorm:"foreignKey:ResourceSpecId" json:"baseResourceSpecs,omitempty"`
  52. }
  53. )
  54. func newTResourceSpecModel(conn sqlx.SqlConn) *defaultTResourceSpecModel {
  55. return &defaultTResourceSpecModel{
  56. conn: conn,
  57. table: "`t_resource_spec`",
  58. }
  59. }
  60. func (m *defaultTResourceSpecModel) Delete(ctx context.Context, id int64) error {
  61. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  62. _, err := m.conn.ExecCtx(ctx, query, id)
  63. return err
  64. }
  65. func (m *defaultTResourceSpecModel) FindOne(ctx context.Context, id int64) (*TResourceSpec, error) {
  66. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", tResourceSpecRows, m.table)
  67. var resp TResourceSpec
  68. err := m.conn.QueryRowCtx(ctx, &resp, query, id)
  69. switch err {
  70. case nil:
  71. return &resp, nil
  72. case sqlx.ErrNotFound:
  73. return nil, ErrNotFound
  74. default:
  75. return nil, err
  76. }
  77. }
  78. func (m *defaultTResourceSpecModel) Insert(ctx context.Context, data *TResourceSpec) (sql.Result, error) {
  79. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, tResourceSpecRowsExpectAutoSet)
  80. ret, err := m.conn.ExecCtx(ctx, query, data.Type, data.Name, data.TotalCount, data.AvailableCount, data.ChangeType, data.Status, data.Region, data.ClusterId, data.UserId, data.DeletedAt)
  81. return ret, err
  82. }
  83. func (m *defaultTResourceSpecModel) Update(ctx context.Context, data *TResourceSpec) error {
  84. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, tResourceSpecRowsWithPlaceHolder)
  85. _, err := m.conn.ExecCtx(ctx, query, data.Type, data.Name, data.TotalCount, data.AvailableCount, data.ChangeType, data.Status, data.Region, data.ClusterId, data.UserId, data.DeletedAt, data.Id)
  86. return err
  87. }
  88. func (m *defaultTResourceSpecModel) tableName() string {
  89. return m.table
  90. }

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.