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.

aimodel_gen.go 4.7 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. aiFieldNames = builder.RawFieldNames(&Ai{})
  15. aiRows = strings.Join(aiFieldNames, ",")
  16. aiRowsExpectAutoSet = strings.Join(stringx.Remove(aiFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
  17. aiRowsWithPlaceHolder = strings.Join(stringx.Remove(aiFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
  18. )
  19. type (
  20. aiModel interface {
  21. Insert(ctx context.Context, data *Ai) (sql.Result, error)
  22. FindOne(ctx context.Context, id int64) (*Ai, error)
  23. FindOneByServiceNameProjectIdName(ctx context.Context, serviceName sql.NullString, projectId sql.NullString, name sql.NullString) (*Ai, error)
  24. Update(ctx context.Context, data *Ai) error
  25. Delete(ctx context.Context, id int64) error
  26. }
  27. defaultAiModel struct {
  28. conn sqlx.SqlConn
  29. table string
  30. }
  31. Ai struct {
  32. Id int64 `db:"id"` // id
  33. TaskId int64 `db:"task_id"` // 任务id
  34. ProjectId string `db:"project_id"` // 项目id
  35. Name string `db:"name"` // 名称
  36. Status string `db:"status"` // 状态
  37. StartTime string `db:"start_time"` // 开始时间
  38. RunningTime int64 `db:"running_time"` // 运行时间
  39. CreatedBy int64 `db:"created_by"` // 创建人
  40. CreatedTime sql.NullTime `db:"created_time"` // 创建时间
  41. UpdatedBy int64 `db:"updated_by"` // 更新人
  42. UpdatedTime sql.NullTime `db:"updated_time"` // 更新时间
  43. DeletedFlag int64 `db:"deleted_flag"` // 是否删除(0-否,1-是)
  44. ServiceName string `db:"service_name"`
  45. Result string `db:"result"`
  46. YamlString string `db:"yaml_string"`
  47. JobId string `db:"job_id"`
  48. Command string `db:"command"`
  49. FlavorId string `db:"flavor_id"`
  50. ImageUrl string `db:"image_url"`
  51. SubscriptionId string `db:"subscription_id"`
  52. ItemVersionId string `db:"itemVersion_id"`
  53. }
  54. )
  55. func newAiModel(conn sqlx.SqlConn) *defaultAiModel {
  56. return &defaultAiModel{
  57. conn: conn,
  58. table: "`ai`",
  59. }
  60. }
  61. func (m *defaultAiModel) Delete(ctx context.Context, id int64) error {
  62. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  63. _, err := m.conn.ExecCtx(ctx, query, id)
  64. return err
  65. }
  66. func (m *defaultAiModel) FindOne(ctx context.Context, id int64) (*Ai, error) {
  67. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", aiRows, m.table)
  68. var resp Ai
  69. err := m.conn.QueryRowCtx(ctx, &resp, query, id)
  70. switch err {
  71. case nil:
  72. return &resp, nil
  73. case sqlc.ErrNotFound:
  74. return nil, ErrNotFound
  75. default:
  76. return nil, err
  77. }
  78. }
  79. func (m *defaultAiModel) FindOneByServiceNameProjectIdName(ctx context.Context, serviceName sql.NullString, projectId sql.NullString, name sql.NullString) (*Ai, error) {
  80. var resp Ai
  81. query := fmt.Sprintf("select %s from %s where `service_name` = ? and `project_id` = ? and `name` = ? limit 1", aiRows, m.table)
  82. err := m.conn.QueryRowCtx(ctx, &resp, query, serviceName, projectId, name)
  83. switch err {
  84. case nil:
  85. return &resp, nil
  86. case sqlc.ErrNotFound:
  87. return nil, ErrNotFound
  88. default:
  89. return nil, err
  90. }
  91. }
  92. func (m *defaultAiModel) Insert(ctx context.Context, data *Ai) (sql.Result, error) {
  93. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, aiRowsExpectAutoSet)
  94. ret, err := m.conn.ExecCtx(ctx, query, data.TaskId, data.ProjectId, data.Name, data.Status, data.StartTime, data.RunningTime, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.DeletedFlag, data.ServiceName, data.Result, data.YamlString)
  95. return ret, err
  96. }
  97. func (m *defaultAiModel) Update(ctx context.Context, newData *Ai) error {
  98. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, aiRowsWithPlaceHolder)
  99. _, err := m.conn.ExecCtx(ctx, query, newData.TaskId, newData.ProjectId, newData.Name, newData.Status, newData.StartTime, newData.RunningTime, newData.CreatedBy, newData.CreatedTime, newData.UpdatedBy, newData.UpdatedTime, newData.DeletedFlag, newData.ServiceName, newData.Result, newData.YamlString, newData.Id)
  100. return err
  101. }
  102. func (m *defaultAiModel) tableName() string {
  103. return m.table
  104. }

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.