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.

aiCenterModel_gen.go 4.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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/cache"
  10. "github.com/zeromicro/go-zero/core/stores/sqlc"
  11. "github.com/zeromicro/go-zero/core/stores/sqlx"
  12. "github.com/zeromicro/go-zero/core/stringx"
  13. )
  14. var (
  15. aiCenterFieldNames = builder.RawFieldNames(&AiCenter{})
  16. aiCenterRows = strings.Join(aiCenterFieldNames, ",")
  17. aiCenterRowsExpectAutoSet = strings.Join(stringx.Remove(aiCenterFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
  18. aiCenterRowsWithPlaceHolder = strings.Join(stringx.Remove(aiCenterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
  19. cachePcmAiCenterIdPrefix = "cache:pcm:aiCenter:id:"
  20. )
  21. type (
  22. aiCenterModel interface {
  23. Insert(ctx context.Context, data *AiCenter) (sql.Result, error)
  24. FindOne(ctx context.Context, id int64) (*AiCenter, error)
  25. Update(ctx context.Context, data *AiCenter) error
  26. Delete(ctx context.Context, id int64) error
  27. }
  28. defaultAiCenterModel struct {
  29. sqlc.CachedConn
  30. table string
  31. }
  32. AiCenter struct {
  33. Id int64 `db:"id"` // 平台唯一id
  34. ClusterNum sql.NullInt64 `db:"cluster_num"` // 集群数量
  35. NodeNum sql.NullInt64 `db:"node_num"` // 节点数量
  36. CpuNum sql.NullInt64 `db:"cpu_num"` // CPU核数
  37. GpuNum sql.NullInt64 `db:"gpu_num"` // GPU卡数
  38. ManagedFlops sql.NullString `db:"managed_flops"` // 已接入算力
  39. UnmanagedFlops sql.NullString `db:"unmanaged_flops"` // 未接入算力
  40. ManagedStorage sql.NullString `db:"managed_storage"` // 已接入存储
  41. UnmanagedStorage sql.NullString `db:"unmanaged_storage"` // 未接入存储
  42. }
  43. )
  44. func newAiCenterModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAiCenterModel {
  45. return &defaultAiCenterModel{
  46. CachedConn: sqlc.NewConn(conn, c),
  47. table: "`ai_center`",
  48. }
  49. }
  50. func (m *defaultAiCenterModel) Delete(ctx context.Context, id int64) error {
  51. pcmAiCenterIdKey := fmt.Sprintf("%s%v", cachePcmAiCenterIdPrefix, id)
  52. _, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
  53. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  54. return conn.ExecCtx(ctx, query, id)
  55. }, pcmAiCenterIdKey)
  56. return err
  57. }
  58. func (m *defaultAiCenterModel) FindOne(ctx context.Context, id int64) (*AiCenter, error) {
  59. pcmAiCenterIdKey := fmt.Sprintf("%s%v", cachePcmAiCenterIdPrefix, id)
  60. var resp AiCenter
  61. err := m.QueryRowCtx(ctx, &resp, pcmAiCenterIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
  62. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", aiCenterRows, m.table)
  63. return conn.QueryRowCtx(ctx, v, query, id)
  64. })
  65. switch err {
  66. case nil:
  67. return &resp, nil
  68. case sqlc.ErrNotFound:
  69. return nil, ErrNotFound
  70. default:
  71. return nil, err
  72. }
  73. }
  74. func (m *defaultAiCenterModel) Insert(ctx context.Context, data *AiCenter) (sql.Result, error) {
  75. pcmAiCenterIdKey := fmt.Sprintf("%s%v", cachePcmAiCenterIdPrefix, data.Id)
  76. ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
  77. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, aiCenterRowsExpectAutoSet)
  78. return conn.ExecCtx(ctx, query, data.Id, data.ClusterNum, data.NodeNum, data.CpuNum, data.GpuNum, data.ManagedFlops, data.UnmanagedFlops, data.ManagedStorage, data.UnmanagedStorage)
  79. }, pcmAiCenterIdKey)
  80. return ret, err
  81. }
  82. func (m *defaultAiCenterModel) Update(ctx context.Context, data *AiCenter) error {
  83. pcmAiCenterIdKey := fmt.Sprintf("%s%v", cachePcmAiCenterIdPrefix, data.Id)
  84. _, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
  85. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, aiCenterRowsWithPlaceHolder)
  86. return conn.ExecCtx(ctx, query, data.ClusterNum, data.NodeNum, data.CpuNum, data.GpuNum, data.ManagedFlops, data.UnmanagedFlops, data.ManagedStorage, data.UnmanagedStorage, data.Id)
  87. }, pcmAiCenterIdKey)
  88. return err
  89. }
  90. func (m *defaultAiCenterModel) formatPrimary(primary interface{}) string {
  91. return fmt.Sprintf("%s%v", cachePcmAiCenterIdPrefix, primary)
  92. }
  93. func (m *defaultAiCenterModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
  94. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", aiCenterRows, m.table)
  95. return conn.QueryRowCtx(ctx, v, query, primary)
  96. }
  97. func (m *defaultAiCenterModel) tableName() string {
  98. return m.table
  99. }

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.