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.

computeCenterModel_gen.go 5.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. computeCenterFieldNames = builder.RawFieldNames(&ComputeCenter{})
  16. computeCenterRows = strings.Join(computeCenterFieldNames, ",")
  17. computeCenterRowsExpectAutoSet = strings.Join(stringx.Remove(computeCenterFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
  18. computeCenterRowsWithPlaceHolder = strings.Join(stringx.Remove(computeCenterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
  19. cachePcmComputeCenterIdPrefix = "cache:pcm:computeCenter:id:"
  20. )
  21. type (
  22. computeCenterModel interface {
  23. Insert(ctx context.Context, data *ComputeCenter) (sql.Result, error)
  24. FindOne(ctx context.Context, id int64) (*ComputeCenter, error)
  25. Update(ctx context.Context, data *ComputeCenter) error
  26. Delete(ctx context.Context, id int64) error
  27. }
  28. defaultComputeCenterModel struct {
  29. sqlc.CachedConn
  30. table string
  31. }
  32. ComputeCenter struct {
  33. Id int64 `db:"id"` // 平台唯一id
  34. CenterSource sql.NullString `db:"center_source"` // 中心来源(鹏城,nudt,公有云等)
  35. SourceId sql.NullString `db:"source_id"` // 数据来源原id
  36. Name sql.NullString `db:"name"` // 中心名称
  37. Description sql.NullString `db:"description"` // 详细描述
  38. Type sql.NullString `db:"type"` // 中心类型(云算、智算 or 超算)
  39. Area sql.NullString `db:"area"` // 资源区域
  40. City sql.NullString `db:"city"` // 所在城市
  41. Longitude sql.NullFloat64 `db:"longitude"` // 经度
  42. Latitude sql.NullFloat64 `db:"latitude"` // 纬度
  43. Status sql.NullString `db:"status"` // 接入状态
  44. UserNum sql.NullInt64 `db:"user_num"` // 用户数量
  45. DeletedFlag sql.NullInt64 `db:"deleted_flag"` // 是否删除(0-否,1-是)
  46. }
  47. )
  48. func newComputeCenterModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultComputeCenterModel {
  49. return &defaultComputeCenterModel{
  50. CachedConn: sqlc.NewConn(conn, c),
  51. table: "`compute_center`",
  52. }
  53. }
  54. func (m *defaultComputeCenterModel) Delete(ctx context.Context, id int64) error {
  55. pcmComputeCenterIdKey := fmt.Sprintf("%s%v", cachePcmComputeCenterIdPrefix, id)
  56. _, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
  57. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  58. return conn.ExecCtx(ctx, query, id)
  59. }, pcmComputeCenterIdKey)
  60. return err
  61. }
  62. func (m *defaultComputeCenterModel) FindOne(ctx context.Context, id int64) (*ComputeCenter, error) {
  63. pcmComputeCenterIdKey := fmt.Sprintf("%s%v", cachePcmComputeCenterIdPrefix, id)
  64. var resp ComputeCenter
  65. err := m.QueryRowCtx(ctx, &resp, pcmComputeCenterIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
  66. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", computeCenterRows, m.table)
  67. return conn.QueryRowCtx(ctx, v, query, id)
  68. })
  69. switch err {
  70. case nil:
  71. return &resp, nil
  72. case sqlc.ErrNotFound:
  73. return nil, ErrNotFound
  74. default:
  75. return nil, err
  76. }
  77. }
  78. func (m *defaultComputeCenterModel) Insert(ctx context.Context, data *ComputeCenter) (sql.Result, error) {
  79. pcmComputeCenterIdKey := fmt.Sprintf("%s%v", cachePcmComputeCenterIdPrefix, data.Id)
  80. ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
  81. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, computeCenterRowsExpectAutoSet)
  82. return conn.ExecCtx(ctx, query, data.Id, data.CenterSource, data.SourceId, data.Name, data.Description, data.Type, data.Area, data.City, data.Longitude, data.Latitude, data.Status, data.UserNum, data.DeletedFlag)
  83. }, pcmComputeCenterIdKey)
  84. return ret, err
  85. }
  86. func (m *defaultComputeCenterModel) Update(ctx context.Context, data *ComputeCenter) error {
  87. pcmComputeCenterIdKey := fmt.Sprintf("%s%v", cachePcmComputeCenterIdPrefix, data.Id)
  88. _, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
  89. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, computeCenterRowsWithPlaceHolder)
  90. return conn.ExecCtx(ctx, query, data.CenterSource, data.SourceId, data.Name, data.Description, data.Type, data.Area, data.City, data.Longitude, data.Latitude, data.Status, data.UserNum, data.DeletedFlag, data.Id)
  91. }, pcmComputeCenterIdKey)
  92. return err
  93. }
  94. func (m *defaultComputeCenterModel) formatPrimary(primary interface{}) string {
  95. return fmt.Sprintf("%s%v", cachePcmComputeCenterIdPrefix, primary)
  96. }
  97. func (m *defaultComputeCenterModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
  98. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", computeCenterRows, m.table)
  99. return conn.QueryRowCtx(ctx, v, query, primary)
  100. }
  101. func (m *defaultComputeCenterModel) tableName() string {
  102. return m.table
  103. }

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.