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.

cloudmodel_gen.go 4.6 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Code generated by goctl. DO NOT EDIT.
  2. package model
  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. cloudFieldNames = builder.RawFieldNames(&Cloud{})
  15. cloudRows = strings.Join(cloudFieldNames, ",")
  16. cloudRowsExpectAutoSet = strings.Join(stringx.Remove(cloudFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
  17. cloudRowsWithPlaceHolder = strings.Join(stringx.Remove(cloudFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
  18. )
  19. type (
  20. cloudModel interface {
  21. Insert(ctx context.Context, data *Cloud) (sql.Result, error)
  22. FindOne(ctx context.Context, id int64) (*Cloud, error)
  23. FindOneByNamespaceNameServiceName(ctx context.Context, namespace sql.NullString, name sql.NullString, serviceName sql.NullString) (*Cloud, error)
  24. Update(ctx context.Context, data *Cloud) error
  25. Delete(ctx context.Context, id int64) error
  26. }
  27. defaultCloudModel struct {
  28. conn sqlx.SqlConn
  29. table string
  30. }
  31. Cloud struct {
  32. Id int64 `db:"id"` // id
  33. TaskId int64 `db:"task_id"` // 任务id
  34. ApiVersion string `db:"api_version"`
  35. Name string `db:"name"` // 名称
  36. Namespace string `db:"namespace"` // 命名空间
  37. Kind string `db:"kind"` // 种类
  38. Status string `db:"status"` // 状态
  39. StartTime string `db:"start_time"` // 开始时间
  40. RunningTime int64 `db:"running_time"` // 运行时长
  41. CreatedBy int64 `db:"created_by"` // 创建人
  42. CreatedTime sql.NullTime `db:"created_time"` // 创建时间
  43. UpdatedBy int64 `db:"updated_by"` // 更新人
  44. UpdatedTime sql.NullTime `db:"updated_time"` // 更新时间
  45. DeletedFlag int64 `db:"deleted_flag"` // 是否删除(0-否,1-是)
  46. ServiceName string `db:"service_name"`
  47. YamlString string `db:"yaml_string"`
  48. Result string `db:"result"`
  49. }
  50. )
  51. func newCloudModel(conn sqlx.SqlConn) *defaultCloudModel {
  52. return &defaultCloudModel{
  53. conn: conn,
  54. table: "`cloud`",
  55. }
  56. }
  57. func (m *defaultCloudModel) Delete(ctx context.Context, id int64) error {
  58. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  59. _, err := m.conn.ExecCtx(ctx, query, id)
  60. return err
  61. }
  62. func (m *defaultCloudModel) FindOne(ctx context.Context, id int64) (*Cloud, error) {
  63. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", cloudRows, m.table)
  64. var resp Cloud
  65. err := m.conn.QueryRowCtx(ctx, &resp, query, id)
  66. switch err {
  67. case nil:
  68. return &resp, nil
  69. case sqlc.ErrNotFound:
  70. return nil, ErrNotFound
  71. default:
  72. return nil, err
  73. }
  74. }
  75. func (m *defaultCloudModel) FindOneByNamespaceNameServiceName(ctx context.Context, namespace sql.NullString, name sql.NullString, serviceName sql.NullString) (*Cloud, error) {
  76. var resp Cloud
  77. query := fmt.Sprintf("select %s from %s where `namespace` = ? and `name` = ? and `service_name` = ? limit 1", cloudRows, m.table)
  78. err := m.conn.QueryRowCtx(ctx, &resp, query, namespace, name, serviceName)
  79. switch err {
  80. case nil:
  81. return &resp, nil
  82. case sqlc.ErrNotFound:
  83. return nil, ErrNotFound
  84. default:
  85. return nil, err
  86. }
  87. }
  88. func (m *defaultCloudModel) Insert(ctx context.Context, data *Cloud) (sql.Result, error) {
  89. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, cloudRowsExpectAutoSet)
  90. ret, err := m.conn.ExecCtx(ctx, query, data.TaskId, data.ApiVersion, data.Name, data.Namespace, data.Kind, data.Status, data.StartTime, data.RunningTime, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.DeletedFlag, data.ServiceName, data.YamlString, data.Result)
  91. return ret, err
  92. }
  93. func (m *defaultCloudModel) Update(ctx context.Context, newData *Cloud) error {
  94. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, cloudRowsWithPlaceHolder)
  95. _, err := m.conn.ExecCtx(ctx, query, newData.TaskId, newData.ApiVersion, newData.Name, newData.Namespace, newData.Kind, newData.Status, newData.StartTime, newData.RunningTime, newData.CreatedBy, newData.CreatedTime, newData.UpdatedBy, newData.UpdatedTime, newData.DeletedFlag, newData.ServiceName, newData.YamlString, newData.Result, newData.Id)
  96. return err
  97. }
  98. func (m *defaultCloudModel) tableName() string {
  99. return m.table
  100. }

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.